What is the appropriate nanobind
syntax to expose the instance method below?
struct Foo {
int &value() & {
return v;
};
int v;
};
With pybind
, one could use static_cast
with Foo::*
syntax to cast the function pointer to the appropriate type, like so:
nb::class_<Foo>(m, "Foo").def("value", static_cast<int &(Foo::*)() &>(&Foo::value));
but with nanobind
, I get this error:
...third_party/nanobind/include/nanobind/nb_class.h:567:28: error: no matching
function for call to 'cpp_function_def<Foo>(int& (Foo::*)() &, nanobind::scope,
nanobind::name, nanobind::is_method)'
567 | cpp_function_def<T>((detail::forward_t<Func>) f, scope(*this),
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
568 | name(name_), is_method(), extra...);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do I need some sort of wrapper class with a non-ref-qualified method?