I'd like to specify the type of a template function as a parameter to another function.
I can almost do it like this:
template<typename T, typename U>
auto add(T left, U right) -> decltype(left + right) { return left + right; }
template<typename T, typename U>
auto subtract(T left, U right) -> decltype(left - right) { return left - right; }
void Process(??? operation) {
...
}
DoAdd() {
Process(add);
Process(subtract);
}
It feels like add
and subtract
could have a same type, but I'm not sure how to express that to the compiler. For example, GCC gives me this error for this code:
Is it possible to express the type of template functions (or lambdas) like this?