Передача списка Python в вектор C ++ с помощью Boost. python

Как передать список Python моего типа объекта ClassName функции C ++, которая принимает вектор ?

Лучшее, что я нашел, выглядит примерно так: пример . К сожалению, код вылетает, и я не могу понять почему. Вот что я использовал:

template
void python_to_vector(boost::python::object o, vector* v) {
    try {
      object iter_obj = object(handle<>(PyObject_GetIter(o.ptr())));
      return;
      for (;;) {
          object obj = extract(iter_obj.attr("next")());
          // Should launch an exception if it cannot extract T
          v->emplace_back(extract(obj));
      }
    } catch(error_already_set) {
        PyErr_Clear();
        // If there is an exception (no iterator, extract failed or end of the
        // list reached), clear it and exit the function
        return;
    }
}

7
задан Neil G 27 January 2011 в 19:09
поделиться