Skip to content

Instantly share code, notes, and snippets.

@marty1885
Created December 2, 2017 02:14
Show Gist options
  • Save marty1885/566fd5e609274786cb5ec9c1f30d2511 to your computer and use it in GitHub Desktop.
Save marty1885/566fd5e609274786cb5ec9c1f30d2511 to your computer and use it in GitHub Desktop.
template<typename VType>
void Switch(const VType& val)
{
}
template<typename VType, typename Func>
void Switch(const VType& val, Func func)
{
func();
}
template<typename VType
,typename Func, typename ... Args>
void Switch(const VType& val, const VType& arg, Func func , Args ... args)
{
If(val == arg,[&](){
func();
},[&](){
Switch(val, args ...);
});
}
int main()
{
int num = 42;
Switch(num,
42, [](){
std::cout << "Meaning of life" << std::endl;
},
60, [](){
std::cout << "How many seconds in a minute" << std::endl;
}
[](){
std::cout << "nothing" << std::endl;
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment