Init
This commit is contained in:
101
cppdraft/any/assign.md
Normal file
101
cppdraft/any/assign.md
Normal file
@@ -0,0 +1,101 @@
|
||||
[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.2 Template 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)
|
||||
28
cppdraft/any/bad/any/cast.md
Normal file
28
cppdraft/any/bad/any/cast.md
Normal file
@@ -0,0 +1,28 @@
|
||||
[any.bad.any.cast]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.7 Storage for any type [[any]](any#bad.any.cast)
|
||||
|
||||
### 22.7.3 Class bad_any_cast [any.bad.any.cast]
|
||||
|
||||
[ð](#lib:bad_any_cast)
|
||||
|
||||
namespace std {class bad_any_cast : public bad_cast {public:// see [[exception]](exception "17.9.3 Class exception") for the specification of the special member functionsconst char* what() const noexcept override; };}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7077)
|
||||
|
||||
Objects of type bad_any_cast are thrown by a failed[any_cast](any.nonmembers#lib:any_cast "22.7.5 Non-member functions [any.nonmembers]")[.](#1.sentence-1)
|
||||
|
||||
[ð](#lib:what,bad_any_cast)
|
||||
|
||||
`const char* what() const noexcept override;
|
||||
`
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7087)
|
||||
|
||||
*Returns*: An implementation-defined ntbs[.](#2.sentence-1)
|
||||
501
cppdraft/any/class.md
Normal file
501
cppdraft/any/class.md
Normal file
@@ -0,0 +1,501 @@
|
||||
[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*]
|
||||
47
cppdraft/any/class/general.md
Normal file
47
cppdraft/any/class/general.md
Normal file
@@ -0,0 +1,47 @@
|
||||
[any.class.general]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.7 Storage for any type [[any]](any#class.general)
|
||||
|
||||
### 22.7.4 Class any [[any.class]](any.class#general)
|
||||
|
||||
#### 22.7.4.1 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](#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[.](#1.sentence-1)
|
||||
|
||||
The stored instance is called the [*contained value*](#def:contained_value,any "22.7.4.1 General [any.class.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[.](#1.sentence-3)
|
||||
|
||||
[2](#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[.](#2.sentence-1)
|
||||
|
||||
[3](#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[.](#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[.](#3.sentence-2)
|
||||
|
||||
[*Example [1](#example-1)*:
|
||||
|
||||
A contained value of type int could be stored in an internal buffer,
|
||||
not in separately-allocated memory[.](#3.sentence-3)
|
||||
|
||||
â *end example*]
|
||||
187
cppdraft/any/cons.md
Normal file
187
cppdraft/any/cons.md
Normal file
@@ -0,0 +1,187 @@
|
||||
[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)
|
||||
26
cppdraft/any/general.md
Normal file
26
cppdraft/any/general.md
Normal file
@@ -0,0 +1,26 @@
|
||||
[any.general]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.7 Storage for any type [[any]](any#general)
|
||||
|
||||
### 22.7.1 General [any.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7020)
|
||||
|
||||
Subclause [[any]](any "22.7 Storage for any type") describes components that C++ programs may use to perform operations on objects of a discriminated type[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7023)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The discriminated type can contain values of different types but does not attempt conversion between them,
|
||||
i.e., 5 is held strictly as an int and is not implicitly convertible either to "5" or to 5.0[.](#2.sentence-1)
|
||||
|
||||
This indifference to interpretation but awareness of type effectively allows safe, generic containers of single values, with no scope for surprises from ambiguous conversions[.](#2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
152
cppdraft/any/modifiers.md
Normal file
152
cppdraft/any/modifiers.md
Normal file
@@ -0,0 +1,152 @@
|
||||
[any.modifiers]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.7 Storage for any type [[any]](any#modifiers)
|
||||
|
||||
### 22.7.4 Class any [[any.class]](any.class#any.modifiers)
|
||||
|
||||
#### 22.7.4.4 Modifiers [any.modifiers]
|
||||
|
||||
[ð](#lib:emplace,any)
|
||||
|
||||
`template<class T, class... Args>
|
||||
decay_t<T>& emplace(Args&&... args);
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7390)
|
||||
|
||||
Let VT be decay_t<T>[.](#1.sentence-1)
|
||||
|
||||
[2](#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[.](#2.sentence-1)
|
||||
|
||||
[3](#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[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7402)
|
||||
|
||||
*Effects*: Calls reset()[.](#4.sentence-1)
|
||||
|
||||
Then direct-non-list-initializes the contained value of type VT with std::forward<Args>(args)...[.](#4.sentence-2)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7408)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7412)
|
||||
|
||||
*Returns*: A reference to the new contained value[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7416)
|
||||
|
||||
*Throws*: Any exception thrown by the selected constructor of VT[.](#7.sentence-1)
|
||||
|
||||
[8](#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[.](#8.sentence-1)
|
||||
|
||||
[ð](#lib:emplace,any_)
|
||||
|
||||
`template<class T, class U, class... Args>
|
||||
decay_t<T>& emplace(initializer_list<U> il, Args&&... args);
|
||||
`
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7434)
|
||||
|
||||
Let VT be decay_t<T>[.](#9.sentence-1)
|
||||
|
||||
[10](#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[.](#10.sentence-1)
|
||||
|
||||
[11](#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[.](#11.sentence-1)
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7446)
|
||||
|
||||
*Effects*: Calls reset()[.](#12.sentence-1)
|
||||
|
||||
Then direct-non-list-initializes the contained value
|
||||
of type VT with il, std::forward<Args>(args)...[.](#12.sentence-2)
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7451)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#13.sentence-1)
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7455)
|
||||
|
||||
*Returns*: A reference to the new contained value[.](#14.sentence-1)
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7459)
|
||||
|
||||
*Throws*: Any exception thrown by the selected constructor of VT[.](#15.sentence-1)
|
||||
|
||||
[16](#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[.](#16.sentence-1)
|
||||
|
||||
[ð](#lib:reset,any)
|
||||
|
||||
`void reset() noexcept;
|
||||
`
|
||||
|
||||
[17](#17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7476)
|
||||
|
||||
*Effects*: If has_value() is true, destroys the contained value[.](#17.sentence-1)
|
||||
|
||||
[18](#18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7480)
|
||||
|
||||
*Postconditions*: has_value() is false[.](#18.sentence-1)
|
||||
|
||||
[ð](#lib:swap,any)
|
||||
|
||||
`void swap(any& rhs) noexcept;
|
||||
`
|
||||
|
||||
[19](#19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7492)
|
||||
|
||||
*Effects*: Exchanges the states of *this and rhs[.](#19.sentence-1)
|
||||
128
cppdraft/any/nonmembers.md
Normal file
128
cppdraft/any/nonmembers.md
Normal file
@@ -0,0 +1,128 @@
|
||||
[any.nonmembers]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.7 Storage for any type [[any]](any#nonmembers)
|
||||
|
||||
### 22.7.5 Non-member functions [any.nonmembers]
|
||||
|
||||
[ð](#lib:swap,any)
|
||||
|
||||
`void swap(any& x, any& y) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7535)
|
||||
|
||||
*Effects*: Equivalent to x.swap(y)[.](#1.sentence-1)
|
||||
|
||||
[ð](#lib:make_any)
|
||||
|
||||
`template<class T, class... Args>
|
||||
any make_any(Args&&... args);
|
||||
`
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7547)
|
||||
|
||||
*Effects*: Equivalent to: return any(in_place_type<T>, std::forward<Args>(args)...);
|
||||
|
||||
[ð](#lib:make_any_)
|
||||
|
||||
`template<class T, class U, class... Args>
|
||||
any make_any(initializer_list<U> il, Args&&... args);
|
||||
`
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7559)
|
||||
|
||||
*Effects*: Equivalent to: return any(in_place_type<T>, il, std::forward<Args>(args)...);
|
||||
|
||||
[ð](#lib:any_cast)
|
||||
|
||||
`template<class T>
|
||||
T any_cast(const any& operand);
|
||||
template<class T>
|
||||
T any_cast(any& operand);
|
||||
template<class T>
|
||||
T any_cast(any&& operand);
|
||||
`
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7575)
|
||||
|
||||
Let U be the type remove_cvref_t<T>[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7578)
|
||||
|
||||
*Mandates*: For the first overload, is_constructible_v<T, const U&> is true[.](#5.sentence-1)
|
||||
|
||||
For the second overload, is_constructible_v<T, U&> is true[.](#5.sentence-2)
|
||||
|
||||
For the third overload, is_constructible_v<T, U> is true[.](#5.sentence-3)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7584)
|
||||
|
||||
*Returns*: For the first and second overload, static_cast<T>(*any_cast<U>(&operand))[.](#6.sentence-1)
|
||||
|
||||
For the third overload, static_cast<T>(std::move(*any_cast<U>(&operand)))[.](#6.sentence-2)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7589)
|
||||
|
||||
*Throws*: bad_any_cast if operand.type() != typeid(remove_reference_t<T>)[.](#7.sentence-1)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7593)
|
||||
|
||||
[*Example [1](#example-1)*: any x(5); // x holds int assert(any_cast<int>(x) == 5); // cast to value any_cast<int&>(x) = 10; // cast to reference assert(any_cast<int>(x) == 10);
|
||||
|
||||
x = "Meow"; // x holds const char* assert(strcmp(any_cast<const char*>(x), "Meow") == 0);
|
||||
any_cast<const char*&>(x) = "Harry";
|
||||
assert(strcmp(any_cast<const char*>(x), "Harry") == 0);
|
||||
|
||||
x = string("Meow"); // x holds string string s, s2("Jane");
|
||||
s = move(any_cast<string&>(x)); // move from any assert(s == "Meow");
|
||||
any_cast<string&>(x) = move(s2); // move to any assert(any_cast<const string&>(x) == "Jane");
|
||||
|
||||
string cat("Meow");const any y(cat); // const y holds string assert(any_cast<const string&>(y) == cat);
|
||||
|
||||
any_cast<string&>(y); // error: cannot any_cast away const â *end example*]
|
||||
|
||||
[ð](#lib:any_cast_)
|
||||
|
||||
`template<class T>
|
||||
const T* any_cast(const any* operand) noexcept;
|
||||
template<class T>
|
||||
T* any_cast(any* operand) noexcept;
|
||||
`
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7631)
|
||||
|
||||
*Mandates*: is_void_v<T> is false[.](#9.sentence-1)
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7635)
|
||||
|
||||
*Returns*: If operand != nullptr && operand->type() == typeid(T) is true,
|
||||
a pointer to the object contained by operand;
|
||||
otherwise, nullptr[.](#10.sentence-1)
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7641)
|
||||
|
||||
[*Example [2](#example-2)*: bool is_string(const any& operand) {return any_cast<string>(&operand) != nullptr;} â *end example*]
|
||||
42
cppdraft/any/observers.md
Normal file
42
cppdraft/any/observers.md
Normal file
@@ -0,0 +1,42 @@
|
||||
[any.observers]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.7 Storage for any type [[any]](any#observers)
|
||||
|
||||
### 22.7.4 Class any [[any.class]](any.class#any.observers)
|
||||
|
||||
#### 22.7.4.5 Observers [any.observers]
|
||||
|
||||
[ð](#lib:has_value,any)
|
||||
|
||||
`bool has_value() const noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7505)
|
||||
|
||||
*Returns*: true if *this contains an object, otherwise false[.](#1.sentence-1)
|
||||
|
||||
[ð](#lib:type,any)
|
||||
|
||||
`const type_info& type() const noexcept;
|
||||
`
|
||||
|
||||
[2](#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)[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7521)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Useful for querying against types known either at compile time or only at runtime[.](#3.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
9
cppdraft/any/synop.md
Normal file
9
cppdraft/any/synop.md
Normal file
@@ -0,0 +1,9 @@
|
||||
[any.synop]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.7 Storage for any type [[any]](any#synop)
|
||||
|
||||
### 22.7.2 Header <any> synopsis [any.synop]
|
||||
|
||||
namespace std {// [[any.bad.any.cast]](any.bad.any.cast "22.7.3 Class bad_any_cast"), class bad_any_castclass bad_any_cast; // [[any.class]](any.class "22.7.4 Class any"), class anyclass any; // [[any.nonmembers]](any.nonmembers "22.7.5 Non-member functions"), non-member functionsvoid swap(any& x, any& y) noexcept; template<class T, class... Args> any make_any(Args&&... args); template<class T, class U, class... Args> any make_any(initializer_list<U> il, Args&&... args); template<class T> T any_cast(const any& operand); template<class T> T any_cast(any& operand); template<class T> T any_cast(any&& operand); template<class T>const T* any_cast(const any* operand) noexcept; template<class T> T* any_cast(any* operand) noexcept;}
|
||||
Reference in New Issue
Block a user