Created
July 21, 2016 11:47
-
-
Save Newlifer/bfa41f25c4b19a262ceb39cf310c4b0a 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 <iostream> | |
#include <vector> | |
#include <type_traits> | |
template < typename Tp, typename... List > | |
struct contains : std::true_type {}; | |
template < typename Tp, typename Head, typename... Rest > | |
struct contains<Tp, Head, Rest...> | |
: std::conditional< std::is_same<Tp, Head>::value, | |
std::true_type, | |
contains<Tp, Rest...> | |
>::type {}; | |
template<typename... Types> | |
struct foo | |
{ | |
template<typename Arg, typename = void> | |
void f(Arg) | |
{ | |
static_assert(false, "Type is not allowed"); | |
} | |
template<typename Arg, typename std::enable_if<contains<Arg, Types...>::value>::type*> | |
void f(Arg) | |
{} | |
}; | |
int main() { | |
foo<int, float> f; | |
f.f(std::string()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment