Skip to content

Instantly share code, notes, and snippets.

@Newlifer
Created July 21, 2016 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Newlifer/bfa41f25c4b19a262ceb39cf310c4b0a to your computer and use it in GitHub Desktop.
Save Newlifer/bfa41f25c4b19a262ceb39cf310c4b0a to your computer and use it in GitHub Desktop.
#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