From Jason Turner

[any.class]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpdbq6nvmb/{from.md → to.md} +56 -58
tmp/tmpdbq6nvmb/{from.md → to.md} RENAMED
@@ -1,17 +1,19 @@
1
  ### Class `any` <a id="any.class">[[any.class]]</a>
2
 
3
  ``` cpp
 
4
  class any {
5
  public:
6
  // [any.cons], construction and destruction
7
  constexpr any() noexcept;
8
 
9
  any(const any& other);
10
  any(any&& other) noexcept;
11
 
12
- template <class T> any(T&& value);
 
13
 
14
  template<class T, class... Args>
15
  explicit any(in_place_type_t<T>, Args&&...);
16
  template<class T, class U, class... Args>
17
  explicit any(in_place_type_t<T>, initializer_list<U>, Args&&...);
@@ -20,11 +22,12 @@ public:
20
 
21
  // [any.assign], assignments
22
  any& operator=(const any& rhs);
23
  any& operator=(any&& rhs) noexcept;
24
 
25
- template <class T> any& operator=(T&& rhs);
 
26
 
27
  // [any.modifiers], modifiers
28
  template<class T, class... Args>
29
  decay_t<T>& emplace(Args&&...);
30
  template<class T, class U, class... Args>
@@ -34,124 +37,119 @@ public:
34
 
35
  // [any.observers], observers
36
  bool has_value() const noexcept;
37
  const type_info& type() const noexcept;
38
  };
 
39
  ```
40
 
41
- An object of class `any` stores an instance of any type that satisfies
42
- the constructor requirements or it has no value, and this is referred to
43
- as the *state* of the class `any` object. The stored instance is called
44
- the *contained value*, Two states are equivalent if either they both
45
- have no value, or both have a value and the contained values are
46
  equivalent.
47
 
48
  The non-member `any_cast` functions provide type-safe access to the
49
  contained value.
50
 
51
  Implementations should avoid the use of dynamically allocated memory for
52
- a small contained value.
 
 
53
 
54
- [*Example 1*: where the object constructed is holding only an
55
- `int`. — *end example*]
56
-
57
- Such small-object optimization shall only be applied to types `T` for
58
- which `is_nothrow_move_constructible_v<T>` is `true`.
59
 
60
  #### Construction and destruction <a id="any.cons">[[any.cons]]</a>
61
 
62
  ``` cpp
63
  constexpr any() noexcept;
64
  ```
65
 
66
- *Postconditions:* `has_value()` is `false`.
67
 
68
  ``` cpp
69
  any(const any& other);
70
  ```
71
 
72
  *Effects:* If `other.has_value()` is `false`, constructs an object that
73
  has no value. Otherwise, equivalent to
74
- `any(in_place<T>, any_cast<const T&>(other))` where `T` is the type of
75
- the contained object.
76
 
77
  *Throws:* Any exceptions arising from calling the selected constructor
78
  for the contained value.
79
 
80
  ``` cpp
81
  any(any&& other) noexcept;
82
  ```
83
 
84
  *Effects:* If `other.has_value()` is `false`, constructs an object that
85
  has no value. Otherwise, constructs an object of type `any` that
86
- contains either the contained object of `other`, or contains an object
87
- of the same type constructed from the contained object of `other`
88
- considering that contained object as an rvalue.
89
-
90
- *Postconditions:* `other` is left in a valid but otherwise unspecified
91
- state.
92
 
93
  ``` cpp
94
  template<class T>
95
  any(T&& value);
96
  ```
97
 
98
  Let `VT` be `decay_t<T>`.
99
 
100
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
 
101
 
102
  *Effects:* Constructs an object of type `any` that contains an object of
103
  type `VT` direct-initialized with `std::forward<T>(value)`.
104
 
105
- *Remarks:* This constructor shall not participate in overload resolution
106
- unless `VT` is not the same type as `any`, `VT` is not a specialization
107
- of `in_place_type_t`, and `is_copy_constructible_v<VT>` is `true`.
108
-
109
  *Throws:* Any exception thrown by the selected constructor of `VT`.
110
 
111
  ``` cpp
112
  template<class T, class... Args>
113
  explicit any(in_place_type_t<T>, Args&&... args);
114
  ```
115
 
116
  Let `VT` be `decay_t<T>`.
117
 
118
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
119
 
120
  *Effects:* Initializes the contained value as if
121
  direct-non-list-initializing an object of type `VT` with the arguments
122
  `std::forward<Args>(args)...`.
123
 
