Files
cppdraft_translate/cppdraft/any/modifiers.md
2025-10-25 03:02:53 +03:00

4.8 KiB
Raw Permalink Blame History

[any.modifiers]

22 General utilities library [utilities]

22.7 Storage for any type [any]

22.7.4 Class any [any.class]

22.7.4.4 Modifiers [any.modifiers]

🔗

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

1

#

Let VT be decay_t.

2

#

Constraints: is_copy_constructible_v is true andis_constructible_v<VT, Args...> is true.

3

#

Preconditions: VT meets the Cpp17CopyConstructible requirements.

4

#

Effects: Calls reset().

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

5

#

Postconditions: *this contains a value.

6

#

Returns: A reference to the new contained value.

7

#

Throws: Any exception thrown by the selected constructor of VT.

8

#

Remarks: If an exception is thrown during the call to VT's constructor,*this does not contain a value, and any previously contained value has been destroyed.

🔗

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

9

#

Let VT be decay_t.

10

#

Constraints: is_copy_constructible_v is true andis_constructible_v<VT, initializer_list&, Args...> is true.

11

#

Preconditions: VT meets the Cpp17CopyConstructible requirements.

12

#

Effects: Calls reset().

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

13

#

Postconditions: *this contains a value.

14

#

Returns: A reference to the new contained value.

15

#

Throws: Any exception thrown by the selected constructor of VT.

16

#

Remarks: If an exception is thrown during the call to VT's constructor,*this does not contain a value, and any previously contained value has been destroyed.

🔗

void reset() noexcept;

17

#

Effects: If has_value() is true, destroys the contained value.

18

#

Postconditions: has_value() is false.

🔗

void swap(any& rhs) noexcept;

19

#

Effects: Exchanges the states of *this and rhs.