[C++-sig] V2 type_from_python question

David Abrahams david.abrahams at rcn.com
Sat Apr 6 01:07:38 CEST 2002


----- Original Message -----
From: "Peter Bienstman" <pbienst at MIT.EDU>
To: <c++-sig at python.org>
Sent: Friday, April 05, 2002 3:52 PM
Subject: [C++-sig] V2 type_from_python question


> OK, one of the final hurdles. I'm trying to convert a Numerical Python
> array to a C++ array type. For that I try
>
> struct cVector_from_python
> {
>   static cVector execute(PyArrayObject& o)
>   {
>     // do stuff
>     return cVector(/* some params */);
>   }
> };
>
> type_from_python<&PyArray_Type, cVector_from_python>();
>
> This gives compiler errors:
>
> /home/pbienst/boost_cvs/boost/boost/python/type_from_python.hpp: In
> constructor
>    `boost::python::type_from_python<python_type,
> Extractor>::type_from_python()
>    [with const PyTypeObject*python_type = (&PyArray_Type), Extractor =
>    cVector_from_python]':
> /home/pbienst/camfr_work/camfr/camfr_wrap2.cpp:434:   instantiated
from
> here
> /home/pbienst/boost_cvs/boost/boost/python/type_from_python.hpp:86: no
> matching
>    function for call to `extractor_type_id(cVector
(*)(PyArrayObject&))'
>
> Looking more closely at the examples, I see that all of the 'execute'
> functions return a reference, which is of course not an option in my
> case.
>
> Am I doing something wrong?

You need an rvalue from_python converter. All the examples show lvalue
converters. Some examples of rvalue converters are in
libs/python/src/converter/builtin_converters.cpp.

-Dave

P.S. I plan to do something to make that easier, if I can find a few
minutes... my monthly report shows that I intend to make generalized
sequence converters.







More information about the Cplusplus-sig mailing list