[BUG] - Using GetHandle with a member function using a const qualifier doesn't work
phelter opened this issue · 2 comments
phelter commented
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.
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 jsonrpccxxThis will allow const functions of a const instance to be called as well.
phelter commented
I believe these should be in include/jsonrpccxx/typemapper.hpp
cinemast commented
Thank you, I integrated it.