| 23 | } |
| 24 | |
| 25 | int main() |
| 26 | { |
| 27 | std::cout << "create(false) returned " |
| 28 | << create(false).value_or("empty") << '\n'; |
| 29 | |
| 30 | // optional-returning factory functions are usable as conditions of while and if |
| 31 | if (auto str = create2(true)) { |
| 32 | std::cout << "create2(true) returned " << *str << '\n'; |
| 33 | } |
| 34 | |
| 35 | if (auto str = create_ref(true)) { |
| 36 | // using get() to access the reference_wrapper's value |
| 37 | std::cout << "create_ref(true) returned " << str->get() << '\n'; |
| 38 | str->get() = "Mothra"; |
| 39 | std::cout << "modifying it changed it to " << str->get() << '\n'; |
| 40 | } |
| 41 | } |
nothing calls this directly
no test coverage detected