How should one use std::optional?

The simplest example I can think of: std::optional<int> try_parse_int(std::string s) { //try to parse an int from the given string, //and return “nothing” if you fail } The same thing might be accomplished with a reference argument instead (as in the following signature), but using std::optional makes the signature and usage nicer. bool try_parse_int(std::string s, … Read more

std::optional specialization for reference types

When n3406 (revision #2 of the proposal) was discussed, some committee members were uncomfortable with optional references. In n3527 (revision #3), the authors decided to make optional references an auxiliary proposal, to increase the chances of getting optional values approved and put into what became C++14. While optional didn’t quite make it into C++14 for … Read more