Created
September 8, 2014 16:40
-
-
Save DieHertz/bcd0048f62f64796066b to your computer and use it in GitHub Desktop.
This file contains hidden or 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<typename... T> struct type_list; | |
template<typename T, typename List> struct in; | |
template<typename T, typename Head, typename... Tail> struct in<T, type_list<Head, Tail...>> { | |
static constexpr auto value = std::is_same<T, Head>::value || in<T, type_list<Tail...>>::value; | |
}; | |
template<typename T> struct in<T, type_list<>> { | |
static constexpr auto value = false; | |
}; | |
template<typename T, | |
typename std::enable_if<in<T, type_list<float, double, long double>>::value>::type * = nullptr> | |
void foo(T) { std::cout << "floating overload" << std::endl; } | |
template<typename T, | |
typename std::enable_if<in<T, type_list<signed char, short, int, long, long long>>::value>::type * = nullptr> | |
void foo(T) { std::cout << "signed integer overload" << std::endl; } | |
template<typename T, | |
typename std::enable_if<in<T, | |
type_list<unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long>>::value>::type * = nullptr> | |
void foo(T) { std::cout << "unsigned integer overload" << std::endl; } | |
void foo(char) { std::cout << "char overload" << std::endl; } | |
int main() { | |
foo('\0'); | |
foo(0); | |
foo(1.0f); | |
foo(0ULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment