Created
September 22, 2014 04:08
-
-
Save jeremytregunna/bcde49beaa2020cdc45b to your computer and use it in GitHub Desktop.
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> | |
using namespace std; | |
template<class X> using Maybe = std::unique_ptr<X>; | |
template<class X> Maybe<X> Just(const X& x) | |
{ | |
return Maybe<X>( new X(x) ); | |
} | |
template<class X> Maybe<X> Nothing() | |
{ | |
return Maybe<X>(nullptr); | |
} | |
template<class X> const X& fromJust(const Maybe<X>& m) | |
{ | |
return *m; | |
} | |
int main(void) | |
{ | |
auto x = Just<bool>(false); | |
if(x != Nothing<bool>()) | |
std::cout << fromJust(x) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment