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

102 lines
3.0 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[any.assign]
# 22 General utilities library [[utilities]](./#utilities)
## 22.7 Storage for any type [[any]](any#assign)
### 22.7.4 Class any [[any.class]](any.class#any.assign)
#### 22.7.4.3 Assignment [any.assign]
[🔗](#lib:operator=,any)
`any& operator=(const any& rhs);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7315)
*Effects*: As if by any(rhs).swap(*this)[.](#1.sentence-1)
No effects if an exception is thrown[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7320)
*Returns*: *this[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7324)
*Throws*: Any exceptions arising from the copy constructor for the contained value[.](#3.sentence-1)
[🔗](#lib:operator=,any_)
`any& operator=(any&& rhs) noexcept;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7335)
*Effects*: As if by any(std::move(rhs)).swap(*this)[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7339)
*Postconditions*: The state of *this is equivalent to the original state of rhs[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7343)
*Returns*: *this[.](#6.sentence-1)
[🔗](#lib:operator=,any__)
`template<class T>
any& operator=(T&& rhs);
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7355)
Let VT be decay_t<T>[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7358)
*Constraints*: VT is not the same type as any andis_copy_constructible_v<VT> is true[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7363)
*Preconditions*: VT meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7367)
*Effects*: Constructs an object tmp of type any that contains an object of type VT direct-initialized with std::forward<T>(rhs), and tmp.swap(*this)[.](#10.sentence-1)
No effects if an exception is thrown[.](#10.sentence-2)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7372)
*Returns*: *this[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7376)
*Throws*: Any exception thrown by the selected constructor of VT[.](#12.sentence-1)