Created
December 19, 2012 07:25
-
-
Save argv0/4335050 to your computer and use it in GitHub Desktop.
compile with clang++ --std=c++11 maybe.cpp
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 <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()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
compile with clang++ --std=c++11 maybe.cpp