I have a problem with creating a function that, for a given type, if it is received from another, does something, but for all the others it does something else. My code is:
class BaseClass {}; class DerivedClass : public BaseClass {}; template <typename T> void Function(typename std::enable_if<std::is_base_of<BaseClass, T>::value, T>::type && arg) { std::cout << "Proper"; } template <typename T> void Function(T && arg) { std::cout << "Improper"; } void test() { Function(DerivedClass{}); }
For DeriviedClass and another based on BaseClass I would like to call the couting Proper function, but it is disabled by Improper . Any suggestions?
c ++ c ++ 11 templates metaprogramming
miqelm
source share