Skip to content

Instantly share code, notes, and snippets.

@kybernetyk
Created May 18, 2014 10:01
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 kybernetyk/02f4e017abb5f6483121 to your computer and use it in GitHub Desktop.
Save kybernetyk/02f4e017abb5f6483121 to your computer and use it in GitHub Desktop.
//compile with:
// clang++ -std=c++1y -stdlib=libc++ optional.cpp
#include <experimental/optional>
#include <string>
#include <cstdio>
std::experimental::optional<std::string> get_fancy_shit() {
//return std::string("some fancy shit!");
return std::experimental::nullopt;
}
int main(int argc, char *argv[]) {
auto s = get_fancy_shit().value_or("no fancy shit!");
printf("I got: %s\n", s.c_str());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment