[C++-sig] automatic conversion of tuple to vector

Nathan Cournia cournia at gmail.com
Tue May 25 00:00:22 CEST 2010


Hi All,

The FAQ at:

  http://www.boost.org/doc/libs/1_43_0/libs/python/doc/v2/faq.html

lists the following code as not possible with boost.python:

C++:

void foo(std::vector<double>& array)
{
  for(std::size_t i=0;i<array.size();i++) {
    array[i] *= 2;
  }
}

Python:

>>> l = [1, 2, 3]
>>> foo(l)
>>> print l
[2, 4, 6]

Basically, the desired behavior is to have a C++ function which
accepts a vector in C++; accept a tuple/list when in Python.

I'm not sure if the FAQ is up-to-date.  Is this still not possible in
boost.python?  How do people generally get the behavior I outlined
above?

Thanks!

nathan


More information about the Cplusplus-sig mailing list