This is how you don't code game rules.
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> | |
enum stuff { | |
laugh, | |
strike, | |
slap, | |
}; | |
struct true_ {}; | |
struct false_ {}; | |
template<unsigned> | |
struct stuffTriggersSlap { typedef false_ T; }; | |
template<> | |
struct stuffTriggersSlap<strike> { typedef true_ T; }; | |
template<> | |
struct stuffTriggersSlap<slap> { typedef true_ T; }; | |
template<typename T> | |
void maybeTriggerSlap(void) | |
{ | |
std::cout << "Not slapped." << std::endl; | |
} | |
template<> | |
void maybeTriggerSlap<true_>(void) | |
{ | |
std::cout << "Slapped." << std::endl; | |
} | |
int main (int argc, char **argv) | |
{ | |
maybeTriggerSlap<typename stuffTriggersSlap<laugh>::T>(); | |
maybeTriggerSlap<typename stuffTriggersSlap<strike>::T>(); | |
maybeTriggerSlap<typename stuffTriggersSlap<slap>::T>(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment