-
I'm having trouble compiling the following code with a member function that returns a nested template type (vector of tuples). I'm using g++-13 with c++23 mode. #include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <memory>
#include <string>
#include <tuple>
#include <vector>
namespace py = pybind11;
using namespace std;
class A {
public:
virtual ~A() = default;
virtual vector<tuple<string, int>> fields() = 0;
};
class PyA : public A {
public:
using A::A;
vector<tuple<string, int> > fields() override {
PYBIND11_OVERRIDE_PURE(vector<tuple<string, int> >, A, fields);
};
};
PYBIND11_MODULE(example, m) {
py::class_<A, PyA, shared_ptr<A>>(m, "A");
} If I don't place white spaces between the ">>" template closing brackets (in trampoline class), I get an error "expected ‘>’ before ‘>>’ token". Otherwise, I get an error "expected ‘(’ before ‘>’ token". Does anyone have any suggestions on how I might be able to mimic this return type using pybind? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Actually, this is an issue with the macro expansion. The macro is confused by the comma in the template definition. If I expand the macro manually but as intended then the code compiles, i.e. PYBIND11_OVERRIDE_PURE_NAME(PYBIND11_TYPE(vector<tuple<string, int>>),
PYBIND11_TYPE(A), "fields", fields); There some other possible workarounds here (none look pretty). |
Beta Was this translation helpful? Give feedback.
Actually, this is an issue with the macro expansion. The macro is confused by the comma in the template definition. If I expand the macro manually but as intended then the code compiles, i.e.
There some other possible workarounds here (none look pretty).