I'm trying to bind a registerHandler() defined in a given class, which I can't modify.
The class:
class FG{
public:
//return DType, no input argument
using Handler = std::function<DType(void)>;
void RegisterHandler(Handler h);
}
class DType{
public:
DType() noexcept = default;
DType(DType const &) = delete;
DType(DType&& other) noexcept = default;
~DType() noexcept
{...
}
DType& operator=(DType const&) = delete;
DType& operator=(DType&& other) & noexcept = default;
...
}
If I bind it like below, it gives an error message saying "error: use of deleted function 'DType(const DType&)'.
#include <pybind/pybind11>
#include <pybind/stl_bind11>
#include <pybind/functional.h>
#include <pybind/stl.h>
using Handler = std::function<DType>(void);
void bind_FG(py::module& m)
{
py::class_<FG> pyClass(m, "FG", py::module_local());
pyClass.def("RegisterHandler" &RegisterHandler);
//or
// pyClass.def("RegisterHandler", [](FG& self, Handler h)
// {
// self.RegisterHandler(h);
// }
// );
}
I googled std::function, and it says it requires a copy ctor, does it mean that there is no way to bind the RegisterHandler() for my case?
At the same time, I'm confused we have implemented the handler function in the C++ side, it seems to be fine (build and work). Why doesn't it require a copy ctor for C++ code?