I am writing a member function of a class that will accept a lambda with the given type Tin the function argument. My question is: is it possible to overload a member function at compile time based on variability of the argument? The following is an example:
template <typename T>
class Wrapper {
T _t;
template <typename F, typename R = std::result_of_t<F(T&)>>
std::enable_if_t<std::is_same<R, void>::value> operator()(F&& f) {
f(_t);
}
template <typename F, typename R = std::result_of_t<F(const T&)>>
std::enable_if_t<std::is_same<R, void>::value> operator()(F&& f) const {
f(_t);
}
};
So, I want, if you give lambda with the following signature, I need to call the first statement.
[](T&) {
...
};
For a constant argument, you need to call the second.
[](const T&) {
}
source
share