Created
December 2, 2017 02:14
-
-
Save marty1885/566fd5e609274786cb5ec9c1f30d2511 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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