[C++-sig] boost python constructor for tr1::array

Amos Anderson nitroamos at gmail.com
Tue Mar 2 02:19:30 CET 2010


Hello -- i've got a wrapper for a tr1::array, but i don't know how to
make a constructor for it.

i have something like:
//some stuff defining functions
//...
   class_<std::tr1::array<T,dim> > (ss.str().c_str())
      .def("__getitem__", get,
return_value_policy<copy_non_const_reference>())
      .def("__setitem__", &array_setitem<T,dim>)
      .def("__iter__", range<return_value_policy<return_by_value> >
           (vecbegin, vecend))
   ;

where the name will end up being something like "Array2_double". In my
python code right now, I have do to something like this:
pair = Array2_double()
pair[0] = 0.1
pair[1] = 1.2

But I'd like to do this:
pair = Array2_double(0.1, 1.2)

or even better:
listOfPairs = Vector_Array2_double()
listOfPairs.append(0.1, 1.2)

i've been able to follow the tutorials etc for simple classes, but
nothing i've tried for this will compile. well, i know i could make an
external function:
pair = make_Array2_double(0.1,1.2)
if i really wanted to, but i don't know how to do this within
templates, so i think i'd have to make all those separately.

thanks!

Amos.


More information about the Cplusplus-sig mailing list