124
- *Postconditions:* `*this` contains a value of type `VT`.
125
 
126
  *Throws:* Any exception thrown by the selected constructor of `VT`.
127
 
128
- *Remarks:* This constructor shall not participate in overload resolution
129
- unless `is_copy_constructible_v<VT>` is `true` and
130
- `is_constructible_v<VT, Args...>` is `true`.
131
-
132
  ``` cpp
133
  template<class T, class U, class... Args>
134
  explicit any(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
135
  ```
136
 
137
  Let `VT` be `decay_t<T>`.
138
 
139
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
140
 
141
  *Effects:* Initializes the contained value as if
142
  direct-non-list-initializing an object of type `VT` with the arguments
143
  `il, std::forward<Args>(args)...`.
144
 
145
- *Postconditions:* `*this` contains a value.
146
 
147
  *Throws:* Any exception thrown by the selected constructor of `VT`.
148
 
149
- *Remarks:* This constructor shall not participate in overload resolution
150
- unless `is_copy_constructible_v<VT>` is `true` and
151
- `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
152
-
153
  ``` cpp
154
  ~any();
155
  ```
156
 
157
  *Effects:* As if by `reset()`.
@@ -176,33 +174,31 @@ any& operator=(any&& rhs) noexcept;
176
 
177
  *Effects:* As if by `any(std::move(rhs)).swap(*this)`.
178
 
179
  *Returns:* `*this`.
180
 
181
- *Postconditions:* The state of `*this` is equivalent to the original
182
- state of `rhs` and `rhs` is left in a valid but otherwise unspecified
183
- state.
184
 
185
  ``` cpp
186
  template<class T>
187
  any& operator=(T&& rhs);
188
  ```
189
 
190
  Let `VT` be `decay_t<T>`.
191
 
192
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
193
 
194
  *Effects:* Constructs an object `tmp` of type `any` that contains an
195
  object of type `VT` direct-initialized with `std::forward<T>(rhs)`, and
196
  `tmp.swap(*this)`. No effects if an exception is thrown.
197
 
198
  *Returns:* `*this`.
199
 
200
- *Remarks:* This operator shall not participate in overload resolution
201
- unless `VT` is not the same type as `any` and
202
- `is_copy_constructible_v<VT>` is `true`.
203
-
204
  *Throws:* Any exception thrown by the selected constructor of `VT`.
205
 
206
  #### Modifiers <a id="any.modifiers">[[any.modifiers]]</a>
207
 
208
  ``` cpp
@@ -210,60 +206,62 @@ template <class T, class... Args>
210
  decay_t<T>& emplace(Args&&... args);
211
  ```
212
 
213
  Let `VT` be `decay_t<T>`.
214
 
215
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
216
 
217
  *Effects:* Calls `reset()`. Then initializes the contained value as if
218
  direct-non-list-initializing an object of type `VT` with the arguments
219
  `std::forward<Args>(args)...`.
220
 
221
- *Postconditions:* `*this` contains a value.
222
 
223
  *Returns:* A reference to the new contained value.
224
 
225
  *Throws:* Any exception thrown by the selected constructor of `VT`.
226
 
227
  *Remarks:* If an exception is thrown during the call to `VT`’s
228
  constructor, `*this` does not contain a value, and any previously
229
- contained value has been destroyed. This function shall not participate
230
- in overload resolution unless `is_copy_constructible_v<VT>` is `true`
231
- and `is_constructible_v<VT, Args...>` is `true`.
232
 
233
  ``` cpp
234
  template<class T, class U, class... Args>
235
  decay_t<T>& emplace(initializer_list<U> il, Args&&... args);
236
  ```
237
 
238
  Let `VT` be `decay_t<T>`.
239
 
240
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
241
 
242
  *Effects:* Calls `reset()`. Then initializes the contained value as if
243
  direct-non-list-initializing an object of type `VT` with the arguments
244
  `il, std::forward<Args>(args)...`.
245
 
246
- *Postconditions:* `*this` contains a value.
247
 
248
  *Returns:* A reference to the new contained value.
249
 
250
  *Throws:* Any exception thrown by the selected constructor of `VT`.
251
 
252
  *Remarks:* If an exception is thrown during the call to `VT`’s
253
  constructor, `*this` does not contain a value, and any previously
254
- contained value has been destroyed. The function shall not participate
255
- in overload resolution unless `is_copy_constructible_v<VT>` is `true`
256
- and `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
257
 
258
  ``` cpp
259
  void reset() noexcept;
260
  ```
