[C++-sig] def_readonly and const array members

Jeff Brewer jeff at brewer.com
Fri Jul 25 05:48:34 CEST 2003


I am using Boost 1.30. Sorry I forgot to mention that.

def_readonly seems to still in 1.30 and its implementation is:
template <class D, class B>
self& def_readonly(char const* name, D B::*pm_)
    {
        D T::*pm = pm_;
        this->add_property(name, make_getter(pm));
        return *this;
    }
Is it deprecated though?

However, I tried add_property with make_getter (which I usually use
anyway) and I get the same error. Here is my new class_ code:

class_<testStruct>("testStruct", init<>())
	.add_property("theArray",
make_getter(&testStruct::theArray,
return_value_policy<return_by_value>()));

Thank you for the help,

Jeff Brewer
jeff at brewer.com

-----Original Message-----
From: Ralf W. Grosse-Kunstleve [mailto:rwgk at yahoo.com] 
Posted At: Thursday, July 24, 2003 6:06 PM
Posted To: c++-sig
Conversation: [C++-sig] def_readonly and const array members
Subject: Re: [C++-sig] def_readonly and const array members

--- Jeff Brewer <jeff at brewer.com> wrote:
> I am trying to wrap structs that have character arrays and I'm having
> problems since I moved from MSVC 7 to MSVC 7.1 (VS .NET 2003). Here is
> the struct I'm trying to expose the theArray member of using
> class_::def_readonly:

Are you also moving to a more recent boost?

> 		.def_readonly("theArray", &testStruct::theArray);

Try this instead:

#include <boost/python/return_value_policy.hpp>
#include <boost/python/return_by_value.hpp>

.add_property("theArray", make_getter(&testStruct::theArray,
return_value_policy<return_by_value>()));

If you want to support both Boost 1.29 and never versions:

#include <boost/version.hpp>
#if BOOST_VERSION >= 103000
// use add_property
#else
// use def_readonly or def_readwrite
#endif

Ralf


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig





More information about the Cplusplus-sig mailing list