502 lines
18 KiB
Markdown
502 lines
18 KiB
Markdown
[any.class]
|
||
|
||
# 22 General utilities library [[utilities]](./#utilities)
|
||
|
||
## 22.7 Storage for any type [[any]](any#class)
|
||
|
||
### 22.7.4 Class any [any.class]
|
||
|
||
#### [22.7.4.1](#general) General [[any.class.general]](any.class.general)
|
||
|
||
namespace std {class any {public:// [[any.cons]](#any.cons "22.7.4.2 Construction and destruction"), construction and destructionconstexpr any() noexcept;
|
||
|
||
any(const any& other);
|
||
any(any&& other) noexcept; template<class T> any(T&& value); template<class T, class... Args>explicit any(in_place_type_t<T>, Args&&...); template<class T, class U, class... Args>explicit any(in_place_type_t<T>, initializer_list<U>, Args&&...); ~any(); // [[any.assign]](#any.assign "22.7.4.3 Assignment"), assignments any& operator=(const any& rhs);
|
||
any& operator=(any&& rhs) noexcept; template<class T> any& operator=(T&& rhs); // [[any.modifiers]](#any.modifiers "22.7.4.4 Modifiers"), modifierstemplate<class T, class... Args> decay_t<T>& emplace(Args&&...); template<class T, class U, class... Args> decay_t<T>& emplace(initializer_list<U>, Args&&...); void reset() noexcept; void swap(any& rhs) noexcept; // [[any.observers]](#any.observers "22.7.4.5 Observers"), observersbool has_value() const noexcept; const type_info& type() const noexcept; };}
|
||
|
||
[1](#general-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7138)
|
||
|
||
An object of class any stores an instance of any type that meets the constructor requirements or it has no value,
|
||
and this is referred to as the [*state*](#def:state "22.7.4.1 General [any.class.general]") of the class any object[.](#general-1.sentence-1)
|
||
|
||
The stored instance is called the [*contained value*](#def:contained_value,any "22.7.4.1 General [any.class.general]")[.](#general-1.sentence-2)
|
||
|
||
Two states are equivalent if either they both have no value, or they both have a value and the contained values are equivalent[.](#general-1.sentence-3)
|
||
|
||
[2](#general-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7144)
|
||
|
||
The non-member any_cast functions provide type-safe access to the contained value[.](#general-2.sentence-1)
|
||
|
||
[3](#general-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7147)
|
||
|
||
Implementations should avoid the use of dynamically allocated memory for a small contained value[.](#general-3.sentence-1)
|
||
|
||
However, any such small-object optimization shall only be applied to types T for whichis_nothrow_move_constructible_v<T> is true[.](#general-3.sentence-2)
|
||
|
||
[*Example [1](#general-example-1)*:
|
||
|
||
A contained value of type int could be stored in an internal buffer,
|
||
not in separately-allocated memory[.](#general-3.sentence-3)
|
||
|
||
â *end example*]
|
||
|
||
#### [22.7.4.2](#any.cons) Construction and destruction [[any.cons]](any.cons)
|
||
|
||
[ð](#lib:any,constructor)
|
||
|
||
`constexpr any() noexcept;
|
||
`
|
||
|
||
[1](#any.cons-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7164)
|
||
|
||
*Postconditions*: has_value() is false[.](#any.cons-1.sentence-1)
|
||
|
||
[ð](#lib:any,constructor_)
|
||
|
||
`any(const any& other);
|
||
`
|
||
|
||
[2](#any.cons-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[.](#any.cons-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[.](#any.cons-2.sentence-2)
|
||
|
||
[3](#any.cons-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[.](#any.cons-3.sentence-1)
|
||
|
||
[ð](#lib:any,constructor__)
|
||
|
||
`any(any&& other) noexcept;
|
||
`
|
||
|
||
[4](#any.cons-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[.](#any.cons-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[.](#any.cons-4.sentence-2)
|
||
|
||
[ð](#lib:any,constructor___)
|
||
|
||
`template<class T>
|
||
any(T&& value);
|
||
`
|
||
|
||
[5](#any.cons-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7208)
|
||
|
||
Let VT be decay_t<T>[.](#any.cons-5.sentence-1)
|
||
|
||
[6](#any.cons-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[.](#any.cons-6.sentence-1)
|
||
|
||
[7](#any.cons-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[.](#any.cons-7.sentence-1)
|
||
|
||
[8](#any.cons-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)[.](#any.cons-8.sentence-1)
|
||
|
||
[9](#any.cons-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7225)
|
||
|
||
*Throws*: Any exception thrown by the selected constructor of VT[.](#any.cons-9.sentence-1)
|
||
|
||
[ð](#lib:any,constructor____)
|
||
|
||
`template<class T, class... Args>
|
||
explicit any(in_place_type_t<T>, Args&&... args);
|
||
`
|
||
|
||
[10](#any.cons-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7237)
|
||
|
||
Let VT be decay_t<T>[.](#any.cons-10.sentence-1)
|
||
|
||
[11](#any.cons-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[.](#any.cons-11.sentence-1)
|
||
|
||
[12](#any.cons-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[.](#any.cons-12.sentence-1)
|
||
|
||
[13](#any.cons-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)...[.](#any.cons-13.sentence-1)
|
||
|
||
[14](#any.cons-14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7254)
|
||
|
||
*Postconditions*: *this contains a value of type VT[.](#any.cons-14.sentence-1)
|
||
|
||
[15](#any.cons-15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7258)
|
||
|
||
*Throws*: Any exception thrown by the selected constructor of VT[.](#any.cons-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](#any.cons-16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7270)
|
||
|
||
Let VT be decay_t<T>[.](#any.cons-16.sentence-1)
|
||
|
||
[17](#any.cons-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[.](#any.cons-17.sentence-1)
|
||
|
||
[18](#any.cons-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[.](#any.cons-18.sentence-1)
|
||
|
||
[19](#any.cons-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)...[.](#any.cons-19.sentence-1)
|
||
|
||
[20](#any.cons-20)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7287)
|
||
|
||
*Postconditions*: *this contains a value[.](#any.cons-20.sentence-1)
|
||
|
||
[21](#any.cons-21)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7291)
|
||
|
||
*Throws*: Any exception thrown by the selected constructor of VT[.](#any.cons-21.sentence-1)
|
||
|
||
[ð](#lib:any,destructor)
|
||
|
||
`~any();
|
||
`
|
||
|
||
[22](#any.cons-22)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7302)
|
||
|
||
*Effects*: As if by reset()[.](#any.cons-22.sentence-1)
|
||
|
||
#### [22.7.4.3](#any.assign) Assignment [[any.assign]](any.assign)
|
||
|
||
[ð](#lib:operator=,any)
|
||
|
||
`any& operator=(const any& rhs);
|
||
`
|
||
|
||
[1](#any.assign-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7315)
|
||
|
||
*Effects*: As if by any(rhs).swap(*this)[.](#any.assign-1.sentence-1)
|
||
|
||
No effects if an exception is thrown[.](#any.assign-1.sentence-2)
|
||
|
||
[2](#any.assign-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7320)
|
||
|
||
*Returns*: *this[.](#any.assign-2.sentence-1)
|
||
|
||
[3](#any.assign-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7324)
|
||
|
||
*Throws*: Any exceptions arising from the copy constructor for the contained value[.](#any.assign-3.sentence-1)
|
||
|
||
[ð](#lib:operator=,any_)
|
||
|
||
`any& operator=(any&& rhs) noexcept;
|
||
`
|
||
|
||
[4](#any.assign-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7335)
|
||
|
||
*Effects*: As if by any(std::move(rhs)).swap(*this)[.](#any.assign-4.sentence-1)
|
||
|
||
[5](#any.assign-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[.](#any.assign-5.sentence-1)
|
||
|
||
[6](#any.assign-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7343)
|
||
|
||
*Returns*: *this[.](#any.assign-6.sentence-1)
|
||
|
||
[ð](#lib:operator=,any__)
|
||
|
||
`template<class T>
|
||
any& operator=(T&& rhs);
|
||
`
|
||
|
||
[7](#any.assign-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7355)
|
||
|
||
Let VT be decay_t<T>[.](#any.assign-7.sentence-1)
|
||
|
||
[8](#any.assign-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[.](#any.assign-8.sentence-1)
|
||
|
||
[9](#any.assign-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7363)
|
||
|
||
*Preconditions*: VT meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#any.assign-9.sentence-1)
|
||
|
||
[10](#any.assign-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)[.](#any.assign-10.sentence-1)
|
||
|
||
No effects if an exception is thrown[.](#any.assign-10.sentence-2)
|
||
|
||
[11](#any.assign-11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7372)
|
||
|
||
*Returns*: *this[.](#any.assign-11.sentence-1)
|
||
|
||
[12](#any.assign-12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7376)
|
||
|
||
*Throws*: Any exception thrown by the selected constructor of VT[.](#any.assign-12.sentence-1)
|
||
|
||
#### [22.7.4.4](#any.modifiers) Modifiers [[any.modifiers]](any.modifiers)
|
||
|
||
[ð](#lib:emplace,any)
|
||
|
||
`template<class T, class... Args>
|
||
decay_t<T>& emplace(Args&&... args);
|
||
`
|
||
|
||
[1](#any.modifiers-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7390)
|
||
|
||
Let VT be decay_t<T>[.](#any.modifiers-1.sentence-1)
|
||
|
||
[2](#any.modifiers-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7393)
|
||
|
||
*Constraints*: is_copy_constructible_v<VT> is true andis_constructible_v<VT, Args...> is true[.](#any.modifiers-2.sentence-1)
|
||
|
||
[3](#any.modifiers-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7398)
|
||
|
||
*Preconditions*: VT meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#any.modifiers-3.sentence-1)
|
||
|
||
[4](#any.modifiers-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7402)
|
||
|
||
*Effects*: Calls reset()[.](#any.modifiers-4.sentence-1)
|
||
|
||
Then direct-non-list-initializes the contained value of type VT with std::forward<Args>(args)...[.](#any.modifiers-4.sentence-2)
|
||
|
||
[5](#any.modifiers-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7408)
|
||
|
||
*Postconditions*: *this contains a value[.](#any.modifiers-5.sentence-1)
|
||
|
||
[6](#any.modifiers-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7412)
|
||
|
||
*Returns*: A reference to the new contained value[.](#any.modifiers-6.sentence-1)
|
||
|
||
[7](#any.modifiers-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7416)
|
||
|
||
*Throws*: Any exception thrown by the selected constructor of VT[.](#any.modifiers-7.sentence-1)
|
||
|
||
[8](#any.modifiers-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7420)
|
||
|
||
*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[.](#any.modifiers-8.sentence-1)
|
||
|
||
[ð](#lib:emplace,any_)
|
||
|
||
`template<class T, class U, class... Args>
|
||
decay_t<T>& emplace(initializer_list<U> il, Args&&... args);
|
||
`
|
||
|
||
[9](#any.modifiers-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7434)
|
||
|
||
Let VT be decay_t<T>[.](#any.modifiers-9.sentence-1)
|
||
|
||
[10](#any.modifiers-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7437)
|
||
|
||
*Constraints*: is_copy_constructible_v<VT> is true andis_constructible_v<VT, initializer_list<U>&, Args...> is true[.](#any.modifiers-10.sentence-1)
|
||
|
||
[11](#any.modifiers-11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7442)
|
||
|
||
*Preconditions*: VT meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#any.modifiers-11.sentence-1)
|
||
|
||
[12](#any.modifiers-12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7446)
|
||
|
||
*Effects*: Calls reset()[.](#any.modifiers-12.sentence-1)
|
||
|
||
Then direct-non-list-initializes the contained value
|
||
of type VT with il, std::forward<Args>(args)...[.](#any.modifiers-12.sentence-2)
|
||
|
||
[13](#any.modifiers-13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7451)
|
||
|
||
*Postconditions*: *this contains a value[.](#any.modifiers-13.sentence-1)
|
||
|
||
[14](#any.modifiers-14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7455)
|
||
|
||
*Returns*: A reference to the new contained value[.](#any.modifiers-14.sentence-1)
|
||
|
||
[15](#any.modifiers-15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7459)
|
||
|
||
*Throws*: Any exception thrown by the selected constructor of VT[.](#any.modifiers-15.sentence-1)
|
||
|
||
[16](#any.modifiers-16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7463)
|
||
|
||
*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[.](#any.modifiers-16.sentence-1)
|
||
|
||
[ð](#lib:reset,any)
|
||
|
||
`void reset() noexcept;
|
||
`
|
||
|
||
[17](#any.modifiers-17)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7476)
|
||
|
||
*Effects*: If has_value() is true, destroys the contained value[.](#any.modifiers-17.sentence-1)
|
||
|
||
[18](#any.modifiers-18)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7480)
|
||
|
||
*Postconditions*: has_value() is false[.](#any.modifiers-18.sentence-1)
|
||
|
||
[ð](#lib:swap,any)
|
||
|
||
`void swap(any& rhs) noexcept;
|
||
`
|
||
|
||
[19](#any.modifiers-19)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7492)
|
||
|
||
*Effects*: Exchanges the states of *this and rhs[.](#any.modifiers-19.sentence-1)
|
||
|
||
#### [22.7.4.5](#any.observers) Observers [[any.observers]](any.observers)
|
||
|
||
[ð](#lib:has_value,any)
|
||
|
||
`bool has_value() const noexcept;
|
||
`
|
||
|
||
[1](#any.observers-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7505)
|
||
|
||
*Returns*: true if *this contains an object, otherwise false[.](#any.observers-1.sentence-1)
|
||
|
||
[ð](#lib:type,any)
|
||
|
||
`const type_info& type() const noexcept;
|
||
`
|
||
|
||
[2](#any.observers-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7516)
|
||
|
||
*Returns*: typeid(T) if *this has a contained value of type T,
|
||
otherwise typeid(void)[.](#any.observers-2.sentence-1)
|
||
|
||
[3](#any.observers-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7521)
|
||
|
||
[*Note [1](#any.observers-note-1)*:
|
||
|
||
Useful for querying against types known either at compile time or only at runtime[.](#any.observers-3.sentence-1)
|
||
|
||
â *end note*]
|