Skip to content

Instantly share code, notes, and snippets.

@argv0
Created December 19, 2012 07:25
Show Gist options
  • Save argv0/4335050 to your computer and use it in GitHub Desktop.
Save argv0/4335050 to your computer and use it in GitHub Desktop.
compile with clang++ --std=c++11 maybe.cpp
#include <cstdio>
#include <boost/optional.hpp>
template <class T>
using Maybe = boost::optional<T>;
Maybe<int> isYouPositive(int val)
{
return val > 0 ? Maybe<int>(val) : Maybe<int>();
}
int main(void)
{
auto valid = isYouPositive(1);
auto invalid = isYouPositive(-1);
printf("%d\n", valid.get());
printf("%d\n", invalid.get());
}
@argv0
Copy link
Author

argv0 commented Dec 19, 2012

compile with clang++ --std=c++11 maybe.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment