Last active
August 29, 2015 14:07
-
-
Save DieHertz/1db611d78b6ab73f79ea 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
#include <chrono> | |
#include <random> | |
#include <iostream> | |
template<typename T> struct match_impl { | |
template<typename F> match_impl& operator()(const T& cond, F f) { | |
if (value == cond) f(); | |
return *this; | |
} | |
const T& value; | |
}; | |
template<typename T> match_impl<T> match(const T& value) { | |
return match_impl<T>{value}; | |
} | |
int main() { | |
std::mt19937 engine(std::chrono::system_clock::now().time_since_epoch().count()); | |
std::uniform_int_distribution<int> distribution{0, 9}; | |
const auto value(distribution(engine)); | |
std::cout << value << std::endl; | |
match(value) | |
(0, [] { std::cout << "one\n"; }) | |
(1, [] { std::cout << "two\n"; }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment