-
-
Save ddemidov/3992260 to your computer and use it in GitHub Desktop.
sfinae enabler
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
/* | |
* third.cpp | |
* Date: 2012-11-01 | |
* Author: Karsten Ahnert (karsten.ahnert@gmx.de) | |
*/ | |
#include <iostream> | |
#include <boost/utility/enable_if.hpp> | |
#define tab "\t" | |
using namespace std; | |
template <int N> | |
struct A { }; | |
template <int N> | |
struct B { }; | |
template< class T > struct is_a_or_b {}; | |
template<int N> struct is_a_or_b< A<N> > { const static bool value = true; }; | |
template<int N> struct is_a_or_b< B<N> > { const static bool value = true; }; | |
template< class Class , class Enabler = void > struct dispatcher; | |
template< class T > | |
struct dispatcher< T , typename boost::enable_if_c< is_a_or_b< T >::value > ::type > | |
{ | |
const static size_t value = 2; | |
}; | |
template<int N> | |
struct dispatcher< A<N> > | |
{ | |
const static size_t value = 1; | |
}; | |
int main( int argc , char *argv[] ) | |
{ | |
cout << dispatcher< A<1> >::value << endl; | |
cout << dispatcher< B<1> >::value << endl; | |
return 0; | |
} |
Author
ddemidov
commented
Nov 1, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment