boost python writing converters for list to std::vector<T>

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

boost python writing converters for list to std::vector<T>

helferthomas
Hi,

using
http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/, I tried to write a converter for list to std::vector<T> (In the example, T will be double).

The code (see converter.cxx) I wrote is still in early stage of
development (no check) but compiles fine on ubuntu oneiric with boost
python 1.46. I used it to create an std module. However, a simple test
(see test.py) does not work as exepted.

Did I misunderstood something or does boost have a special treatment for
the list object which bypasses converters ?

Thanks for any help,

Sincerly,

Helfer THomas

_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig

converter.cxx (2K) Download Attachment
test.py (35 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: boost python writing converters for list to std::vector<T>

Jim Bosch-2
On 04/20/2012 11:45 AM, Helfer Thomas wrote:

> Hi,
>
> using
> http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/, I tried to write a converter for list to std::vector<T>  (In the example, T will be double).
>
> The code (see converter.cxx) I wrote is still in early stage of
> development (no check) but compiles fine on ubuntu oneiric with boost
> python 1.46. I used it to create an std module. However, a simple test
> (see test.py) does not work as exepted.
>
> Did I misunderstood something or does boost have a special treatment for
> the list object which bypasses converters ?
>

The problem is that your "print" function takes a std::vector by
reference, and you've defined an rvalue converter, which will only match
value or const reference arguments.  In other words,

void print(std::vector<double> const & v) {...}

or

void print(std::vector<double> v) {...}

should work.  Everything else looks good.

HTH!

Jim
_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Loading...