From Jason Turner

[variant.get]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmplhsp4axu/{from.md → to.md} +72 -0
tmp/tmplhsp4axu/{from.md → to.md} RENAMED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Value access <a id="variant.get">[[variant.get]]</a>
2
+
3
+ ``` cpp
4
+ template <class T, class... Types>
5
+ constexpr bool holds_alternative(const variant<Types...>& v) noexcept;
6
+ ```
7
+
8
+ *Requires:* The type `T` occurs exactly once in `Types...`. Otherwise,
9
+ the program is ill-formed.
10
+
11
+ *Returns:* `true` if `index()` is equal to the zero-based index of `T`
12
+ in `Types...`.
13
+
14
+ ``` cpp
15
+ template <size_t I, class... Types>
16
+ constexpr variant_alternative_t<I, variant<Types...>>& get(variant<Types...>& v);
17
+ template <size_t I, class... Types>
18
+ constexpr variant_alternative_t<I, variant<Types...>>&& get(variant<Types...>&& v);
19
+ template <size_t I, class... Types>
20
+ constexpr const variant_alternative_t<I, variant<Types...>>& get(const variant<Types...>& v);
21
+ template <size_t I, class... Types>
22
+ constexpr const variant_alternative_t<I, variant<Types...>>&& get(const variant<Types...>&& v);
23
+ ```
24
+
25
+ *Requires:* `I < sizeof...(Types)`. Otherwise the program is ill-formed.
26
+
27
+ *Effects:* If `v.index()` is `I`, returns a reference to the object
28
+ stored in the `variant`. Otherwise, throws an exception of type
29
+ `bad_variant_access`.
30
+
31
+ ``` cpp
32
+ template <class T, class... Types> constexpr T& get(variant<Types...>& v);
33
+ template <class T, class... Types> constexpr T&& get(variant<Types...>&& v);
34
+ template <class T, class... Types> constexpr const T& get(const variant<Types...>& v);
35
+ template <class T, class... Types> constexpr const T&& get(const variant<Types...>&& v);
36
+ ```
37
+
38
+ *Requires:* The type `T` occurs exactly once in `Types...`. Otherwise,
39
+ the program is ill-formed.
40
+
41
+ *Effects:* If `v` holds a value of type `T`, returns a reference to that
42
+ value. Otherwise, throws an exception of type `bad_variant_access`.
43
+
44
+ ``` cpp
45
+ template <size_t I, class... Types>
46
+ constexpr add_pointer_t<variant_alternative_t<I, variant<Types...>>>
47
+ get_if(variant<Types...>* v) noexcept;
48
+ template <size_t I, class... Types>
49
+ constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...>>>
50
+ get_if(const variant<Types...>* v) noexcept;
51
+ ```
52
+
53
+ *Requires:* `I < sizeof...(Types)`. Otherwise the program is ill-formed.
54
+
55
+ *Returns:* A pointer to the value stored in the `variant`, if
56
+ `v != nullptr` and `v->index() == I`. Otherwise, returns `nullptr`.
57
+
58
+ ``` cpp
59
+ template <class T, class... Types>
60
+ constexpr add_pointer_t<T>
61
+ get_if(variant<Types...>* v) noexcept;
62
+ template <class T, class... Types>
63
+ constexpr add_pointer_t<const T>
64
+ get_if(const variant<Types...>* v) noexcept;
65
+ ```
66
+
67
+ *Requires:* The type `T` occurs exactly once in `Types...`. Otherwise,
68
+ the program is ill-formed.
69
+
70
+ *Effects:* Equivalent to: `return get_if<`i`>(v);` with i being the
71
+ zero-based index of `T` in `Types...`.
72
+