[C++-sig] rvalue custom converters ( was Protected destructor compile error )
Ralf W. Grosse-Kunstleve
rwgk at yahoo.com
Sat Jun 24 07:02:59 CEST 2006
--- Roman Yakovenko <roman.yakovenko at gmail.com> wrote:
> I will study the examples. I and Lakin Wecker work on Python bindings for
> That library contains few classes like Matrix3 or Matrix4( Vector3, Vector4
> Those classes have constructors from regular C++ arrays. It could be nice if
> we can create Python bindings, where user could pass Python list or
> tuple instead
> of [Matrix|Vector][3|4] as argument to functions.
> If I understand right, custom rvalue converters is the way to go, right?
> The only question I have is how it will work in presents of registration of
> [Matrix|Vector][3|4] classes?
Situation 1 a:
.def(init<matrix const&>()) // wrap the copy constructor
Also define custom from_python converters converting Python sequences (e.g.
list, tuple, iter) to matrix. This way any function expecting a matrix const&
will also accept a Python sequence, including the copy constructor above.
Situation 1 b:
If you don't want all function to convert sequences on the fly (e.g. because
you are afraid your users don't understand the impact on runtime performance),
don't define the custom from_python converters. Instead of wrapping the copy
constructor, use make_constructor to inject a constructor converting Python
Define both custom to_python and from_python conversions, don't use class_.
Which enables, e.g.:
tuple_mapping_fixed_size<matrix>(); // situation 2 above
This also uses container_conversions.h, but only to define from_python
conversions. The copy constructor is wrapped. This is situation 1 a above.
Look for from_list_or_tuple_of_lists_or_tuples() which is used with
make_constructor. This is situation 1 b above.
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
More information about the Cplusplus-sig