261
 
262
  *Effects:* If `has_value()` is `true`, destroys the contained value.
263
 
264
- *Postconditions:* `has_value()` is `false`.
265
 
266
  ``` cpp
267
  void swap(any& rhs) noexcept;
268
  ```
269
 
 
1
  ### Class `any` <a id="any.class">[[any.class]]</a>
2
 
3
  ``` cpp
4
+ namespace std {
5
  class any {
6
  public:
7
  // [any.cons], construction and destruction
8
  constexpr any() noexcept;
9
 
10
  any(const any& other);
11
  any(any&& other) noexcept;
12
 
13
+ template<class T>
14
+ any(T&& value);
15
 
16
  template<class T, class... Args>
17
  explicit any(in_place_type_t<T>, Args&&...);
18
  template<class T, class U, class... Args>
19
  explicit any(in_place_type_t<T>, initializer_list<U>, Args&&...);
 
22
 
23
  // [any.assign], assignments
24
  any& operator=(const any& rhs);
25
  any& operator=(any&& rhs) noexcept;
26
 
27
+ template<class T>
28
+ any& operator=(T&& rhs);
29
 
30
  // [any.modifiers], modifiers
31
  template<class T, class... Args>
32
  decay_t<T>& emplace(Args&&...);
33
  template<class T, class U, class... Args>
 
37
 
38
  // [any.observers], observers
39
  bool has_value() const noexcept;
40
  const type_info& type() const noexcept;
41
  };
42
+ }
43
  ```
44
 
45
+ An object of class `any` stores an instance of any type that meets the
46
+ constructor requirements or it has no value, and this is referred to as
47
+ the *state* of the class `any` object. The stored instance is called the
48
+ *contained value*. Two states are equivalent if either they both have no
49
+ value, or they both have a value and the contained values are
50
  equivalent.
51
 
52
  The non-member `any_cast` functions provide type-safe access to the
53
  contained value.
54
 
55
  Implementations should avoid the use of dynamically allocated memory for
56
+ a small contained value. However, any such small-object optimization
57
+ shall only be applied to types `T` for which
58
+ `is_nothrow_move_constructible_v<T>` is `true`.
59
 
60
+ [*Example 1*: A contained value of type `int` could be stored in an
61
+ internal buffer, not in separately-allocated memory. — *end example*]
 
 
 
62
 
63
  #### Construction and destruction <a id="any.cons">[[any.cons]]</a>
64
 
65
  ``` cpp
66
  constexpr any() noexcept;
67
  ```
68
 
69
+ *Ensures:* `has_value()` is `false`.
70
 
71
  ``` cpp
72
  any(const any& other);
73
  ```
74
 
75
  *Effects:* If `other.has_value()` is `false`, constructs an object that
76
  has no value. Otherwise, equivalent to
77
+ `any(in_place_type<T>, any_cast<const T&>(other))` where `T` is the type
78
+ of the contained value.
79
 
80
  *Throws:* Any exceptions arising from calling the selected constructor
81
  for the contained value.
82
 
83
  ``` cpp
84
  any(any&& other) noexcept;
85
  ```
86
 
87
  *Effects:* If `other.has_value()` is `false`, constructs an object that
88
  has no value. Otherwise, constructs an object of type `any` that
89
+ contains either the contained value of `other`, or contains an object of
90
+ the same type constructed from the contained value of `other`
91
+ considering that contained value as an rvalue.
 
 
 
92
 
93
  ``` cpp
94
  template<class T>
95
  any(T&& value);
96
  ```
97
 
98
  Let `VT` be `decay_t<T>`.
99
 
100
+ *Constraints:* `VT` is not the same type as `any`, `VT` is not a
101
+ specialization of `in_place_type_t`, and `is_copy_constructible_v<VT>`
102
+ is `true`.
103
+
104
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
105
 
106
  *Effects:* Constructs an object of type `any` that contains an object of
107
  type `VT` direct-initialized with `std::forward<T>(value)`.
108
 
 
 
 
 
109
  *Throws:* Any exception thrown by the selected constructor of `VT`.
110
 
111
  ``` cpp
112
  template<class T, class... Args>
113
  explicit any(in_place_type_t<T>, Args&&... args);
114
  ```
115
 
116
  Let `VT` be `decay_t<T>`.
117
 
118
+ *Constraints:* `is_copy_constructible_v<VT>` is `true` and
119
+ `is_constructible_v<VT, Args...>` is `true`.
120
+
121
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
122
 
