Files
2025-10-25 03:02:53 +03:00

4.9 KiB
Raw Permalink Blame History

[variant.mod]

22 General utilities library [utilities]

22.6 Variants [variant]

22.6.3 Class template variant [variant.variant]

22.6.3.5 Modifiers [variant.mod]

🔗

template<class T, class... Args> constexpr T& emplace(Args&&... args);

1

#

Constraints: is_constructible_v<T, Args...> is true, andT occurs exactly once in Types.

2

#

Effects: Equivalent to:return emplace(std::forward(args)...); where I is the zero-based index of T in Types.

🔗

template<class T, class U, class... Args> constexpr T& emplace(initializer_list<U> il, Args&&... args);

3

#

Constraints: is_constructible_v<T, initializer_list&, Args...> is true, and T occurs exactly once in Types.

4

#

Effects: Equivalent to:return emplace(il, std::forward(args)...); where I is the zero-based index of T in Types.

🔗

template<size_t I, class... Args> constexpr variant_alternative_t<I, variant<Types...>>& emplace(Args&&... args);

5

#

Mandates: I < sizeof...(Types).

6

#

Constraints: is_constructible_v<TI, Args...> is true.

7

#

Effects: Destroys the currently contained value if valueless_by_exception() is false.

Then direct-non-list-initializes the contained value of type TI with the arguments std::forward(args)....

8

#

Postconditions: index() is I.

9

#

Returns: A reference to the new contained value.

10

#

Throws: Any exception thrown during the initialization of the contained value.

11

#

Remarks: If an exception is thrown during the initialization of the contained value, the variant is permitted to not hold a value.

🔗

template<size_t I, class U, class... Args> constexpr variant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U> il, Args&&... args);

12

#

Mandates: I < sizeof...(Types).

13

#

Constraints: is_constructible_v<TI, initializer_list&, Args...> is true.

14

#

Effects: Destroys the currently contained value if valueless_by_exception() is false.

Then direct-non-list-initializes the contained value of type TI with il, std::forward(args)....

15

#

Postconditions: index() is I.

16

#

Returns: A reference to the new contained value.

17

#

Throws: Any exception thrown during the initialization of the contained value.

18

#

Remarks: If an exception is thrown during the initialization of the contained value, the variant is permitted to not hold a value.