Skip to content

[BUG] - Using GetHandle with a member function using a const qualifier doesn't work #45

Closed
@phelter

Description

@phelter

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 jsonrpccxx

This will allow const functions of a const instance to be called as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions