The fact optional implemented .value_or() with a return by value is a mistake. Expected need not repeat that mistake.
I might have missed something, but if .value_or() returns a reference, won't:
auto &&s = std::optionalstd::string{}.value_or("temporary"s); std::cout << s << std::endl;
triggers undefined behavior?
'"temporary"s' is destroyed right after the declaration of 's', hence 's' is a dangling reference.
By requiring .value_or() to return by value, this should just work.
Does not the bind to a reference keep the std::string temporary object alive? https://godbolt.org/g/ZcLpe5 suggests that it does. But you might be onto something. Some other combination with value_or() might well produce a reference to a deleted temporary. That would explain the choice of value returning semantics for value_or(). Niall -- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/