Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
/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());
auto o = get_fancy_shit();
if (o) {
printf("We have some fancy shit\n");
} else {
printf("We have no fancy shit\n");
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.