[C++-sig] Boost-python wrapping a vector of vectors?

Tim Couper tim at tizmoi.net
Thu Jan 7 10:21:50 CET 2010


Troy

Thanks for the prompt reply .. I'm a python expert and a C++ novice ... 
Apologies for not getting this ...

I've seen I can define a python mapping using the vector_indexing suite

class_< std::vector< std::vector<double> > >("vector_double2")
      .def(vector_indexing_suite<std::vector< std::vector<double> > >

but I can't see how to get that information into the init argument in 
the C++

class_<A>("A")
     .def(init<vector_double2>( ))

as vector_double2 isn't known when the c++ compiles, so this clearly 
isn't the "type" argument to which you refer. Clearly there's something 
I'm missing. How do I define a type? Should I be using the named 
constructors/factories described in 
http://wiki.python.org/moin/boost.python/HowTo? If so how?

Thanks again

Tim






On 06/01/2010 23:16, troy d. straszheim wrote:
> Tim Couper wrote:
>>
>> I'm trying to boost-python a vector-of-vectors, like
>>
>> class A
>> {
>> public
>>    A(const std::vector<std::vector double >>& my_array);
>> };
>>
>> and would intuitively write the wrapper:
>>
>> BOOST_PYTHON_MODULE(foo)
>> {
>> using namespace boost::python
>>
>> class_<A>("A")
>>     .def(init(std::vector<std::vector<double> >())
>>     ;
>>
>> but get the error "a call to a constructor cannot appear in a 
>> constant expression"
>
> Syntax error, init takes a type argument:  init<T>()
>
> -t
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.725 / Virus Database: 270.14.127/2603 - Release Date: 01/06/10 07:35:00
>
>    
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20100107/56b2bd54/attachment.htm>


More information about the Cplusplus-sig mailing list