Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jeremytregunna
Created September 22, 2014 04:08
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 jeremytregunna/bcde49beaa2020cdc45b to your computer and use it in GitHub Desktop.
Save jeremytregunna/bcde49beaa2020cdc45b to your computer and use it in GitHub Desktop.
#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