Skip to content

Instantly share code, notes, and snippets.

@multun
Created February 13, 2020 14:37
Show Gist options
  • Save multun/8d0056b34e357013307656eef274c3c1 to your computer and use it in GitHub Desktop.
Save multun/8d0056b34e357013307656eef274c3c1 to your computer and use it in GitHub Desktop.
#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