Skip to content

Instantly share code, notes, and snippets.

@mfukar
Created March 1, 2014 18:25
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 mfukar/9294569 to your computer and use it in GitHub Desktop.
Save mfukar/9294569 to your computer and use it in GitHub Desktop.
This is how you don't code game rules.
#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