veselink1 / refl-cpp

Static reflection for C++17 (compile-time enumeration, attributes, proxies, overloads, template functions, metaprogramming).
https://veselink1.github.io/refl-cpp/md__introduction.html
MIT License
1.06k stars 77 forks source link

Reflecting const/non const function overloads #2

Closed cszawisza closed 4 years ago

cszawisza commented 5 years ago

Hi!

I got an class

class X{};

class A{
public:
  X& foo();
  const X& foo() const;
};

And I want to bind it to couple of script languages (chaiscript, python) and I need information about constness of given method for example pybind handles it by adding an additional tag

struct Widget {
    int foo(int x, float y);
    int foo(int x, float y) const;
};

py::class_<Widget>(m, "Widget")
   .def("foo_mutable", py::overload_cast<int, float>(&Widget::foo))
   .def("foo_const",   py::overload_cast<int, float>(&Widget::foo, py::const_));

How to properly reflect those methods using refl-cpp library?

veselink1 commented 4 years ago

Sorry, but it is not entirely clear to me what the use case is. refl-cpp generally differentiates members by their name only. That is, a member descriptor in refl-cpp is responsible for all overloads of a member function "foo". If you would like to obtain a pointer to a member function, you could use the .pointer member variable of the descriptor. It is only available if .is_resolved is true though, otherwise, you will be required to use the .resolve() member function and provide it with the full type of the function pointer which is required. There currently is no easier way to resolve an overloaded function pointer, but work is being done to resolve this issue.