Created
February 13, 2020 14:37
-
-
Save multun/8d0056b34e357013307656eef274c3c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
#include <iostream> | |
template<class T> | |
struct BaseA { | |
static void test() { | |
std::cout << "int" << std::endl; | |
} | |
}; | |
template<class T> | |
struct FloatA { | |
static void test() { | |
std::cout << "float" << std::endl; | |
} | |
}; | |
template<class T, class Enable = void> | |
struct ADispatch { | |
using type = BaseA<T>; | |
}; | |
template<class T> | |
struct ADispatch<T, typename std::enable_if<std::is_floating_point<T>::value>::type> { | |
using type = FloatA<T>; | |
}; | |
template<class T> | |
using A = typename ADispatch<T>::type; | |
int main() | |
{ | |
A<int>::test(); | |
A<double>::test(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment