MCPcopy Create free account
hub / github.com/0voice/cpp_new_features / main

Function main

cpp_17/006_variant_monostate.cpp:11–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9};
10
11int 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected