[C++-sig] Boost.Python v2: implicit conversion support
Martin Casado
casado2 at llnl.gov
Fri Mar 29 17:42:26 CET 2002
> --- David Abrahams <david.abrahams at rcn.com> wrote:
> > Support for C++ implicit conversions has now been added to the v2
> > codebase. Please see libs/python/test/implicit.* for examples.
>
> Cool!
> Could this mechanism also be used to convert, e.g., python tuples
> to std::vector?
Ralf,
I wrote a conversion mechanism for python sequence types to c++
container types using boost type coersion. It works pretty well,
however I was having troubles with recursive types, i.e. lists of
lists and haven't had the time to look back into that. If you are
interested I can forward you my code.
~~m
> implicitly_convertible<boost::python::tuple, std::vector<double> >();
>
> I guess not since there is no appropriate C++ implicit conversion.
> What about something like this:
>
> struct my_converter_type {
> operator()(const boost::python::tuple& t, std::vector<double>& v) const
> {
> // convert the elements of the tuple and store in v
> };
> };
>
> implicitly_convertible<
> boost::python::tuple,
> std::vector<double>,
> my_converter_type>();
>
> Thanks,
> Ralf
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Movies - coverage of the 74th Academy Awards®
> http://movies.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