I am trying to wrap some C++ class using Pybind11.
The class (Alpha) two getters, one returning a const reference to a member force_ the other one returning a non-const reference.
struct Dummy {
double x{3.3};
};
class Alpha {
const Dummy& force() const {return force_;}
Dummy& force() {return force_;}
private:
Dummy force_;
};
I initially tried using the py::return_value_policy however this way, it seems like i didn't correctly disambiguate between the two versions of function force() as I am getting
note: template argument deduction/substitution failed: and couldn’t deduce template parameter ‘Func’
py::class_<Alpha>(m, "Alpha")
.def(py::init())
.def("force", &Alpha::force, "returns reference", py::return_value_policy::reference_internal)
.def("force", &Alpha::force, "returns copy", py::return_value_policy::copy);
}
Am I heading in a completely wrong direction? I do not really want do alter the C++ side of the code. A side question would be: How could I write &Alpha::force unambiguously to either mean the const or non-const version.