[C++-sig] def_readwrite and custom rvalue converters
Ralf W. Grosse-Kunstleve
rwgk at yahoo.com
Mon Mar 10 07:21:26 CET 2003
--- David Abrahams <dave at boost-consulting.com> wrote:
> > Is this still the best solution available?
>
> Sorry, I don't remember enough about the problem to be able to say.
That strongly suggests the answer is "yes."
FWIW: Say you have a custom rvalue converter which converts Python tuples to
std::vector<int> and a to_python converter for the opposite direction.
Everything is fine for converting function arguments and return values.
However, with Boost 1.30.0 def_readonly() and def_readwrite() do not work for
that std::vector<int>. In connection with this you pointed me to the following
code:
data_members.cpp contains:
// If it's a regular class type (not an object manager or other
// type for which we have to_python specializations, use
// return_internal_reference so that we can do things like
// x.y.z = 1
// and get the right result.
template <class T>
struct default_getter_policy
You wrote further:
> Which selects a policy to use for getters. The problem is that your
> converter can't use return_internal_reference, because it's making a
> list or tuple or something else which doesn't support weak references,
> instead of an extension class instance.
You told me that this can be used instead of def_readwrite():
typedef return_value_policy<return_by_value> rbv;
// ...
.add_property("site", make_getter(&w_t::site, rbv()),
make_setter(&w_t::site))
You thought it would be better to handle this situation automatically with some
"not_exposed_as_class" specialization.
Ralf
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
More information about the Cplusplus-sig
mailing list