Closed phelter closed 1 month ago
Say I have an object:
class Foo { public: int bar() const {return 42;} };
Using the MethodHandle GetHandle(&Foo::bar, foo) templated function doesn't work because there is no templated function for const functions.
MethodHandle GetHandle(&Foo::bar, foo)
Could you please add the following to your list of templated types:
namespace jsonrpccxx { template<typename T, typename ReturnType, typename... ParamTypes> MethodHandle GetHandle(ReturnType (T::*method)(ParamTypes...) const, const T &instance) { std::function<ReturnType(ParamTypes...)> function = [&instance, method](ParamTypes &&...params) -> ReturnType { return (instance.*method)(std::forward<ParamTypes>(params)...); }; return GetHandle(function); } template<typename T, typename... ParamTypes> NotificationHandle GetHandle(void (T::*method)(ParamTypes...) const, const T &instance) { std::function<void(ParamTypes...)> function = [&instance, method](ParamTypes &&...params) -> void { return (instance.*method)(std::forward<ParamTypes>(params)...); }; return GetHandle(function); } } // namespace jsonrpccxx
This will allow const functions of a const instance to be called as well.
I believe these should be in include/jsonrpccxx/typemapper.hpp
include/jsonrpccxx/typemapper.hpp
Thank you, I integrated it.
Say I have an object:
Using the
MethodHandle GetHandle(&Foo::bar, foo)
templated function doesn't work because there is no templated function for const functions.Could you please add the following to your list of templated types:
This will allow const functions of a const instance to be called as well.