Is there a way to get result_of
to work with const overloaded member functions? The regular way demonstrated in cppreference doesn't work since the address of the overloaded function can't be resolved.
#include <type_traits>
class C {
public:
auto& f () { return x_; }
const auto& f() const { return x_; }
private:
int x_;
};
using FRet = std::result_of_t<decltype(&C::f)(C)>;
Wandbox
Do not use result_of
in this situation - you will have to manually disambiguate the overload. You can simply use decltype
and std::declval
:
using FRet = decltype(std::declval<C>().f());
If you want to hit the const
overload, use:
using FRet = decltype(std::declval<const C>().f());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With