Last active
August 29, 2015 13:56
-
-
Save makulik/8943582 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 <typeinfo> | |
using namespace std; | |
template<typename FalseType, typename TrueType, bool condition> | |
struct ConditionalTypeSelector | |
{ | |
typedef void ResultType; | |
}; | |
template<typename FalseType, typename TrueType> | |
struct ConditionalTypeSelector<FalseType,TrueType,false> | |
{ | |
typedef FalseType ResultType; | |
}; | |
template<typename FalseType, typename TrueType> | |
struct ConditionalTypeSelector<FalseType,TrueType,true> | |
{ | |
typedef TrueType ResultType; | |
}; | |
struct A { | |
unsigned char member; | |
}; | |
struct B { | |
int member; | |
}; | |
struct C { | |
long long member; | |
}; | |
int main() { | |
cout << typeid | |
( ConditionalTypeSelector | |
< A,B,(sizeof(A) > sizeof(B)) | |
>::ResultType | |
).name() << endl; | |
cout << typeid | |
( ConditionalTypeSelector | |
< A,B,(sizeof(B) > sizeof(A)) | |
>::ResultType | |
).name() << endl; | |
cout << typeid | |
( ConditionalTypeSelector | |
< A,C,(sizeof(A) > sizeof(C)) | |
>::ResultType | |
).name() << endl; | |
cout << typeid | |
( ConditionalTypeSelector | |
< C,B,true>::ResultType | |
).name() << endl; | |
cout << typeid | |
( ConditionalTypeSelector | |
< C,A,false>::ResultType | |
).name() << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment