[C++-sig] boost python writing converters for list to std::vector<T>

Jim Bosch talljimbo at gmail.com
Mon Apr 23 17:28:46 CEST 2012


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


More information about the Cplusplus-sig mailing list