Skip to content

Instantly share code, notes, and snippets.

@jeremytregunna
Created April 9, 2014 22:17
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/10324276 to your computer and use it in GitHub Desktop.
Save jeremytregunna/10324276 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment