We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fc1b201 commit eb1ee8cCopy full SHA for eb1ee8c
cpp_17/006_variant_variant_npos.cpp
@@ -1 +1,27 @@
1
-1
+#include <iostream>
2
+#include <stdexcept>
3
+#include <string>
4
+#include <variant>
5
+
6
+struct Demon
7
+{
8
+ Demon(int) {}
9
+ Demon(const Demon&) { throw std::domain_error("copy ctor"); }
10
+ Demon& operator= (const Demon&) = default;
11
+};
12
13
+int main()
14
15
+ std::variant<int, Demon> var{42};
16
+ std::cout
17
+ << std::boolalpha
18
+ << "index == npos: " << (var.index() == std::variant_npos) << '\n';
19
20
+ try { var = Demon{666}; } catch (const std::domain_error& ex)
21
+ {
22
23
+ << "Exception: " << ex.what() << '\n'
24
+ << "index == npos: " << (var.index() == std::variant_npos) << '\n'
25
+ << "valueless: " << var.valueless_by_exception() << '\n';
26
+ }
27
+}
0 commit comments