123
  *Effects:* Initializes the contained value as if
124
  direct-non-list-initializing an object of type `VT` with the arguments
125
  `std::forward<Args>(args)...`.
126
 
127
+ *Ensures:* `*this` contains a value of type `VT`.
128
 
129
  *Throws:* Any exception thrown by the selected constructor of `VT`.
130
 
 
 
 
 
131
  ``` cpp
132
  template<class T, class U, class... Args>
133
  explicit any(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
134
  ```
135
 
136
  Let `VT` be `decay_t<T>`.
137
 
138
+ *Constraints:* `is_copy_constructible_v<VT>` is `true` and
139
+ `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
140
+
141
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
142
 
143
  *Effects:* Initializes the contained value as if
144
  direct-non-list-initializing an object of type `VT` with the arguments
145
  `il, std::forward<Args>(args)...`.
146
 
147
+ *Ensures:* `*this` contains a value.
148
 
149
  *Throws:* Any exception thrown by the selected constructor of `VT`.
150
 
 
 
 
 
151
  ``` cpp
152
  ~any();
153
  ```
154
 
155
  *Effects:* As if by `reset()`.
 
174
 
175
  *Effects:* As if by `any(std::move(rhs)).swap(*this)`.
176
 
177
  *Returns:* `*this`.
178
 
179
+ *Ensures:* The state of `*this` is equivalent to the original state of
180
+ `rhs`.
 
181
 
182
  ``` cpp
183
  template<class T>
184
  any& operator=(T&& rhs);
185
  ```
186
 
187
  Let `VT` be `decay_t<T>`.
188
 
189
+ *Constraints:* `VT` is not the same type as `any` and
190
+ `is_copy_constructible_v<VT>` is `true`.
191
+
192
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
193
 
194
  *Effects:* Constructs an object `tmp` of type `any` that contains an
195
  object of type `VT` direct-initialized with `std::forward<T>(rhs)`, and
196
  `tmp.swap(*this)`. No effects if an exception is thrown.
197
 
198
  *Returns:* `*this`.
199
 
 
 
 
 
200
  *Throws:* Any exception thrown by the selected constructor of `VT`.
201
 
202
  #### Modifiers <a id="any.modifiers">[[any.modifiers]]</a>
203
 
204
  ``` cpp
 
206
  decay_t<T>& emplace(Args&&... args);
207
  ```
208
 
209
  Let `VT` be `decay_t<T>`.
210
 
211
+ *Constraints:* `is_copy_constructible_v<VT>` is `true` and
212
+ `is_constructible_v<VT, Args...>` is `true`.
213
+
214
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
215
 
216
  *Effects:* Calls `reset()`. Then initializes the contained value as if
217
  direct-non-list-initializing an object of type `VT` with the arguments
218
  `std::forward<Args>(args)...`.
219
 
220
+ *Ensures:* `*this` contains a value.
221
 
222
  *Returns:* A reference to the new contained value.
223
 
224
  *Throws:* Any exception thrown by the selected constructor of `VT`.
225
 
226
  *Remarks:* If an exception is thrown during the call to `VT`’s
227
  constructor, `*this` does not contain a value, and any previously
228
+ contained value has been destroyed.
 
 
229
 
230
  ``` cpp
231
  template<class T, class U, class... Args>
232
  decay_t<T>& emplace(initializer_list<U> il, Args&&... args);
233
  ```
234
 
235
  Let `VT` be `decay_t<T>`.
236
 
237
+ *Constraints:* `is_copy_constructible_v<VT>` is `true` and
238
+ `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
239
+
240
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
241
 
242
  *Effects:* Calls `reset()`. Then initializes the contained value as if
243
  direct-non-list-initializing an object of type `VT` with the arguments
244
  `il, std::forward<Args>(args)...`.
245
 
246
+ *Ensures:* `*this` contains a value.
247
 
248
  *Returns:* A reference to the new contained value.
249
 
250
  *Throws:* Any exception thrown by the selected constructor of `VT`.
251
 
252
  *Remarks:* If an exception is thrown during the call to `VT`’s
253
  constructor, `*this` does not contain a value, and any previously
254
+ contained value has been destroyed.
 
 
255
 
256
  ``` cpp
257
  void reset() noexcept;
258
  ```
259
 
260
  *Effects:* If `has_value()` is `true`, destroys the contained value.
261
 
262
+ *Ensures:* `has_value()` is `false`.
263
 
264
  ``` cpp
265
  void swap(any& rhs) noexcept;
266
  ```
267