0

I'm trying to use pybind11's stl_bind header to no avail. I tried this:

#include <vector>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>

namespace py = pybind11;

PYBIND11_PLUGIN(test)
{
    py::module m("test", "pybind11 example plugin");
    py::bind_vector<std::vector<double>>(m, "std_vector");
}

But when I try to use "std_vector" in python I get this:

In [1]: import test as b

In [2]: vec = b.std_vector()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-f81a62984a4e> in <module>()
----> 1 vec = b.std_vector()

ValueError: vector::reserve

Is this a bug, or am I using pybind11 wrong?

user2602914
  • 301
  • 3
  • 11

1 Answers1

0

Aren't you missing a call to the PYBIND11_MAKE_OPAQUE macro before PYBIND11_PLUGIN(test)?

PYBIND11_MAKE_OPAQUE(std::vector<double>);

According to the PyBind11 doc you shoud first disable the defalut type conversion from vector to list.

MarcoP
  • 1,438
  • 10
  • 17