188 lines
6.1 KiB
Markdown
188 lines
6.1 KiB
Markdown
[any.cons]
|
||
|
||
# 22 General utilities library [[utilities]](./#utilities)
|
||
|
||
## 22.7 Storage for any type [[any]](any#cons)
|
||
|
||
### 22.7.4 Class any [[any.class]](any.class#any.cons)
|
||
|
||
#### 22.7.4.2 Construction and destruction [any.cons]
|
||
|
||
[ð](#lib:any,constructor)
|
||
|
||
`constexpr any() noexcept;
|
||
`
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7164)
|
||
|
||
*Postconditions*: has_value() is false[.](#1.sentence-1)
|
||
|
||
[ð](#lib:any,constructor_)
|
||
|
||
`any(const any& other);
|
||
`
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7175)
|
||
|
||
*Effects*: If other.has_value() is false, constructs an object that has no value[.](#2.sentence-1)
|
||
|
||
Otherwise, equivalent to any(in_place_type<T>, any_cast<const T&>(other)) where T is the type of the contained value[.](#2.sentence-2)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7181)
|
||
|
||
*Throws*: Any exceptions arising from calling the selected constructor for the contained value[.](#3.sentence-1)
|
||
|
||
[ð](#lib:any,constructor__)
|
||
|
||
`any(any&& other) noexcept;
|
||
`
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7192)
|
||
|
||
*Effects*: If other.has_value() is false, constructs an object that has no value[.](#4.sentence-1)
|
||
|
||
Otherwise, constructs an object of type any that
|
||
contains either the contained value of other, or
|
||
contains an object of the same type constructed from
|
||
the contained value of other considering that contained value as an rvalue[.](#4.sentence-2)
|
||
|
||
[ð](#lib:any,constructor___)
|
||
|
||
`template<class T>
|
||
any(T&& value);
|
||
`
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7208)
|
||
|
||
Let VT be decay_t<T>[.](#5.sentence-1)
|
||
|
||
[6](#6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7211)
|
||
|
||
*Constraints*: VT is not the same type as any,VT is not a specialization of in_place_type_t,
|
||
and is_copy_constructible_v<VT> is true[.](#6.sentence-1)
|
||
|
||
[7](#7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7217)
|
||
|
||
*Preconditions*: VT meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#7.sentence-1)
|
||
|
||
[8](#8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7221)
|
||
|
||
*Effects*: Constructs an object of type any that contains an object of type VT direct-initialized with std::forward<T>(value)[.](#8.sentence-1)
|
||
|
||
[9](#9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7225)
|
||
|
||
*Throws*: Any exception thrown by the selected constructor of VT[.](#9.sentence-1)
|
||
|
||
[ð](#lib:any,constructor____)
|
||
|
||
`template<class T, class... Args>
|
||
explicit any(in_place_type_t<T>, Args&&... args);
|
||
`
|
||
|
||
[10](#10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7237)
|
||
|
||
Let VT be decay_t<T>[.](#10.sentence-1)
|
||
|
||
[11](#11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7240)
|
||
|
||
*Constraints*: is_copy_constructible_v<VT> is true andis_constructible_v<VT, Args...> is true[.](#11.sentence-1)
|
||
|
||
[12](#12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7245)
|
||
|
||
*Preconditions*: VT meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#12.sentence-1)
|
||
|
||
[13](#13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7249)
|
||
|
||
*Effects*: Direct-non-list-initializes the contained value of type VT with std::forward<Args>(args)...[.](#13.sentence-1)
|
||
|
||
[14](#14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7254)
|
||
|
||
*Postconditions*: *this contains a value of type VT[.](#14.sentence-1)
|
||
|
||
[15](#15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7258)
|
||
|
||
*Throws*: Any exception thrown by the selected constructor of VT[.](#15.sentence-1)
|
||
|
||
[ð](#lib:any,constructor_____)
|
||
|
||
`template<class T, class U, class... Args>
|
||
explicit any(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
|
||
`
|
||
|
||
[16](#16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7270)
|
||
|
||
Let VT be decay_t<T>[.](#16.sentence-1)
|
||
|
||
[17](#17)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7273)
|
||
|
||
*Constraints*: is_copy_constructible_v<VT> is true andis_constructible_v<VT, initializer_list<U>&, Args...> is true[.](#17.sentence-1)
|
||
|
||
[18](#18)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7278)
|
||
|
||
*Preconditions*: VT meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#18.sentence-1)
|
||
|
||
[19](#19)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7282)
|
||
|
||
*Effects*: Direct-non-list-initializes the contained value of type VT with il, std::forward<Args>(args)...[.](#19.sentence-1)
|
||
|
||
[20](#20)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7287)
|
||
|
||
*Postconditions*: *this contains a value[.](#20.sentence-1)
|
||
|
||
[21](#21)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7291)
|
||
|
||
*Throws*: Any exception thrown by the selected constructor of VT[.](#21.sentence-1)
|
||
|
||
[ð](#lib:any,destructor)
|
||
|
||
`~any();
|
||
`
|
||
|
||
[22](#22)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7302)
|
||
|
||
*Effects*: As if by reset()[.](#22.sentence-1)
|