optional can be used as the return type of a factory that may fail
| 5 | |
| 6 | // optional can be used as the return type of a factory that may fail |
| 7 | std::optional<std::string> create(bool b) { |
| 8 | if (b) |
| 9 | return "Godzilla"; |
| 10 | return {}; |
| 11 | } |
| 12 | |
| 13 | // std::nullopt can be used to create any (empty) std::optional |
| 14 | auto create2(bool b) { |