11---
22title : " variant Class"
3- ms.date : " 11 /04/2016 "
4- f1_keywords: ["forward_list/std::forward_list", "forward_list/std::forward_list::allocator_type", "forward_list/std::forward_list::const_iterator", "forward_list/std::forward_list::const_pointer", "forward_list/std::forward_list::const_reference", "forward_list/std::forward_list::difference_type", "forward_list/std::forward_list::iterator", "forward_list/std::forward_list::pointer", "forward_list/std::forward_list::reference", "forward_list/std::forward_list::size_type", "forward_list/std::forward_list::value_type", "forward_list/std::forward_list::assign", "forward_list/std::forward_list::before_begin", "forward_list/std::forward_list::begin", "forward_list/std::forward_list::cbefore_begin", "forward_list/std::forward_list::cbegin", "forward_list/std::forward_list::cend", "forward_list/std::forward_list::clear", "forward_list/std::forward_list::emplace_after", "forward_list/std::forward_list::emplace_front", "forward_list/std::forward_list::empty", "forward_list/std::forward_list::end", "forward_list/std::forward_list::erase_after", "forward_list/std::forward_list::front", "forward_list/std::forward_list::get_allocator", "forward_list/std::forward_list::insert_after", "forward_list/std::forward_list::max_size", "forward_list/std::forward_list::merge", "forward_list/std::forward_list::pop_front", "forward_list/std::forward_list::push_front", "forward_list/std::forward_list::remove", "forward_list/std::forward_list::remove_if", "forward_list/std::forward_list::resize", "forward_list/std::forward_list::reverse", "forward_list/std::forward_list::sort", "forward_list/std::forward_list::splice_after", "forward_list/std::forward_list::swap", "forward_list/std::forward_list::unique"]
5- helpviewer_keywords: ["std::forward_list", "std::forward_list::allocator_type", "std::forward_list::const_iterator", "std::forward_list::const_pointer", "std::forward_list::const_reference", "std::forward_list::difference_type", "std::forward_list::iterator", "std::forward_list::pointer", "std::forward_list::reference", "std::forward_list::size_type", "std::forward_list::value_type", "std::forward_list::assign", "std::forward_list::before_begin", "std::forward_list::begin", "std::forward_list::cbefore_begin", "std::forward_list::cbegin", "std::forward_list::cend", "std::forward_list::clear", "std::forward_list::emplace_after", "std::forward_list::emplace_front", "std::forward_list::empty", "std::forward_list::end", "std::forward_list::erase_after", "std::forward_list::front", "std::forward_list::get_allocator", "std::forward_list::insert_after", "std::forward_list::max_size", "std::forward_list::merge", "std::forward_list::pop_front", "std::forward_list::push_front", "std::forward_list::remove", "std::forward_list::remove_if", "std::forward_list::resize", "std::forward_list::reverse", "std::forward_list::sort", "std::forward_list::splice_after", "std::forward_list::swap", "std::forward_list::unique"]
3+ ms.date : " 04 /04/2019 "
4+ f1_keywords : ["variant/std::variant", "variant/std::variant::emplace", "variant/std::variant::index", "variant/std::variant::valueless_by_exception"]
5+ helpviewer_keywords : ["variant/std::variant", "variant/std::variant::emplace", "variant/std::variant::index", "variant/std::variant::valueless_by_exception"]
66---
77# variant Class
88
99Any instance of variant at any given time either holds a value of one of its alternative types, or it holds no value.
1010
11- namespace std {
12- template <class... Types>
13- class variant {
14-
15- // 23.7.3.5, value status
16-
17- constexpr size_t index() const noexcept;
18- };
19- }
20-
2111## Syntax
2212
2313``` cpp
24- template <class Type ,
25- class Allocator = allocator<Type >>
26- class forward_list
14+ template <class ... Types>
15+ class variant
2716```
2817
2918### Constructors
@@ -36,9 +25,9 @@ class forward_list
3625
3726|Member function|Description|
3827|-|-|
39- |[emplace](#emplace)|Erases elements from a forward list and copies a new set of elements to a target forward list .|
40- |[index](#index)|Erases elements from a forward list and copies a new set of elements to a target forward list .|
41- |[valueless_by_exception](#emplace)|Erases elements from a forward list and copies a new set of elements to a target forward list .|
28+ |[emplace](#emplace)|Creates a new contained value .|
29+ |[index](#index)|Returns the index of a contained value .|
30+ |[valueless_by_exception](#emplace)|Returns **false** if the variant holds a value .|
4231
4332### Operators
4433
@@ -54,7 +43,7 @@ class forward_list
5443
5544## <a name="emplace"></a> variant::emplace
5645
57- No description .
46+ Creates a new contained value .
5847
5948```cpp
6049template <class T, class... Args>
@@ -69,10 +58,10 @@ template <size_t I, class U, class... Args>
6958
7059## <a name =" index " ></a > variant::index
7160
72- No description .
61+ Returns the index of a contained value .
7362
7463``` cpp
75-
64+ constexpr size_t index () const noexcept ;
7665```
7766
7867## <a name =" variant " ></a > variant::variant
@@ -84,45 +73,39 @@ constexpr variant() noexcept(see below);
8473variant(const variant&);
8574variant(variant&&) noexcept(see below);
8675template <class T >
87- constexpr variant(T&&) noexcept(see below);
76+ constexpr variant(T&&) noexcept(see below);
8877template <class T, class... Args>
89- constexpr explicit variant(in_place_type_t<T >, Args&&...);
78+ constexpr explicit variant(in_place_type_t<T >, Args&&...);
9079template <class T, class U, class... Args>
91- constexpr explicit variant(in_place_type_t<T >, initializer_list<U >, Args&&...);
80+ constexpr explicit variant(in_place_type_t<T >, initializer_list<U >, Args&&...);
9281template <size_t I, class... Args>
93- constexpr explicit variant(in_place_index_t<I >, Args&&...);
82+ constexpr explicit variant(in_place_index_t<I >, Args&&...);
9483template <size_t I, class U, class... Args>
95- constexpr explicit variant(in_place_index_t<I >, initializer_list<U >, Args&&...);
96- // allocator-extended constructors
84+ constexpr explicit variant(in_place_index_t<I >, initializer_list<U >, Args&&...);
85+
9786template <class Alloc >
98- variant(allocator_arg_t, const Alloc &);
87+ variant(allocator_arg_t, const Al &);
9988template <class Alloc >
100- variant(allocator_arg_t, const Alloc &, const variant&);
89+ variant(allocator_arg_t, const Al &, const variant&);
10190template <class Alloc >
102- variant(allocator_arg_t, const Alloc &, variant&&);
91+ variant(allocator_arg_t, const Al &, variant&&);
10392template <class Alloc, class T>
104- variant(allocator_arg_t, const Alloc &, T&&);
93+ variant(allocator_arg_t, const Al &, T&&);
10594template <class Alloc, class T, class... Args>
106- variant(allocator_arg_t, const Alloc &, in_place_type_t<T >, Args&&...);
95+ variant(allocator_arg_t, const Al &, in_place_type_t<T >, Args&&...);
10796template <class Alloc, class T, class U, class... Args>
108- variant(allocator_arg_t, const Alloc &, in_place_type_t<T >, initializer_list<U >, Args&&...);
97+ variant(allocator_arg_t, const Al &, in_place_type_t<T >, initializer_list<U >, Args&&...);
10998template <class Alloc, size_t I, class... Args>
110- variant(allocator_arg_t, const Alloc &, in_place_index_t<I >, Args&&...);
99+ variant(allocator_arg_t, const Al &, in_place_index_t<I >, Args&&...);
111100template <class Alloc, size_t I, class U, class... Args>
112- variant(allocator_arg_t, const Alloc &, in_place_index_t<I >, initializer_list<U >, Args&&...);
101+ variant(allocator_arg_t, const Al &, in_place_index_t<I >, initializer_list<U >, Args&&...);
113102```
114103
115104### Parameters
116105
117106|Parameter|Description|
118107|---------------|-----------------|
119108|*Al*|The allocator class to use with this object.|
120- |*Count*|The number of elements in the list constructed.|
121- |*Val*|The value of the elements in the list constructed.|
122- |*Right*|The list of which the constructed list is to be a copy.|
123- |*First*|The position of the first element in the range of elements to be copied.|
124- |*Last*|The position of the first element beyond the range of elements to be copied.|
125- |*IList*|The initializer_list to copy.|
126109
127110## <a name="op_eq"></a> variant::operator=
128111
@@ -137,12 +120,12 @@ template <class T>
137120
138121## <a name =" valueless " ></a > variant::valueless_by_exception
139122
140- No description .
123+ Returns ** false ** if the variant holds a value .
141124
142125``` cpp
143126constexpr bool valueless_by_exception () const noexcept ;
144127```
145128
146129## See also
147130
148- [ <variant >] ( ../standard-library/variant.md ) < br />
131+ [ <variant >] ( ../standard-library/variant.md )
0 commit comments