constexpr variant() noexcept(/* see below */); | (1) | (since C++17) |
variant(const variant& other); | (2) | (since C++17) |
variant(variant&& other) noexcept(/* see below */); | (3) | (since C++17) |
template< class T > constexpr variant(T&& t) noexcept(/* see below */); | (4) | (since C++17) |
template< class T, class... Args > constexpr explicit variant(std::in_place_type_t<T>, Args&&... args); | (5) | (since C++17) |
template< class T, class U, class... Args >
constexpr explicit variant(std::in_place_type_t<T>,
std::initializer_list<U> il, Args&&... args);
| (6) | (since C++17) |
template< std::size_t I, class... Args > constexpr explicit variant(std::in_place_index_t<I>, Args&&... args); | (7) | (since C++17) |
template <size_t I, class U, class... Args>
constexpr explicit variant(std::in_place_index_t<I>,
std::initializer_list<U> il, Args&&... args);
| (8) | (since C++17) |
template <class Alloc> variant(std::allocator_arg_t, const Alloc& a); | (9) | (since C++17) |
template <class Alloc> variant(std::allocator_arg_t, const Alloc& a, const variant& other); | (10) | (since C++17) |
template <class Alloc> variant(std::allocator_arg_t, const Alloc& a, variant&& other); | (11) | (since C++17) |
template <class Alloc, class T> variant(std::allocator_arg_t, const Alloc& a, T&& t); | (12) | (since C++17) |
template <class Alloc, class T, class... Args>
variant(std::allocator_arg_t, const Alloc& a,
std::in_place_type_t<T>, Args&&... args);
| (13) | (since C++17) |
template <class Alloc, class T, class U, class... Args>
variant(std::allocator_arg_t, const Alloc& a,
std::in_place_type_t<T>, std::initializer_list<U> il, Args&&... args);
| (14) | (since C++17) |
template <class Alloc, size_t I, class... Args>
variant(std::allocator_arg_t, const Alloc& a,
std::in_place_index_t<I>, Args&&... args);
| (15) | (since C++17) |
template <class Alloc, size_t I, class U, class... Args>
variant(std::allocator_arg_t, const Alloc& a,
std::in_place_index_t<I>, std::initializer_list<U> il, Args&&... args);
| (16) | (since C++17) |
Constructs a new variant object.
index() is zero). This constructor is constexpr if and only if the value initialization of the alternative type T_0 would satisfy the requirements for a constexpr function. This overload only participates in overload resolution if std::is_default_constructible_v<T_0> is true.other is not valueless_by_exception, constructs a variant holding the same alternative as other and direct-initializes the contained value with std::get<other.index()>(other). Otherwise, initializes a valueless_by_exception variant. This overload only participates in overload resolution if std::is_copy_constructible_v<T_i> is true for all T_i in Types....other is not valueless_by_exception, constructs a variant holding the same alternative as other and direct-initializes the contained value with std::get<other.index()>(std::move(other)). Otherwise, initializes a valueless_by_exception variant. This overload only participates in overload resolution if std::is_move_constructible_v<T_i> is true for all T_i in Types...
T_j that would be selected by overload resolution for the expression F(std::forward<T>(t) if there was an overload of imaginary function F(T_i) for every T_i from Types... in scope at the same time. Direct-initializes the contained value as if by direct non-list-initialization from std::forward<T>(t). This overload only participates in overload resolution if std::is_same_v<std::decay_t<T>, variant> is false, std::decay_t<T> is neither a specialization of std::in_place_type_t nor a specialization of std::in_place_index_t, std::is_constructible_v<T_j, T> is true, and the expression F(std::forward<T>(t)) (with F being the above-mentioned set of imaginary functions) is well formed. This constructor is a constexpr constructor if T_j's selected constructor is a constexpr constructor. variant<string> v("abc"); // OK
variant<string, string> w("abc"); // ill-formed, can't select the alternative to convert to
variant<string, bool> x("abc"); // OK, but chooses boolT and initializes the contained value with the arguments std::forward<Args>(args).... If T's selected constructor is a constexpr constructor, this constructor is also a constexpr constructor. This overload only participates in overload resolution if there is exactly one occurrence of T in Types... and std::is_constructible_v<T, Args...> is true.T and initializes the contained value with the arguments il, std::forward<Args>(args)..... If T's selected constructor is a constexpr constructor, this constructor is also a constexpr constructor. This overload only participates in overload resolution if there is exactly one occurrence of T in Types... and std::is_constructible_v<T, initializer_list<U>&, Args...> is true.I and initializes the contained value with the arguments std::forward<Args>(args).... If T_i's selected constructor is a constexpr constructor, this constructor is also a constexpr constructor. This overload only participates in overload resolution if I < sizeof...(Types) and std::is_constructible_v<T_i, Args...> is true. I and initializes the contained value with the arguments il, std::forward<Args>(args).... If T_i's selected constructor is a constexpr constructor, this constructor is also a constexpr constructor. This overload only participates in overload resolution if I < sizeof...(Types) and std::is_constructible_v<T_i, std::initializer_list<U>&, Args...> is true. | other | - | another variant object whose contained value to copy/move |
| t | - | value to initialize the contained value with |
| args... | - | arguments to initialize the contained value with |
| il | - | initializer list to initialize the contained value with |
| a | - | allocator to pass to the contained value |
| Type requirements | ||
-Alloc must meet the requirements of Allocator in order to use overloads (9). |
||
noexcept specification: noexcept(std::is_nothrow_default_constructible_v<T_0>)Types...
Types.... noexcept specification: noexcept( (std::is_nothrow_move_constructible_v<Types> && ...))T_j. noexcept specification: noexcept(std::is_nothrow_constructible_v<T_j, T>)
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/variant/variant