Answer the question
In order to leave comments, you need to log in
Dependent method type (C++)
If an example of the implementation of such a thing as Dependent method type on Scala. ( link ). Is it possible to do this in C++11 (for example) or in some other language with static typing? The whole point here is to use a functional approach, but with a “hack” in the form of a class.
Answer the question
In order to leave comments, you need to log in
You need an overload on the function's input parameter. It's just that the check of the if / else condition should be shifted to the shoulders of overloaded methods, it is impossible to compare universally inside the method. Make a helper template function.
template<typename T>
struct type2type { typedef T type; }
temlate<typename U, typename T>
U helper_func(T const& method, type2type<GetX>) { return [](){return 1;}; }
temlate<typename U, typename T>
U helper_func(T const& method, type2type<ToString>) { return [](){return "aaaa";}; }
// и вызов
template <typename T>
std::result_of<typename T::signature> func(T const& method) {
return helper_func<std::result_of<typename T::signature>, T>(method, type2type<T>());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question