| 9 | }; |
| 10 | |
| 11 | int main() { |
| 12 | |
| 13 | // Without the monostate type this declaration will fail. |
| 14 | // This is because S is not default-constructible. |
| 15 | |
| 16 | std::variant<std::monostate, S> var; |
| 17 | assert(var.index() == 0); |
| 18 | |
| 19 | try { |
| 20 | std::get<S>(var); // throws! We need to assign a value |
| 21 | } |
| 22 | catch(const std::bad_variant_access& e) { |
| 23 | std::cout << e.what() << '\n'; |
| 24 | } |
| 25 | |
| 26 | var = 12; |
| 27 | |
| 28 | std::cout << std::get<S>(var).i << '\n'; |
| 29 | } |
nothing calls this directly
no outgoing calls
no test coverage detected