- tmp/tmpa5tw6je_/{from.md → to.md} +8190 -2887
tmp/tmpa5tw6je_/{from.md → to.md}
RENAMED
|
@@ -10,77 +10,102 @@ C++standard library. These utilities are summarized in Table
|
|
| 10 |
**Table: General utilities library summary** <a id="tab:util.lib.summary">[tab:util.lib.summary]</a>
|
| 11 |
|
| 12 |
| Subclause | | Header |
|
| 13 |
| --------------------- | -------------------------------- | -------------------- |
|
| 14 |
| [[utility]] | Utility components | `<utility>` |
|
|
|
|
| 15 |
| [[pairs]] | Pairs | `<utility>` |
|
| 16 |
| [[tuple]] | Tuples | `<tuple>` |
|
| 17 |
-
| [[
|
| 18 |
-
| [[
|
| 19 |
-
|
|
| 20 |
-
| [[
|
| 21 |
-
|
|
|
|
|
| 22 |
| [[smartptr]] | Smart pointers | `<memory>` |
|
|
|
|
|
|
|
| 23 |
| [[function.objects]] | Function objects | `<functional>` |
|
| 24 |
| [[meta]] | Type traits | `<type_traits>` |
|
| 25 |
| [[ratio]] | Compile-time rational arithmetic | `<ratio>` |
|
| 26 |
| [[time]] | Time utilities | `<chrono>` |
|
| 27 |
| | | `<ctime>` |
|
| 28 |
-
| [[allocator.adaptor]] | Scoped allocators | `<scoped_allocator>` |
|
| 29 |
| [[type.index]] | Type indexes | `<typeindex>` |
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
## Utility components <a id="utility">[[utility]]</a>
|
| 33 |
|
| 34 |
This subclause contains some basic function and class templates that are
|
| 35 |
used throughout the rest of the library.
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
The header `<utility>` defines several types and function templates that
|
| 40 |
-
are described in this Clause. It also defines the template `pair` and
|
| 41 |
-
various function templates that operate on `pair` objects.
|
| 42 |
|
| 43 |
``` cpp
|
| 44 |
-
#include <initializer_list>
|
| 45 |
|
| 46 |
namespace std {
|
| 47 |
-
// [operators], operators
|
| 48 |
namespace rel_ops {
|
| 49 |
template<class T> bool operator!=(const T&, const T&);
|
| 50 |
template<class T> bool operator> (const T&, const T&);
|
| 51 |
template<class T> bool operator<=(const T&, const T&);
|
| 52 |
template<class T> bool operator>=(const T&, const T&);
|
| 53 |
}
|
| 54 |
|
| 55 |
-
// [utility.swap], swap
|
| 56 |
-
template<class T>
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
// [utility.exchange], exchange
|
| 60 |
-
template <class T, class U=
|
|
|
|
| 61 |
|
| 62 |
-
// [forward], forward/move
|
| 63 |
template <class T>
|
| 64 |
constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 65 |
template <class T>
|
| 66 |
constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
|
| 67 |
template <class T>
|
| 68 |
constexpr remove_reference_t<T>&& move(T&&) noexcept;
|
| 69 |
template <class T>
|
| 70 |
constexpr conditional_t<
|
| 71 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
-
// [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
template <class T>
|
| 76 |
add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
|
|
|
| 77 |
|
| 78 |
-
// [
|
| 79 |
-
template
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
template <class T1, class T2>
|
| 83 |
constexpr bool operator==(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 84 |
template <class T1, class T2>
|
| 85 |
constexpr bool operator< (const pair<T1, T2>&, const pair<T1, T2>&);
|
| 86 |
template <class T1, class T2>
|
|
@@ -89,66 +114,137 @@ namespace std {
|
|
| 89 |
constexpr bool operator> (const pair<T1, T2>&, const pair<T1, T2>&);
|
| 90 |
template <class T1, class T2>
|
| 91 |
constexpr bool operator>=(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 92 |
template <class T1, class T2>
|
| 93 |
constexpr bool operator<=(const pair<T1, T2>&, const pair<T1, T2>&);
|
|
|
|
| 94 |
template <class T1, class T2>
|
| 95 |
void swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
|
|
|
|
| 96 |
template <class T1, class T2>
|
| 97 |
constexpr see below make_pair(T1&&, T2&&);
|
| 98 |
|
| 99 |
-
// [pair.astuple], tuple-like access to pair
|
| 100 |
template <class T> class tuple_size;
|
| 101 |
template <size_t I, class T> class tuple_element;
|
| 102 |
|
| 103 |
template <class T1, class T2> struct tuple_size<pair<T1, T2>>;
|
| 104 |
template <class T1, class T2> struct tuple_element<0, pair<T1, T2>>;
|
| 105 |
template <class T1, class T2> struct tuple_element<1, pair<T1, T2>>;
|
| 106 |
|
| 107 |
template<size_t I, class T1, class T2>
|
| 108 |
-
constexpr tuple_element_t<I, pair<T1, T2>>&
|
| 109 |
-
get(pair<T1, T2>&) noexcept;
|
| 110 |
template<size_t I, class T1, class T2>
|
| 111 |
-
constexpr tuple_element_t<I, pair<T1, T2>>&&
|
| 112 |
-
get(pair<T1, T2>&&) noexcept;
|
| 113 |
template<size_t I, class T1, class T2>
|
| 114 |
-
constexpr const tuple_element_t<I, pair<T1, T2>>&
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
// [pair.piecewise], pair piecewise construction
|
| 130 |
-
struct piecewise_construct_t {
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
|
| 141 |
-
using make_integer_sequence = integer_sequence<T, see below>;
|
| 142 |
-
template<size_t N>
|
| 143 |
-
using make_index_sequence = make_integer_sequence<size_t, N>;
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
}
|
| 148 |
```
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
### Operators <a id="operators">[[operators]]</a>
|
| 151 |
|
| 152 |
To avoid redundant definitions of `operator!=` out of `operator==` and
|
| 153 |
operators `>`, `<=`, and `>=` out of `operator<`, the library provides
|
| 154 |
the following:
|
|
@@ -156,76 +252,82 @@ the following:
|
|
| 156 |
``` cpp
|
| 157 |
template <class T> bool operator!=(const T& x, const T& y);
|
| 158 |
```
|
| 159 |
|
| 160 |
*Requires:* Type `T` is `EqualityComparable`
|
| 161 |
-
(Table [[equalitycomparable]]).
|
| 162 |
|
| 163 |
*Returns:* `!(x == y)`.
|
| 164 |
|
| 165 |
``` cpp
|
| 166 |
template <class T> bool operator>(const T& x, const T& y);
|
| 167 |
```
|
| 168 |
|
| 169 |
*Requires:* Type `T` is `LessThanComparable`
|
| 170 |
-
(Table [[lessthancomparable]]).
|
| 171 |
|
| 172 |
*Returns:* `y < x`.
|
| 173 |
|
| 174 |
``` cpp
|
| 175 |
template <class T> bool operator<=(const T& x, const T& y);
|
| 176 |
```
|
| 177 |
|
| 178 |
*Requires:* Type `T` is `LessThanComparable`
|
| 179 |
-
(Table [[lessthancomparable]]).
|
| 180 |
|
| 181 |
*Returns:* `!(y < x)`.
|
| 182 |
|
| 183 |
``` cpp
|
| 184 |
template <class T> bool operator>=(const T& x, const T& y);
|
| 185 |
```
|
| 186 |
|
| 187 |
*Requires:* Type `T` is `LessThanComparable`
|
| 188 |
-
(Table [[lessthancomparable]]).
|
| 189 |
|
| 190 |
*Returns:* `!(x < y)`.
|
| 191 |
|
| 192 |
In this library, whenever a declaration is provided for an `operator!=`,
|
| 193 |
`operator>`, `operator>=`, or `operator<=`, and requirements and
|
| 194 |
semantics are not explicitly provided, the requirements and semantics
|
| 195 |
are as specified in this Clause.
|
| 196 |
|
| 197 |
-
### swap <a id="utility.swap">[[utility.swap]]</a>
|
| 198 |
|
| 199 |
``` cpp
|
| 200 |
-
template<class T>
|
|
|
|
| 201 |
```
|
| 202 |
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
``` cpp
|
| 206 |
-
|
| 207 |
-
is_nothrow_move_assignable<T>::value
|
| 208 |
```
|
| 209 |
|
| 210 |
*Requires:* Type `T` shall be `MoveConstructible`
|
| 211 |
-
(Table [[moveconstructible]]) and `MoveAssignable`
|
| 212 |
-
(Table [[moveassignable]]).
|
| 213 |
|
| 214 |
*Effects:* Exchanges values stored in two locations.
|
| 215 |
|
| 216 |
``` cpp
|
| 217 |
template <class T, size_t N>
|
| 218 |
-
void swap(T (&a)[N], T (&b)[N]) noexcept(
|
| 219 |
```
|
| 220 |
|
|
|
|
|
|
|
|
|
|
| 221 |
*Requires:* `a[i]` shall be swappable with ([[swappable.requirements]])
|
| 222 |
`b[i]` for all `i` in the range \[`0`, `N`).
|
| 223 |
|
| 224 |
-
*Effects:* `swap_ranges(a, a + N, b)`
|
| 225 |
|
| 226 |
-
### exchange <a id="utility.exchange">[[utility.exchange]]</a>
|
| 227 |
|
| 228 |
``` cpp
|
| 229 |
template <class T, class U = T> T exchange(T& obj, U&& new_val);
|
| 230 |
```
|
| 231 |
|
|
@@ -235,25 +337,28 @@ template <class T, class U=T> T exchange(T& obj, U&& new_val);
|
|
| 235 |
T old_val = std::move(obj);
|
| 236 |
obj = std::forward<U>(new_val);
|
| 237 |
return old_val;
|
| 238 |
```
|
| 239 |
|
| 240 |
-
###
|
| 241 |
|
| 242 |
The library provides templated helper functions to simplify applying
|
| 243 |
move semantics to an lvalue and to simplify the implementation of
|
| 244 |
-
forwarding functions.
|
|
|
|
| 245 |
|
| 246 |
``` cpp
|
| 247 |
template <class T> constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 248 |
template <class T> constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
|
| 249 |
```
|
| 250 |
|
| 251 |
*Returns:* `static_cast<T&&>(t)`.
|
| 252 |
|
| 253 |
-
If the second form is instantiated with an lvalue reference
|
| 254 |
-
program is ill-formed.
|
|
|
|
|
|
|
| 255 |
|
| 256 |
``` cpp
|
| 257 |
template <class T, class A1, class A2>
|
| 258 |
shared_ptr<T> factory(A1&& a1, A2&& a2) {
|
| 259 |
return shared_ptr<T>(new T(std::forward<A1>(a1), std::forward<A2>(a2)));
|
|
@@ -274,16 +379,20 @@ In the first call to `factory`, `A1` is deduced as `int`, so 2 is
|
|
| 274 |
forwarded to `A`’s constructor as an rvalue. In the second call to
|
| 275 |
`factory`, `A1` is deduced as `int&`, so `i` is forwarded to `A`’s
|
| 276 |
constructor as an lvalue. In both cases, `A2` is deduced as `double`, so
|
| 277 |
1.414 is forwarded to `A`’s constructor as an rvalue.
|
| 278 |
|
|
|
|
|
|
|
| 279 |
``` cpp
|
| 280 |
template <class T> constexpr remove_reference_t<T>&& move(T&& t) noexcept;
|
| 281 |
```
|
| 282 |
|
| 283 |
*Returns:* `static_cast<remove_reference_t<T>&&>(t)`.
|
| 284 |
|
|
|
|
|
|
|
| 285 |
``` cpp
|
| 286 |
template <class T, class A1>
|
| 287 |
shared_ptr<T> factory(A1&& a1) {
|
| 288 |
return shared_ptr<T>(new T(std::forward<A1>(a1)));
|
| 289 |
}
|
|
@@ -306,44 +415,256 @@ forwarded as a non-const lvalue. This binds to the constructor
|
|
| 306 |
`A(const A&)`, which copies the value from `a`. In the second call to
|
| 307 |
`factory`, because of the call `std::move(a)`, `A1` is deduced as `A`,
|
| 308 |
so `a` is forwarded as an rvalue. This binds to the constructor
|
| 309 |
`A(A&&)`, which moves the value from `a`.
|
| 310 |
|
|
|
|
|
|
|
| 311 |
``` cpp
|
| 312 |
template <class T> constexpr conditional_t<
|
| 313 |
-
|
| 314 |
-
|
| 315 |
```
|
| 316 |
|
| 317 |
-
*Returns:* `std::move(x)`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
|
| 319 |
### Function template `declval` <a id="declval">[[declval]]</a>
|
| 320 |
|
| 321 |
The library provides the function template `declval` to simplify the
|
| 322 |
definition of expressions which occur as unevaluated operands (Clause
|
| 323 |
[[expr]]).
|
| 324 |
|
| 325 |
``` cpp
|
| 326 |
-
template <class T>
|
| 327 |
-
add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
| 328 |
```
|
| 329 |
|
| 330 |
*Remarks:* If this function is odr-used ([[basic.def.odr]]), the
|
| 331 |
program is ill-formed.
|
| 332 |
|
| 333 |
*Remarks:* The template parameter `T` of `declval` may be an incomplete
|
| 334 |
type.
|
| 335 |
|
|
|
|
|
|
|
| 336 |
``` cpp
|
| 337 |
-
template <class To, class From>
|
| 338 |
-
decltype(static_cast<To>(declval<From>())) convert(From&&);
|
| 339 |
```
|
| 340 |
|
| 341 |
declares a function template `convert` which only participates in
|
| 342 |
overloading if the type `From` can be explicitly converted to type `To`.
|
| 343 |
-
For another example see class template
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
## Pairs <a id="pairs">[[pairs]]</a>
|
| 347 |
|
| 348 |
### In general <a id="pairs.general">[[pairs.general]]</a>
|
| 349 |
|
|
@@ -354,203 +675,217 @@ as if they were `tuple` objects (see [[tuple.helper]] and
|
|
| 354 |
[[tuple.elem]]).
|
| 355 |
|
| 356 |
### Class template `pair` <a id="pairs.pair">[[pairs.pair]]</a>
|
| 357 |
|
| 358 |
``` cpp
|
| 359 |
-
// defined in header <utility>
|
| 360 |
-
|
| 361 |
namespace std {
|
| 362 |
template <class T1, class T2>
|
| 363 |
struct pair {
|
| 364 |
-
|
| 365 |
-
|
| 366 |
|
| 367 |
T1 first;
|
| 368 |
T2 second;
|
|
|
|
| 369 |
pair(const pair&) = default;
|
| 370 |
pair(pair&&) = default;
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
template <class... Args1, class... Args2>
|
| 377 |
-
|
| 378 |
-
tuple<Args1...> first_args, tuple<Args2...> second_args);
|
| 379 |
|
| 380 |
pair& operator=(const pair& p);
|
| 381 |
-
|
| 382 |
pair& operator=(pair&& p) noexcept(see below);
|
| 383 |
-
|
| 384 |
|
| 385 |
void swap(pair& p) noexcept(see below);
|
| 386 |
};
|
|
|
|
|
|
|
|
|
|
| 387 |
}
|
| 388 |
```
|
| 389 |
|
| 390 |
Constructors and member functions of `pair` shall not throw exceptions
|
| 391 |
unless one of the element-wise operations specified to be called for
|
| 392 |
that operation throws an exception.
|
| 393 |
|
| 394 |
-
The defaulted move and copy constructor, respectively, of pair shall
|
| 395 |
-
a
|
| 396 |
initializations for copy and move, respectively, would satisfy the
|
| 397 |
-
requirements for a
|
|
|
|
|
|
|
|
|
|
| 398 |
|
| 399 |
``` cpp
|
| 400 |
-
constexpr pair();
|
| 401 |
```
|
| 402 |
|
| 403 |
-
*Requires:* `is_default_constructible<first_type>::value` is `true` and
|
| 404 |
-
`is_default_construct-`
|
| 405 |
-
`ible<second_type>::value` is `true`.
|
| 406 |
-
|
| 407 |
*Effects:* Value-initializes `first` and `second`.
|
| 408 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
``` cpp
|
| 410 |
-
constexpr pair(const T1& x, const T2& y);
|
| 411 |
```
|
| 412 |
|
| 413 |
-
*
|
| 414 |
-
`is_copy_constructible<second_type>::value` is `true`.
|
| 415 |
|
| 416 |
-
*
|
| 417 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
|
| 419 |
``` cpp
|
| 420 |
-
template<class
|
| 421 |
```
|
| 422 |
|
| 423 |
-
*
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
*Effects:* The constructor initializes `first` with `std::forward<U>(x)`
|
| 427 |
-
and `second` with `std::forward<V>(y)`.
|
| 428 |
|
| 429 |
-
*Remarks:*
|
| 430 |
-
|
| 431 |
-
|
|
|
|
|
|
|
| 432 |
|
| 433 |
``` cpp
|
| 434 |
-
template<class
|
| 435 |
```
|
| 436 |
|
| 437 |
-
*Requires:* `is_constructible<first_type, const U&>::value` is `true`
|
| 438 |
-
and `is_constructible<second_type, const V&>::value` is `true`.
|
| 439 |
-
|
| 440 |
*Effects:* Initializes members from the corresponding members of the
|
| 441 |
argument.
|
| 442 |
|
| 443 |
-
This constructor shall not participate in overload resolution
|
| 444 |
-
`const
|
| 445 |
-
|
|
|
|
|
|
|
| 446 |
|
| 447 |
``` cpp
|
| 448 |
-
template<class
|
| 449 |
```
|
| 450 |
|
| 451 |
-
*
|
| 452 |
-
`
|
| 453 |
|
| 454 |
-
*
|
| 455 |
-
`
|
| 456 |
-
`
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
is implicitly convertible to `first_type` and `V` is implicitly
|
| 460 |
-
convertible to `second_type`.
|
| 461 |
|
| 462 |
``` cpp
|
| 463 |
template<class... Args1, class... Args2>
|
| 464 |
-
pair(piecewise_construct_t,
|
| 465 |
-
tuple<Args1...> first_args, tuple<Args2...> second_args);
|
| 466 |
```
|
| 467 |
|
| 468 |
-
*Requires:* `
|
| 469 |
-
|
| 470 |
|
| 471 |
-
*Effects:*
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
|
| 480 |
``` cpp
|
| 481 |
pair& operator=(const pair& p);
|
| 482 |
```
|
| 483 |
|
| 484 |
-
*Requires:* `is_copy_assignable<first_type>::value` is `true` and
|
| 485 |
-
`is_copy_assignable<second_type>::value` is `true`.
|
| 486 |
-
|
| 487 |
*Effects:* Assigns `p.first` to `first` and `p.second` to `second`.
|
| 488 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
*Returns:* `*this`.
|
| 490 |
|
| 491 |
``` cpp
|
| 492 |
-
template<class
|
| 493 |
```
|
| 494 |
|
| 495 |
-
*Requires:* `is_assignable<first_type&, const U&>::value` is `true` and
|
| 496 |
-
`is_assignable<second_type&, const V&>::value` is `true`.
|
| 497 |
-
|
| 498 |
*Effects:* Assigns `p.first` to `first` and `p.second` to `second`.
|
| 499 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
*Returns:* `*this`.
|
| 501 |
|
| 502 |
``` cpp
|
| 503 |
pair& operator=(pair&& p) noexcept(see below);
|
| 504 |
```
|
| 505 |
|
| 506 |
-
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 507 |
-
|
| 508 |
-
``` cpp
|
| 509 |
-
is_nothrow_move_assignable<T1>::value &&
|
| 510 |
-
is_nothrow_move_assignable<T2>::value
|
| 511 |
-
```
|
| 512 |
-
|
| 513 |
-
*Requires:* `is_move_assignable<first_type>::value` is `true` and
|
| 514 |
-
`is_move_assignable<second_type>::value` is `true`.
|
| 515 |
-
|
| 516 |
*Effects:* Assigns to `first` with `std::forward<first_type>(p.first)`
|
| 517 |
and to `second` with
|
| 518 |
`std::forward<second_type>(p.second)`.
|
| 519 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 520 |
*Returns:* `*this`.
|
| 521 |
|
| 522 |
``` cpp
|
| 523 |
-
template<class
|
| 524 |
```
|
| 525 |
|
| 526 |
-
*Requires:* `is_assignable<first_type&, U&&>::value` is `true` and
|
| 527 |
-
`is_assignable<second_type&, V&&>::value` is `true`.
|
| 528 |
-
|
| 529 |
*Effects:* Assigns to `first` with `std::forward<U>(p.first)` and to
|
| 530 |
`second` with
|
| 531 |
`std::forward<V>(p.second)`.
|
| 532 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
*Returns:* `*this`.
|
| 534 |
|
| 535 |
``` cpp
|
| 536 |
void swap(pair& p) noexcept(see below);
|
| 537 |
```
|
| 538 |
|
| 539 |
-
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 540 |
-
|
| 541 |
-
``` cpp
|
| 542 |
-
noexcept(swap(first, p.first)) &&
|
| 543 |
-
noexcept(swap(second, p.second))
|
| 544 |
-
```
|
| 545 |
-
|
| 546 |
*Requires:* `first` shall be swappable
|
| 547 |
with ([[swappable.requirements]]) `p.first` and `second` shall be
|
| 548 |
swappable with `p.second`.
|
| 549 |
|
| 550 |
*Effects:* Swaps `first` with `p.first` and `second` with `p.second`.
|
| 551 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
### Specialized algorithms <a id="pairs.spec">[[pairs.spec]]</a>
|
| 553 |
|
| 554 |
``` cpp
|
| 555 |
template <class T1, class T2>
|
| 556 |
constexpr bool operator==(const pair<T1, T2>& x, const pair<T1, T2>& y);
|
|
@@ -569,50 +904,55 @@ template <class T1, class T2>
|
|
| 569 |
``` cpp
|
| 570 |
template <class T1, class T2>
|
| 571 |
constexpr bool operator!=(const pair<T1, T2>& x, const pair<T1, T2>& y);
|
| 572 |
```
|
| 573 |
|
| 574 |
-
*Returns:* `!(x == y)`
|
| 575 |
|
| 576 |
``` cpp
|
| 577 |
template <class T1, class T2>
|
| 578 |
constexpr bool operator>(const pair<T1, T2>& x, const pair<T1, T2>& y);
|
| 579 |
```
|
| 580 |
|
| 581 |
-
*Returns:* `y < x`
|
| 582 |
|
| 583 |
``` cpp
|
| 584 |
template <class T1, class T2>
|
| 585 |
constexpr bool operator>=(const pair<T1, T2>& x, const pair<T1, T2>& y);
|
| 586 |
```
|
| 587 |
|
| 588 |
-
*Returns:* `!(x < y)`
|
| 589 |
|
| 590 |
``` cpp
|
| 591 |
template <class T1, class T2>
|
| 592 |
constexpr bool operator<=(const pair<T1, T2>& x, const pair<T1, T2>& y);
|
| 593 |
```
|
| 594 |
|
| 595 |
-
*Returns:* `!(y < x)`
|
| 596 |
|
| 597 |
``` cpp
|
| 598 |
template<class T1, class T2> void swap(pair<T1, T2>& x, pair<T1, T2>& y)
|
| 599 |
noexcept(noexcept(x.swap(y)));
|
| 600 |
```
|
| 601 |
|
| 602 |
-
*Effects:* `x.swap(y)`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
|
| 604 |
``` cpp
|
| 605 |
template <class T1, class T2>
|
| 606 |
constexpr pair<V1, V2> make_pair(T1&& x, T2&& y);
|
| 607 |
```
|
| 608 |
|
| 609 |
-
*Returns:* `pair<V1, V2>(std::forward<T1>(x), std::forward<T2>(y))`
|
| 610 |
-
|
| 611 |
where `V1` and `V2` are determined as follows: Let `Ui` be `decay_t<Ti>`
|
| 612 |
-
for each `Ti`.
|
| 613 |
-
`
|
|
|
|
|
|
|
| 614 |
|
| 615 |
In place of:
|
| 616 |
|
| 617 |
``` cpp
|
| 618 |
return pair<int, double>(5, 3.1415926); // explicit types
|
|
@@ -622,101 +962,84 @@ a C++program may contain:
|
|
| 622 |
|
| 623 |
``` cpp
|
| 624 |
return make_pair(5, 3.1415926); // types are deduced
|
| 625 |
```
|
| 626 |
|
|
|
|
|
|
|
| 627 |
### Tuple-like access to pair <a id="pair.astuple">[[pair.astuple]]</a>
|
| 628 |
|
| 629 |
``` cpp
|
| 630 |
template <class T1, class T2>
|
| 631 |
-
struct tuple_size<pair<T1, T2>>
|
| 632 |
-
: integral_constant<size_t, 2> { };
|
| 633 |
```
|
| 634 |
|
| 635 |
``` cpp
|
| 636 |
tuple_element<0, pair<T1, T2>>::type
|
| 637 |
```
|
| 638 |
|
| 639 |
-
*Value:*
|
| 640 |
|
| 641 |
``` cpp
|
| 642 |
tuple_element<1, pair<T1, T2>>::type
|
| 643 |
```
|
| 644 |
|
| 645 |
-
*Value:*
|
| 646 |
|
| 647 |
``` cpp
|
| 648 |
template<size_t I, class T1, class T2>
|
| 649 |
-
constexpr tuple_element_t<I, pair<T1, T2>>&
|
| 650 |
-
get(pair<T1, T2>& p) noexcept;
|
| 651 |
template<size_t I, class T1, class T2>
|
| 652 |
-
constexpr const tuple_element_t<I, pair<T1, T2>>&
|
| 653 |
-
get(const pair<T1, T2>& p) noexcept;
|
| 654 |
-
```
|
| 655 |
-
|
| 656 |
-
*Returns:* If `I == 0` returns `p.first`; if `I == 1` returns
|
| 657 |
-
`p.second`; otherwise the program is ill-formed.
|
| 658 |
-
|
| 659 |
-
``` cpp
|
| 660 |
template<size_t I, class T1, class T2>
|
| 661 |
-
constexpr tuple_element_t<I, pair<T1, T2>>&&
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
*Returns:* If `I == 0` returns `std::forward<T1&&>(p.first)`; if
|
| 666 |
-
`I == 1` returns `std::forward<T2&&>(p.second)`; otherwise the program
|
| 667 |
-
is ill-formed.
|
| 668 |
-
|
| 669 |
-
``` cpp
|
| 670 |
-
template <class T, class U>
|
| 671 |
-
constexpr T& get(pair<T, U>& p) noexcept;
|
| 672 |
-
template <class T, class U>
|
| 673 |
-
constexpr const T& get(const pair<T, U>& p) noexcept;
|
| 674 |
-
```
|
| 675 |
-
|
| 676 |
-
*Requires:* `T` and `U` are distinct types. Otherwise, the program is
|
| 677 |
-
ill-formed.
|
| 678 |
-
|
| 679 |
-
*Returns:* `get<0>(p);`
|
| 680 |
-
|
| 681 |
-
``` cpp
|
| 682 |
-
template <class T, class U>
|
| 683 |
-
constexpr T&& get(pair<T, U>&& p) noexcept;
|
| 684 |
```
|
| 685 |
|
| 686 |
-
*
|
| 687 |
-
ill-formed.
|
| 688 |
-
|
| 689 |
-
*Returns:* `get<0>(std::move(p));`
|
| 690 |
|
| 691 |
``` cpp
|
| 692 |
-
template <class
|
| 693 |
-
constexpr
|
| 694 |
-
template <class
|
| 695 |
-
constexpr const
|
|
|
|
|
|
|
|
|
|
|
|
|
| 696 |
```
|
| 697 |
|
| 698 |
-
*Requires:* `
|
| 699 |
ill-formed.
|
| 700 |
|
| 701 |
-
*Returns:* `
|
| 702 |
|
| 703 |
``` cpp
|
| 704 |
-
template <class
|
| 705 |
-
constexpr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
```
|
| 707 |
|
| 708 |
-
*Requires:* `
|
| 709 |
ill-formed.
|
| 710 |
|
| 711 |
-
*Returns:* `
|
| 712 |
|
| 713 |
### Piecewise construction <a id="pair.piecewise">[[pair.piecewise]]</a>
|
| 714 |
|
| 715 |
``` cpp
|
| 716 |
-
struct piecewise_construct_t {
|
| 717 |
-
|
|
|
|
|
|
|
| 718 |
```
|
| 719 |
|
| 720 |
The `struct` `piecewise_construct_t` is an empty structure type used as
|
| 721 |
a unique type to disambiguate constructor and function overloading.
|
| 722 |
Specifically, `pair` has a constructor with `piecewise_construct_t` as
|
|
@@ -734,65 +1057,78 @@ arguments. Each template argument specifies the type of an element in
|
|
| 734 |
the `tuple`. Consequently, tuples are heterogeneous, fixed-size
|
| 735 |
collections of values. An instantiation of `tuple` with two arguments is
|
| 736 |
similar to an instantiation of `pair` with the same two arguments. See
|
| 737 |
[[pairs]].
|
| 738 |
|
|
|
|
|
|
|
| 739 |
``` cpp
|
| 740 |
namespace std {
|
| 741 |
-
// [tuple.tuple], class template tuple
|
| 742 |
-
template <class... Types>
|
|
|
|
| 743 |
|
| 744 |
-
// [tuple.creation], tuple creation functions
|
| 745 |
-
|
| 746 |
|
| 747 |
-
template <class...
|
| 748 |
-
constexpr tuple<VTypes...> make_tuple(
|
| 749 |
-
template <class... Types>
|
| 750 |
-
constexpr tuple<Types&&...> forward_as_tuple(Types&&...) noexcept;
|
| 751 |
|
| 752 |
-
template<class...
|
| 753 |
-
constexpr tuple<
|
|
|
|
|
|
|
|
|
|
| 754 |
|
| 755 |
template <class... Tuples>
|
| 756 |
-
constexpr tuple<
|
| 757 |
|
| 758 |
-
// [tuple.
|
| 759 |
-
template <class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 760 |
template <class T> class tuple_size<const T>;
|
| 761 |
template <class T> class tuple_size<volatile T>;
|
| 762 |
template <class T> class tuple_size<const volatile T>;
|
| 763 |
|
| 764 |
template <class... Types> class tuple_size<tuple<Types...>>;
|
| 765 |
|
| 766 |
-
template <size_t I, class T> class tuple_element;
|
| 767 |
template <size_t I, class T> class tuple_element<I, const T>;
|
| 768 |
template <size_t I, class T> class tuple_element<I, volatile T>;
|
| 769 |
template <size_t I, class T> class tuple_element<I, const volatile T>;
|
| 770 |
|
| 771 |
-
template <size_t I, class... Types>
|
|
|
|
| 772 |
|
| 773 |
template <size_t I, class T>
|
| 774 |
using tuple_element_t = typename tuple_element<I, T>::type;
|
| 775 |
|
| 776 |
-
// [tuple.elem], element access
|
| 777 |
template <size_t I, class... Types>
|
| 778 |
-
constexpr tuple_element_t<I, tuple<Types...>>&
|
| 779 |
-
get(tuple<Types...>&) noexcept;
|
| 780 |
template <size_t I, class... Types>
|
| 781 |
-
constexpr tuple_element_t<I, tuple<Types...>>&&
|
| 782 |
-
get(tuple<Types...>&&) noexcept;
|
| 783 |
template <size_t I, class... Types>
|
| 784 |
-
constexpr const tuple_element_t<I, tuple<Types...>>&
|
| 785 |
-
|
|
|
|
| 786 |
template <class T, class... Types>
|
| 787 |
constexpr T& get(tuple<Types...>& t) noexcept;
|
| 788 |
template <class T, class... Types>
|
| 789 |
constexpr T&& get(tuple<Types...>&& t) noexcept;
|
| 790 |
template <class T, class... Types>
|
| 791 |
constexpr const T& get(const tuple<Types...>& t) noexcept;
|
|
|
|
|
|
|
| 792 |
|
| 793 |
-
// [tuple.rel], relational operators
|
| 794 |
template<class... TTypes, class... UTypes>
|
| 795 |
constexpr bool operator==(const tuple<TTypes...>&, const tuple<UTypes...>&);
|
| 796 |
template<class... TTypes, class... UTypes>
|
| 797 |
constexpr bool operator<(const tuple<TTypes...>&, const tuple<UTypes...>&);
|
| 798 |
template<class... TTypes, class... UTypes>
|
|
@@ -806,62 +1142,65 @@ namespace std {
|
|
| 806 |
|
| 807 |
// [tuple.traits], allocator-related traits
|
| 808 |
template <class... Types, class Alloc>
|
| 809 |
struct uses_allocator<tuple<Types...>, Alloc>;
|
| 810 |
|
| 811 |
-
// [tuple.special], specialized algorithms
|
| 812 |
template <class... Types>
|
| 813 |
void swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(see below);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 814 |
}
|
| 815 |
```
|
| 816 |
|
| 817 |
### Class template `tuple` <a id="tuple.tuple">[[tuple.tuple]]</a>
|
| 818 |
|
| 819 |
``` cpp
|
| 820 |
namespace std {
|
| 821 |
template <class... Types>
|
| 822 |
class tuple {
|
| 823 |
public:
|
| 824 |
-
|
| 825 |
// [tuple.cnstr], tuple construction
|
| 826 |
-
|
| 827 |
-
|
| 828 |
template <class... UTypes>
|
| 829 |
-
|
| 830 |
|
| 831 |
tuple(const tuple&) = default;
|
| 832 |
tuple(tuple&&) = default;
|
| 833 |
|
| 834 |
template <class... UTypes>
|
| 835 |
-
|
| 836 |
template <class... UTypes>
|
| 837 |
-
|
| 838 |
|
| 839 |
template <class U1, class U2>
|
| 840 |
-
|
| 841 |
template <class U1, class U2>
|
| 842 |
-
|
| 843 |
|
| 844 |
// allocator-extended constructors
|
| 845 |
template <class Alloc>
|
| 846 |
tuple(allocator_arg_t, const Alloc& a);
|
| 847 |
template <class Alloc>
|
| 848 |
-
|
| 849 |
template <class Alloc, class... UTypes>
|
| 850 |
-
|
| 851 |
template <class Alloc>
|
| 852 |
tuple(allocator_arg_t, const Alloc& a, const tuple&);
|
| 853 |
template <class Alloc>
|
| 854 |
tuple(allocator_arg_t, const Alloc& a, tuple&&);
|
| 855 |
template <class Alloc, class... UTypes>
|
| 856 |
-
|
| 857 |
template <class Alloc, class... UTypes>
|
| 858 |
-
|
| 859 |
template <class Alloc, class U1, class U2>
|
| 860 |
-
|
| 861 |
template <class Alloc, class U1, class U2>
|
| 862 |
-
|
| 863 |
|
| 864 |
// [tuple.assign], tuple assignment
|
| 865 |
tuple& operator=(const tuple&);
|
| 866 |
tuple& operator=(tuple&&) noexcept(see below);
|
| 867 |
|
|
@@ -876,158 +1215,194 @@ namespace std {
|
|
| 876 |
tuple& operator=(pair<U1, U2>&&); // only if sizeof...(Types) == 2
|
| 877 |
|
| 878 |
// [tuple.swap], tuple swap
|
| 879 |
void swap(tuple&) noexcept(see below);
|
| 880 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 881 |
}
|
| 882 |
```
|
| 883 |
|
| 884 |
#### Construction <a id="tuple.cnstr">[[tuple.cnstr]]</a>
|
| 885 |
|
| 886 |
For each `tuple` constructor, an exception is thrown only if the
|
| 887 |
construction of one of the types in `Types` throws an exception.
|
| 888 |
|
| 889 |
The defaulted move and copy constructor, respectively, of `tuple` shall
|
| 890 |
-
be a
|
| 891 |
initializations for copy and move, respectively, would satisfy the
|
| 892 |
-
requirements for a
|
| 893 |
-
constructor of `tuple<>` shall be
|
|
|
|
|
|
|
|
|
|
| 894 |
|
| 895 |
In the constructor descriptions that follow, let i be in the range
|
| 896 |
-
\[`0`, `sizeof...(Types)`) in order, Tᵢ be the iᵗʰ type in `Types`,
|
| 897 |
-
Uᵢ be the iᵗʰ type in a template parameter pack named `UTypes`,
|
| 898 |
-
indexing is zero-based.
|
| 899 |
|
| 900 |
``` cpp
|
| 901 |
-
constexpr tuple();
|
| 902 |
```
|
| 903 |
|
| 904 |
-
*
|
| 905 |
|
| 906 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 907 |
|
| 908 |
``` cpp
|
| 909 |
-
constexpr
|
| 910 |
```
|
| 911 |
|
| 912 |
-
*Requires:* `is_copy_constructible<`Tᵢ`>::value` is true for all i.
|
| 913 |
-
|
| 914 |
*Effects:* Initializes each element with the value of the corresponding
|
| 915 |
parameter.
|
| 916 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 917 |
``` cpp
|
| 918 |
-
template <class... UTypes>
|
| 919 |
-
constexpr explicit tuple(UTypes&&... u);
|
| 920 |
```
|
| 921 |
|
| 922 |
-
*Requires:* `sizeof...(Types)` `==` `sizeof...(UTypes)`.
|
| 923 |
-
`is_constructible<`Tᵢ`, `Uᵢ`&&>::value` is `true` for all i.
|
| 924 |
-
|
| 925 |
*Effects:* Initializes the elements in the tuple with the corresponding
|
| 926 |
value in `std::forward<UTypes>(u)`.
|
| 927 |
|
| 928 |
-
This constructor shall not participate in overload resolution
|
| 929 |
-
|
| 930 |
-
|
|
|
|
|
|
|
| 931 |
|
| 932 |
``` cpp
|
| 933 |
tuple(const tuple& u) = default;
|
| 934 |
```
|
| 935 |
|
| 936 |
-
*Requires:* `
|
| 937 |
|
| 938 |
*Effects:* Initializes each element of `*this` with the corresponding
|
| 939 |
element of `u`.
|
| 940 |
|
| 941 |
``` cpp
|
| 942 |
tuple(tuple&& u) = default;
|
| 943 |
```
|
| 944 |
|
| 945 |
-
*Requires:* `
|
| 946 |
|
| 947 |
*Effects:* For all i, initializes the iᵗʰ element of `*this` with
|
| 948 |
-
`std::forward<`Tᵢ`>(get<`i`>(u))`.
|
| 949 |
|
| 950 |
``` cpp
|
| 951 |
-
template <class... UTypes> constexpr tuple(const tuple<UTypes...>& u);
|
| 952 |
```
|
| 953 |
|
| 954 |
-
*
|
| 955 |
-
`is_constructible<`Tᵢ`, const `Uᵢ`&>::value` is `true` for all i.
|
| 956 |
-
|
| 957 |
-
*Effects:* Constructs each element of `*this` with the corresponding
|
| 958 |
element of `u`.
|
| 959 |
|
| 960 |
-
This constructor shall not participate in overload resolution
|
| 961 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 962 |
|
| 963 |
``` cpp
|
| 964 |
-
template <class... UTypes> constexpr tuple(tuple<UTypes...>&& u);
|
| 965 |
```
|
| 966 |
|
| 967 |
-
*Requires:* `sizeof...(Types)` `==` `sizeof...(UTypes)`.
|
| 968 |
-
`is_constructible<`Tᵢ`, `Uᵢ`&&>::value` is `true` for all i.
|
| 969 |
-
|
| 970 |
*Effects:* For all i, initializes the iᵗʰ element of `*this` with
|
| 971 |
-
`std::forward<`Uᵢ`>(get<`i`>(u))`.
|
| 972 |
|
| 973 |
-
This constructor shall not participate in overload resolution
|
| 974 |
-
|
| 975 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 976 |
|
| 977 |
``` cpp
|
| 978 |
-
template <class U1, class U2> constexpr tuple(const pair<U1, U2>& u);
|
| 979 |
```
|
| 980 |
|
| 981 |
-
*
|
| 982 |
-
`is_constructible<`T₀`, const U1&>::value` is `true` for the first type
|
| 983 |
-
T₀ in `Types` and `is_constructible<`T₁`, const U2&>::value` is `true`
|
| 984 |
-
for the second type T₁ in `Types`.
|
| 985 |
-
|
| 986 |
-
*Effects:* Constructs the first element with `u.first` and the second
|
| 987 |
element with `u.second`.
|
| 988 |
|
| 989 |
-
This constructor shall not participate in overload resolution
|
| 990 |
-
|
| 991 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 992 |
|
| 993 |
``` cpp
|
| 994 |
-
template <class U1, class U2> constexpr tuple(pair<U1, U2>&& u);
|
| 995 |
```
|
| 996 |
|
| 997 |
-
*Requires:* `sizeof...(Types) == 2`.
|
| 998 |
-
`is_constructible<`T₀`, U1&&>::value` is `true` for the first type T₀ in
|
| 999 |
-
`Types` and `is_constructible<`T₁`, U2&&>::value` is `true` for the
|
| 1000 |
-
second type T₁ in `Types`.
|
| 1001 |
-
|
| 1002 |
*Effects:* Initializes the first element with
|
| 1003 |
`std::forward<U1>(u.first)` and the second element with
|
| 1004 |
`std::forward<U2>(u.second)`.
|
| 1005 |
|
| 1006 |
-
This constructor shall not participate in overload resolution
|
| 1007 |
-
`
|
| 1008 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1009 |
|
| 1010 |
``` cpp
|
| 1011 |
template <class Alloc>
|
| 1012 |
tuple(allocator_arg_t, const Alloc& a);
|
| 1013 |
template <class Alloc>
|
| 1014 |
-
tuple(allocator_arg_t, const Alloc& a, const Types&...);
|
| 1015 |
template <class Alloc, class... UTypes>
|
| 1016 |
-
tuple(allocator_arg_t, const Alloc& a, UTypes&&...);
|
| 1017 |
template <class Alloc>
|
| 1018 |
tuple(allocator_arg_t, const Alloc& a, const tuple&);
|
| 1019 |
template <class Alloc>
|
| 1020 |
tuple(allocator_arg_t, const Alloc& a, tuple&&);
|
| 1021 |
template <class Alloc, class... UTypes>
|
| 1022 |
-
tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&);
|
| 1023 |
template <class Alloc, class... UTypes>
|
| 1024 |
-
tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&);
|
| 1025 |
template <class Alloc, class U1, class U2>
|
| 1026 |
-
tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
|
| 1027 |
template <class Alloc, class U1, class U2>
|
| 1028 |
-
tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
|
| 1029 |
```
|
| 1030 |
|
| 1031 |
*Requires:* `Alloc` shall meet the requirements for an
|
| 1032 |
`Allocator` ([[allocator.requirements]]).
|
| 1033 |
|
|
@@ -1038,240 +1413,300 @@ construction ([[allocator.uses.construction]]).
|
|
| 1038 |
#### Assignment <a id="tuple.assign">[[tuple.assign]]</a>
|
| 1039 |
|
| 1040 |
For each `tuple` assignment operator, an exception is thrown only if the
|
| 1041 |
assignment of one of the types in `Types` throws an exception. In the
|
| 1042 |
function descriptions that follow, let i be in the range \[`0`,
|
| 1043 |
-
`sizeof...(Types)`) in order, Tᵢ be the iᵗʰ type in `Types`, and Uᵢ
|
| 1044 |
-
the iᵗʰ type in a template parameter pack named `UTypes`, where
|
| 1045 |
-
is zero-based.
|
| 1046 |
|
| 1047 |
``` cpp
|
| 1048 |
tuple& operator=(const tuple& u);
|
| 1049 |
```
|
| 1050 |
|
| 1051 |
-
*Requires:* `is_copy_assignable<`Tᵢ`>::value` is `true` for all i.
|
| 1052 |
-
|
| 1053 |
*Effects:* Assigns each element of `u` to the corresponding element of
|
| 1054 |
`*this`.
|
| 1055 |
|
| 1056 |
-
*
|
|
|
|
|
|
|
|
|
|
| 1057 |
|
| 1058 |
``` cpp
|
| 1059 |
tuple& operator=(tuple&& u) noexcept(see below);
|
| 1060 |
```
|
| 1061 |
|
| 1062 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1063 |
<span class="smallcaps">and</span> of the following expressions:
|
| 1064 |
|
| 1065 |
``` cpp
|
| 1066 |
-
|
| 1067 |
```
|
| 1068 |
|
| 1069 |
where Tᵢ is the iᵗʰ type in `Types`.
|
| 1070 |
|
| 1071 |
-
*Requires:* `is_move_assignable<`Tᵢ`>::value` is `true` for all i.
|
| 1072 |
-
|
| 1073 |
-
*Effects:* For all i, assigns `std::forward<`Tᵢ`>(get<`i`>(u))` to
|
| 1074 |
-
`get<`i`>(*this)`.
|
| 1075 |
-
|
| 1076 |
*Returns:* `*this`.
|
| 1077 |
|
| 1078 |
``` cpp
|
| 1079 |
-
template <class... UTypes>
|
| 1080 |
-
tuple& operator=(const tuple<UTypes...>& u);
|
| 1081 |
```
|
| 1082 |
|
| 1083 |
-
*Requires:* `sizeof...(Types) == sizeof...(UTypes)` and
|
| 1084 |
-
`is_assignable<`Tᵢ`&, const `Uᵢ`&>::value` is `true` for all i.
|
| 1085 |
-
|
| 1086 |
*Effects:* Assigns each element of `u` to the corresponding element of
|
| 1087 |
`*this`.
|
| 1088 |
|
| 1089 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1090 |
|
| 1091 |
``` cpp
|
| 1092 |
-
template <class... UTypes>
|
| 1093 |
-
tuple& operator=(tuple<UTypes...>&& u);
|
| 1094 |
```
|
| 1095 |
|
| 1096 |
-
*
|
| 1097 |
-
`sizeof...(Types)` `==`
|
| 1098 |
-
`sizeof...(UTypes)`.
|
| 1099 |
-
|
| 1100 |
-
*Effects:* For all i, assigns `std::forward<`Uᵢ`>(get<`i`)>(u))` to
|
| 1101 |
`get<`i`>(*this)`.
|
| 1102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1103 |
*Returns:* `*this`.
|
| 1104 |
|
| 1105 |
``` cpp
|
| 1106 |
template <class U1, class U2> tuple& operator=(const pair<U1, U2>& u);
|
| 1107 |
```
|
| 1108 |
|
| 1109 |
-
*Requires:* `sizeof...(Types) == 2`.
|
| 1110 |
-
`is_assignable<`T₀`&, const U1&>::value` is `true` for the first type T₀
|
| 1111 |
-
in `Types` and `is_assignable<`T₁`&, const U2&>::value` is `true` for
|
| 1112 |
-
the second type T₁ in `Types`.
|
| 1113 |
-
|
| 1114 |
*Effects:* Assigns `u.first` to the first element of `*this` and
|
| 1115 |
`u.second` to the second element of `*this`.
|
| 1116 |
|
| 1117 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1118 |
|
| 1119 |
``` cpp
|
| 1120 |
template <class U1, class U2> tuple& operator=(pair<U1, U2>&& u);
|
| 1121 |
```
|
| 1122 |
|
| 1123 |
-
*Requires:* `sizeof...(Types) == 2`. `is_assignable<`T₀`&, U1&&>::value`
|
| 1124 |
-
is `true` for the first type T₀ in `Types` and
|
| 1125 |
-
`is_assignable<`T₁`&, U2&&>::value` is `true` for the second type T₁ in
|
| 1126 |
-
`Types`.
|
| 1127 |
-
|
| 1128 |
*Effects:* Assigns `std::forward<U1>(u.first)` to the first element of
|
| 1129 |
`*this` and
|
| 1130 |
`std::forward<U2>(u.second)` to the second element of `*this`.
|
| 1131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1132 |
*Returns:* `*this`.
|
| 1133 |
|
| 1134 |
#### `swap` <a id="tuple.swap">[[tuple.swap]]</a>
|
| 1135 |
|
| 1136 |
``` cpp
|
| 1137 |
void swap(tuple& rhs) noexcept(see below);
|
| 1138 |
```
|
| 1139 |
|
| 1140 |
-
The expression inside `noexcept` is equivalent to the logical
|
| 1141 |
-
<span class="smallcaps">and</span> of the following expressions:
|
| 1142 |
-
|
| 1143 |
-
``` cpp
|
| 1144 |
-
noexcept(swap(declval<Tᵢ&>>(), declval<Tᵢ&>()))
|
| 1145 |
-
```
|
| 1146 |
-
|
| 1147 |
-
where Tᵢ is the iᵗʰ type in `Types`.
|
| 1148 |
-
|
| 1149 |
*Requires:* Each element in `*this` shall be swappable
|
| 1150 |
with ([[swappable.requirements]]) the corresponding element in `rhs`.
|
| 1151 |
|
| 1152 |
*Effects:* Calls `swap` for each element in `*this` and its
|
| 1153 |
corresponding element in `rhs`.
|
| 1154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1155 |
*Throws:* Nothing unless one of the element-wise `swap` calls throws an
|
| 1156 |
exception.
|
| 1157 |
|
| 1158 |
#### Tuple creation functions <a id="tuple.creation">[[tuple.creation]]</a>
|
| 1159 |
|
| 1160 |
-
In the function descriptions that follow,
|
| 1161 |
-
`
|
| 1162 |
-
|
| 1163 |
-
`sizeof...(UTypes)`) in order and Uⱼ be the jᵗʰ type in a template
|
| 1164 |
-
parameter pack named `UTypes`, where indexing is zero-based.
|
| 1165 |
|
| 1166 |
``` cpp
|
| 1167 |
-
template<class...
|
| 1168 |
-
constexpr tuple<VTypes...> make_tuple(
|
| 1169 |
```
|
| 1170 |
|
| 1171 |
-
Let Uᵢ be `decay_t<
|
| 1172 |
-
`
|
| 1173 |
-
Uᵢ
|
|
|
|
| 1174 |
|
| 1175 |
-
*Returns:* `tuple<VTypes...>(std::forward<
|
|
|
|
|
|
|
| 1176 |
|
| 1177 |
``` cpp
|
| 1178 |
int i; float j;
|
| 1179 |
make_tuple(1, ref(i), cref(j))
|
| 1180 |
```
|
| 1181 |
|
| 1182 |
-
creates a tuple of type
|
| 1183 |
|
| 1184 |
-
|
| 1185 |
-
tuple<int, int&, const float&>
|
| 1186 |
-
```
|
| 1187 |
|
| 1188 |
``` cpp
|
| 1189 |
-
template<class...
|
| 1190 |
-
constexpr tuple<
|
| 1191 |
```
|
| 1192 |
|
| 1193 |
*Effects:* Constructs a tuple of references to the arguments in `t`
|
| 1194 |
suitable for forwarding as arguments to a function. Because the result
|
| 1195 |
may contain references to temporary variables, a program shall ensure
|
| 1196 |
that the return value of this function does not outlive any of its
|
| 1197 |
-
arguments
|
| 1198 |
named variable).
|
| 1199 |
|
| 1200 |
-
*Returns:* `tuple<
|
| 1201 |
|
| 1202 |
``` cpp
|
| 1203 |
-
template<class...
|
| 1204 |
-
constexpr tuple<
|
| 1205 |
```
|
| 1206 |
|
| 1207 |
-
*Returns:* `tuple<
|
| 1208 |
`ignore`, assigning any value to the corresponding tuple element has no
|
| 1209 |
effect.
|
| 1210 |
|
|
|
|
|
|
|
| 1211 |
`tie` functions allow one to create tuples that unpack tuples into
|
| 1212 |
variables. `ignore` can be used for elements that are not needed:
|
| 1213 |
|
| 1214 |
``` cpp
|
| 1215 |
int i; std::string s;
|
| 1216 |
tie(i, ignore, s) = make_tuple(42, 3.14, "C++");
|
| 1217 |
// i == 42, s == "C++"
|
| 1218 |
```
|
| 1219 |
|
|
|
|
|
|
|
| 1220 |
``` cpp
|
| 1221 |
template <class... Tuples>
|
| 1222 |
constexpr tuple<CTypes...> tuple_cat(Tuples&&... tpls);
|
| 1223 |
```
|
| 1224 |
|
| 1225 |
-
In the following paragraphs, let Tᵢ be the iᵗʰ type in `Tuples`, Uᵢ
|
| 1226 |
-
`remove_reference_t<
|
| 1227 |
-
parameter pack `tpls`, where all indexing is zero-based.
|
| 1228 |
|
| 1229 |
-
*Requires:* For all i, Uᵢ shall be the type cvᵢ `tuple<`Argsᵢ...
|
| 1230 |
-
where cvᵢ is the (possibly empty) iᵗʰ cv-qualifier-seq and Argsᵢ is
|
| 1231 |
-
parameter pack representing the element types in Uᵢ. Let
|
| 1232 |
-
k
|
| 1233 |
-
satisfied:
|
| 1234 |
-
`is_constructible<`Aᵢₖ`, `cvᵢ` `Aᵢₖ`&>::value == true`, otherwise
|
| 1235 |
-
`is_constructible<`Aᵢₖ`, `cvᵢ Aᵢₖ`&&>::value == true`.
|
| 1236 |
|
| 1237 |
-
|
| 1238 |
-
|
| 1239 |
-
|
| 1240 |
-
|
| 1241 |
-
to the
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1242 |
|
| 1243 |
*Returns:* A `tuple` object constructed by initializing the kᵢᵗʰ type
|
| 1244 |
-
element
|
| 1245 |
-
`get<`kᵢ`>(std::forward<`Tᵢ`>(`tpᵢ`))` for each valid kᵢ and each group
|
| 1246 |
-
eᵢ in order.
|
| 1247 |
|
| 1248 |
-
|
| 1249 |
-
|
| 1250 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1251 |
|
| 1252 |
#### Tuple helper classes <a id="tuple.helper">[[tuple.helper]]</a>
|
| 1253 |
|
| 1254 |
``` cpp
|
| 1255 |
template <class T> struct tuple_size;
|
| 1256 |
```
|
| 1257 |
|
| 1258 |
-
*Remarks:* All specializations of `tuple_size
|
| 1259 |
-
`UnaryTypeTrait` requirements ([[meta.rqmts]]) with a
|
| 1260 |
-
|
| 1261 |
|
| 1262 |
``` cpp
|
| 1263 |
template <class... Types>
|
| 1264 |
-
class tuple_size<tuple<Types...> >
|
| 1265 |
-
: public integral_constant<size_t, sizeof...(Types)> { };
|
| 1266 |
```
|
| 1267 |
|
| 1268 |
``` cpp
|
| 1269 |
template <size_t I, class... Types>
|
| 1270 |
class tuple_element<I, tuple<Types...>> {
|
| 1271 |
public:
|
| 1272 |
-
|
| 1273 |
};
|
| 1274 |
```
|
| 1275 |
|
| 1276 |
*Requires:* `I < sizeof...(Types)`. The program is ill-formed if `I` is
|
| 1277 |
out of bounds.
|
|
@@ -1283,101 +1718,119 @@ is zero-based.
|
|
| 1283 |
template <class T> class tuple_size<const T>;
|
| 1284 |
template <class T> class tuple_size<volatile T>;
|
| 1285 |
template <class T> class tuple_size<const volatile T>;
|
| 1286 |
```
|
| 1287 |
|
| 1288 |
-
Let *TS* denote `tuple_size<T>` of the cv-unqualified type `T`.
|
| 1289 |
-
|
| 1290 |
-
|
|
|
|
|
|
|
| 1291 |
|
| 1292 |
``` cpp
|
| 1293 |
integral_constant<size_t, TS::value>
|
| 1294 |
```
|
| 1295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1296 |
``` cpp
|
| 1297 |
template <size_t I, class T> class tuple_element<I, const T>;
|
| 1298 |
template <size_t I, class T> class tuple_element<I, volatile T>;
|
| 1299 |
template <size_t I, class T> class tuple_element<I, const volatile T>;
|
| 1300 |
```
|
| 1301 |
|
| 1302 |
-
Let *TE* denote `
|
| 1303 |
-
Then each of the three templates shall meet the
|
| 1304 |
-
requirements ([[meta.rqmts]]) with a member
|
| 1305 |
-
the following type:
|
| 1306 |
|
| 1307 |
-
- for the first specialization, `add_const_t<`*`TE`*`
|
| 1308 |
-
- for the second specialization, `add_volatile_t<`*`TE`*`
|
| 1309 |
-
- for the third specialization, `add_cv_t<`*`TE`*`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1310 |
|
| 1311 |
#### Element access <a id="tuple.elem">[[tuple.elem]]</a>
|
| 1312 |
|
| 1313 |
``` cpp
|
| 1314 |
template <size_t I, class... Types>
|
| 1315 |
-
constexpr tuple_element_t<I, tuple<Types...>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1316 |
```
|
| 1317 |
|
| 1318 |
*Requires:* `I < sizeof...(Types)`. The program is ill-formed if `I` is
|
| 1319 |
out of bounds.
|
| 1320 |
|
| 1321 |
*Returns:* A reference to the `I`th element of `t`, where indexing is
|
| 1322 |
zero-based.
|
| 1323 |
|
| 1324 |
-
```
|
| 1325 |
-
|
| 1326 |
-
|
| 1327 |
-
|
| 1328 |
-
|
| 1329 |
-
|
| 1330 |
-
|
| 1331 |
-
`
|
| 1332 |
-
|
| 1333 |
-
*Note:* if a `T` in `Types` is some reference type `X&`, the return type
|
| 1334 |
-
is `X&`, not `X&&`. However, if the element type is a non-reference type
|
| 1335 |
-
`T`, the return type is `T&&`.
|
| 1336 |
-
|
| 1337 |
-
``` cpp
|
| 1338 |
-
template <size_t I, class... Types>
|
| 1339 |
-
constexpr tuple_element_t<I, tuple<Types...> > const& get(const tuple<Types...>& t) noexcept;
|
| 1340 |
-
```
|
| 1341 |
-
|
| 1342 |
-
*Requires:* `I < sizeof...(Types)`. The program is ill-formed if `I` is
|
| 1343 |
-
out of bounds.
|
| 1344 |
-
|
| 1345 |
-
*Returns:* A const reference to the `I`th element of `t`, where indexing
|
| 1346 |
-
is zero-based.
|
| 1347 |
-
|
| 1348 |
-
Constness is shallow. If a `T` in `Types` is some reference type `X&`,
|
| 1349 |
-
the return type is `X&`, not `const X&`. However, if the element type is
|
| 1350 |
-
non-reference type `T`, the return type is `const T&`. This is
|
| 1351 |
-
consistent with how constness is defined to work for member variables of
|
| 1352 |
-
reference type.
|
| 1353 |
|
| 1354 |
``` cpp
|
| 1355 |
template <class T, class... Types>
|
| 1356 |
constexpr T& get(tuple<Types...>& t) noexcept;
|
| 1357 |
template <class T, class... Types>
|
| 1358 |
constexpr T&& get(tuple<Types...>&& t) noexcept;
|
| 1359 |
template <class T, class... Types>
|
| 1360 |
constexpr const T& get(const tuple<Types...>& t) noexcept;
|
|
|
|
|
|
|
| 1361 |
```
|
| 1362 |
|
| 1363 |
*Requires:* The type `T` occurs exactly once in `Types...`. Otherwise,
|
| 1364 |
the program is ill-formed.
|
| 1365 |
|
| 1366 |
*Returns:* A reference to the element of `t` corresponding to the type
|
| 1367 |
`T` in `Types...`.
|
| 1368 |
|
|
|
|
|
|
|
| 1369 |
``` cpp
|
| 1370 |
const tuple<int, const int, double, double> t(1, 2, 3.4, 5.6);
|
| 1371 |
const int& i1 = get<int>(t); // OK. Not ambiguous. i1 == 1
|
| 1372 |
const int& i2 = get<const int>(t); // OK. Not ambiguous. i2 == 2
|
| 1373 |
const double& d = get<double>(t); // ERROR. ill-formed
|
| 1374 |
```
|
| 1375 |
|
| 1376 |
-
|
| 1377 |
-
|
| 1378 |
-
|
|
|
|
|
|
|
|
|
|
| 1379 |
|
| 1380 |
#### Relational operators <a id="tuple.rel">[[tuple.rel]]</a>
|
| 1381 |
|
| 1382 |
``` cpp
|
| 1383 |
template<class... TTypes, class... UTypes>
|
|
@@ -1400,11 +1853,11 @@ after the first equality comparison that evaluates to `false`.
|
|
| 1400 |
template<class... TTypes, class... UTypes>
|
| 1401 |
constexpr bool operator<(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
|
| 1402 |
```
|
| 1403 |
|
| 1404 |
*Requires:* For all `i`, where `0 <= i` and `i < sizeof...(TTypes)`,
|
| 1405 |
-
`get<i>(t) < get<i>(u)` and `get<i>(u) < get<i>(t)` are valid
|
| 1406 |
expressions returning types that are convertible to `bool`.
|
| 1407 |
`sizeof...(TTypes)` `==` `sizeof...(UTypes)`.
|
| 1408 |
|
| 1409 |
*Returns:* The result of a lexicographical comparison between `t` and
|
| 1410 |
`u`. The result is defined as:
|
|
@@ -1430,24 +1883,25 @@ template<class... TTypes, class... UTypes>
|
|
| 1430 |
``` cpp
|
| 1431 |
template<class... TTypes, class... UTypes>
|
| 1432 |
constexpr bool operator<=(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
|
| 1433 |
```
|
| 1434 |
|
| 1435 |
-
*Returns:* `!(u < t)`
|
| 1436 |
|
| 1437 |
``` cpp
|
| 1438 |
template<class... TTypes, class... UTypes>
|
| 1439 |
constexpr bool operator>=(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
|
| 1440 |
```
|
| 1441 |
|
| 1442 |
-
*Returns:* `!(t < u)`
|
| 1443 |
|
| 1444 |
-
The above definitions for comparison
|
| 1445 |
-
(or `uₜₐᵢₗ`) to be constructed. It may not even be
|
| 1446 |
-
`u` are not required to be copy constructible.
|
| 1447 |
-
|
| 1448 |
-
beyond what is required to determine the result of the
|
|
|
|
| 1449 |
|
| 1450 |
#### Tuple traits <a id="tuple.traits">[[tuple.traits]]</a>
|
| 1451 |
|
| 1452 |
``` cpp
|
| 1453 |
template <class... Types, class Alloc>
|
|
@@ -1455,92 +1909,2581 @@ template <class... Types, class Alloc>
|
|
| 1455 |
```
|
| 1456 |
|
| 1457 |
*Requires:* `Alloc` shall be an
|
| 1458 |
`Allocator` ([[allocator.requirements]]).
|
| 1459 |
|
| 1460 |
-
Specialization of this trait informs other library
|
| 1461 |
-
`tuple` can be constructed with an allocator, even
|
| 1462 |
-
have a nested `allocator_type`.
|
| 1463 |
|
| 1464 |
#### Tuple specialized algorithms <a id="tuple.special">[[tuple.special]]</a>
|
| 1465 |
|
| 1466 |
``` cpp
|
| 1467 |
template <class... Types>
|
| 1468 |
void swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(see below);
|
| 1469 |
```
|
| 1470 |
|
| 1471 |
-
|
|
|
|
|
|
|
|
|
|
| 1472 |
|
| 1473 |
``` cpp
|
| 1474 |
noexcept(x.swap(y))
|
| 1475 |
```
|
| 1476 |
|
| 1477 |
-
*Effects:* `x.swap(y)`
|
| 1478 |
|
| 1479 |
-
##
|
| 1480 |
|
| 1481 |
-
### In general <a id="
|
| 1482 |
|
| 1483 |
-
|
| 1484 |
-
|
| 1485 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1486 |
|
| 1487 |
``` cpp
|
| 1488 |
-
template<class
|
| 1489 |
-
|
| 1490 |
-
|
| 1491 |
-
}
|
| 1492 |
|
| 1493 |
-
|
| 1494 |
-
|
| 1495 |
-
|
| 1496 |
-
|
| 1497 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1498 |
```
|
| 1499 |
|
| 1500 |
-
|
| 1501 |
-
|
| 1502 |
|
| 1503 |
-
|
|
|
|
|
|
|
|
|
|
| 1504 |
|
| 1505 |
``` cpp
|
| 1506 |
-
|
| 1507 |
-
|
| 1508 |
-
|
| 1509 |
-
|
| 1510 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1511 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1512 |
}
|
| 1513 |
```
|
| 1514 |
|
| 1515 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1516 |
|
| 1517 |
-
|
| 1518 |
|
| 1519 |
``` cpp
|
| 1520 |
-
|
| 1521 |
-
|
|
|
|
| 1522 |
```
|
| 1523 |
|
| 1524 |
-
|
| 1525 |
-
`make_integer_sequence` denotes a specialization of `integer_sequence`
|
| 1526 |
-
with `N` template non-type arguments. The type
|
| 1527 |
-
`make_integer_sequence<T, N>` denotes the type
|
| 1528 |
-
`integer_sequence<T, 0, 1, ..., N-1>`. `make_integer_sequence<int, 0>`
|
| 1529 |
-
denotes the type `integer_sequence<int>`
|
| 1530 |
|
| 1531 |
-
##
|
| 1532 |
|
| 1533 |
-
|
| 1534 |
|
| 1535 |
``` cpp
|
| 1536 |
#include <string>
|
| 1537 |
-
#include <iosfwd>
|
|
|
|
| 1538 |
namespace std {
|
| 1539 |
template <size_t N> class bitset;
|
| 1540 |
|
| 1541 |
-
// [bitset.operators] bitset operators
|
| 1542 |
template <size_t N>
|
| 1543 |
bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept;
|
| 1544 |
template <size_t N>
|
| 1545 |
bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept;
|
| 1546 |
template <size_t N>
|
|
@@ -1556,10 +4499,12 @@ namespace std {
|
|
| 1556 |
|
| 1557 |
The header `<bitset>` defines a class template and several related
|
| 1558 |
functions for representing and manipulating fixed-size sequences of
|
| 1559 |
bits.
|
| 1560 |
|
|
|
|
|
|
|
| 1561 |
``` cpp
|
| 1562 |
namespace std {
|
| 1563 |
template<size_t N> class bitset {
|
| 1564 |
public:
|
| 1565 |
// bit reference:
|
|
@@ -1573,27 +4518,29 @@ namespace std {
|
|
| 1573 |
bool operator~() const noexcept; // flips the bit
|
| 1574 |
operator bool() const noexcept; // for x = b[i];
|
| 1575 |
reference& flip() noexcept; // for b[i].flip();
|
| 1576 |
};
|
| 1577 |
|
| 1578 |
-
// [bitset.cons] constructors
|
| 1579 |
constexpr bitset() noexcept;
|
| 1580 |
constexpr bitset(unsigned long long val) noexcept;
|
| 1581 |
template<class charT, class traits, class Allocator>
|
| 1582 |
explicit bitset(
|
| 1583 |
const basic_string<charT, traits, Allocator>& str,
|
| 1584 |
typename basic_string<charT, traits, Allocator>::size_type pos = 0,
|
| 1585 |
typename basic_string<charT, traits, Allocator>::size_type n =
|
| 1586 |
basic_string<charT, traits, Allocator>::npos,
|
| 1587 |
-
|
|
|
|
| 1588 |
template <class charT>
|
| 1589 |
explicit bitset(
|
| 1590 |
const charT* str,
|
| 1591 |
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
|
| 1592 |
-
charT zero = charT('0'),
|
|
|
|
| 1593 |
|
| 1594 |
-
// [bitset.members] bitset operations
|
| 1595 |
bitset<N>& operator&=(const bitset<N>& rhs) noexcept;
|
| 1596 |
bitset<N>& operator|=(const bitset<N>& rhs) noexcept;
|
| 1597 |
bitset<N>& operator^=(const bitset<N>& rhs) noexcept;
|
| 1598 |
bitset<N>& operator<<=(size_t pos) noexcept;
|
| 1599 |
bitset<N>& operator>>=(size_t pos) noexcept;
|
|
@@ -1614,10 +4561,11 @@ namespace std {
|
|
| 1614 |
template <class charT = char,
|
| 1615 |
class traits = char_traits<charT>,
|
| 1616 |
class Allocator = allocator<charT>>
|
| 1617 |
basic_string<charT, traits, Allocator>
|
| 1618 |
to_string(charT zero = charT('0'), charT one = charT('1')) const;
|
|
|
|
| 1619 |
size_t count() const noexcept;
|
| 1620 |
constexpr size_t size() const noexcept;
|
| 1621 |
bool operator==(const bitset<N>& rhs) const noexcept;
|
| 1622 |
bool operator!=(const bitset<N>& rhs) const noexcept;
|
| 1623 |
bool test(size_t pos) const;
|
|
@@ -1626,11 +4574,11 @@ namespace std {
|
|
| 1626 |
bool none() const noexcept;
|
| 1627 |
bitset<N> operator<<(size_t pos) const noexcept;
|
| 1628 |
bitset<N> operator>>(size_t pos) const noexcept;
|
| 1629 |
};
|
| 1630 |
|
| 1631 |
-
// [bitset.hash] hash support
|
| 1632 |
template <class T> struct hash;
|
| 1633 |
template <size_t N> struct hash<bitset<N>>;
|
| 1634 |
}
|
| 1635 |
```
|
| 1636 |
|
|
@@ -1653,11 +4601,11 @@ errors, each associated with a distinct exception:
|
|
| 1653 |
- an *out-of-range* error is associated with exceptions of type
|
| 1654 |
`out_of_range` ([[out.of.range]]);
|
| 1655 |
- an *overflow* error is associated with exceptions of type
|
| 1656 |
`overflow_error` ([[overflow.error]]).
|
| 1657 |
|
| 1658 |
-
### `bitset` constructors <a id="bitset.cons">[[bitset.cons]]</a>
|
| 1659 |
|
| 1660 |
``` cpp
|
| 1661 |
constexpr bitset() noexcept;
|
| 1662 |
```
|
| 1663 |
|
|
@@ -1682,13 +4630,12 @@ bitset(const basic_string<charT, traits, Allocator>& str,
|
|
| 1682 |
typename basic_string<charT, traits, Allocator>::size_type n =
|
| 1683 |
basic_string<charT, traits, Allocator>::npos,
|
| 1684 |
charT zero = charT('0'), charT one = charT('1'));
|
| 1685 |
```
|
| 1686 |
|
| 1687 |
-
*
|
| 1688 |
-
|
| 1689 |
-
*Throws:* `out_of_range` if `pos > str.size()`.
|
| 1690 |
|
| 1691 |
*Effects:* Determines the effective length `rlen` of the initializing
|
| 1692 |
string as the smaller of `n` and `str.size() - pos`.
|
| 1693 |
|
| 1694 |
The function then throws
|
|
@@ -1716,21 +4663,21 @@ template <class charT>
|
|
| 1716 |
const charT* str,
|
| 1717 |
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
|
| 1718 |
charT zero = charT('0'), charT one = charT('1'));
|
| 1719 |
```
|
| 1720 |
|
| 1721 |
-
*Effects:* Constructs an object of class `bitset<N>` as if by
|
| 1722 |
|
| 1723 |
``` cpp
|
| 1724 |
bitset(
|
| 1725 |
n == basic_string<charT>::npos
|
| 1726 |
? basic_string<charT>(str)
|
| 1727 |
: basic_string<charT>(str, n),
|
| 1728 |
0, n, zero, one)
|
| 1729 |
```
|
| 1730 |
|
| 1731 |
-
### `bitset` members <a id="bitset.members">[[bitset.members]]</a>
|
| 1732 |
|
| 1733 |
``` cpp
|
| 1734 |
bitset<N>& operator&=(const bitset<N>& rhs) noexcept;
|
| 1735 |
```
|
| 1736 |
|
|
@@ -1793,12 +4740,10 @@ bitset<N>& set() noexcept;
|
|
| 1793 |
|
| 1794 |
``` cpp
|
| 1795 |
bitset<N>& set(size_t pos, bool val = true);
|
| 1796 |
```
|
| 1797 |
|
| 1798 |
-
*Requires:* `pos` is valid
|
| 1799 |
-
|
| 1800 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 1801 |
position.
|
| 1802 |
|
| 1803 |
*Effects:* Stores a new value in the bit at position `pos` in `*this`.
|
| 1804 |
If `val` is nonzero, the stored value is one, otherwise it is zero.
|
|
@@ -1815,12 +4760,10 @@ bitset<N>& reset() noexcept;
|
|
| 1815 |
|
| 1816 |
``` cpp
|
| 1817 |
bitset<N>& reset(size_t pos);
|
| 1818 |
```
|
| 1819 |
|
| 1820 |
-
*Requires:* `pos` is valid
|
| 1821 |
-
|
| 1822 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 1823 |
position.
|
| 1824 |
|
| 1825 |
*Effects:* Resets the bit at position `pos` in `*this`.
|
| 1826 |
|
|
@@ -1845,12 +4788,10 @@ bitset<N>& flip() noexcept;
|
|
| 1845 |
|
| 1846 |
``` cpp
|
| 1847 |
bitset<N>& flip(size_t pos);
|
| 1848 |
```
|
| 1849 |
|
| 1850 |
-
*Requires:* `pos` is valid
|
| 1851 |
-
|
| 1852 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 1853 |
position.
|
| 1854 |
|
| 1855 |
*Effects:* Toggles the bit at position `pos` in `*this`.
|
| 1856 |
|
|
@@ -1921,35 +4862,33 @@ bool operator!=(const bitset<N>& rhs) const noexcept;
|
|
| 1921 |
|
| 1922 |
``` cpp
|
| 1923 |
bool test(size_t pos) const;
|
| 1924 |
```
|
| 1925 |
|
| 1926 |
-
*Requires:* `pos` is valid
|
| 1927 |
-
|
| 1928 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 1929 |
position.
|
| 1930 |
|
| 1931 |
*Returns:* `true` if the bit at position `pos` in `*this` has the value
|
| 1932 |
one.
|
| 1933 |
|
| 1934 |
``` cpp
|
| 1935 |
bool all() const noexcept;
|
| 1936 |
```
|
| 1937 |
|
| 1938 |
-
*Returns:* `count() == size()`
|
| 1939 |
|
| 1940 |
``` cpp
|
| 1941 |
bool any() const noexcept;
|
| 1942 |
```
|
| 1943 |
|
| 1944 |
-
*Returns:* `count() != 0`
|
| 1945 |
|
| 1946 |
``` cpp
|
| 1947 |
bool none() const noexcept;
|
| 1948 |
```
|
| 1949 |
|
| 1950 |
-
*Returns:* `count() == 0`
|
| 1951 |
|
| 1952 |
``` cpp
|
| 1953 |
bitset<N> operator<<(size_t pos) const noexcept;
|
| 1954 |
```
|
| 1955 |
|
|
@@ -1982,23 +4921,22 @@ bitset<N>::reference operator[](size_t pos);
|
|
| 1982 |
`(*this)[pos] == this->test(pos)`, and such that `(*this)[pos] = val` is
|
| 1983 |
equivalent to `this->set(pos, val)`.
|
| 1984 |
|
| 1985 |
*Throws:* Nothing.
|
| 1986 |
|
| 1987 |
-
For the purpose of determining the presence of a data
|
| 1988 |
race ([[intro.multithread]]), any access or update through the
|
| 1989 |
resulting reference potentially accesses or modifies, respectively, the
|
| 1990 |
entire underlying bitset.
|
| 1991 |
|
| 1992 |
### `bitset` hash support <a id="bitset.hash">[[bitset.hash]]</a>
|
| 1993 |
|
| 1994 |
``` cpp
|
| 1995 |
template <size_t N> struct hash<bitset<N>>;
|
| 1996 |
```
|
| 1997 |
|
| 1998 |
-
The
|
| 1999 |
-
template `hash` ([[unord.hash]]).
|
| 2000 |
|
| 2001 |
### `bitset` operators <a id="bitset.operators">[[bitset.operators]]</a>
|
| 2002 |
|
| 2003 |
``` cpp
|
| 2004 |
bitset<N> operator&(const bitset<N>& lhs, const bitset<N>& rhs) noexcept;
|
|
@@ -2062,19 +5000,19 @@ os << x.template to_string<charT,traits,allocator<charT> >(
|
|
| 2062 |
## Memory <a id="memory">[[memory]]</a>
|
| 2063 |
|
| 2064 |
### In general <a id="memory.general">[[memory.general]]</a>
|
| 2065 |
|
| 2066 |
This subclause describes the contents of the header `<memory>` (
|
| 2067 |
-
[[memory.syn]]) and some of the contents of the
|
| 2068 |
-
|
| 2069 |
|
| 2070 |
### Header `<memory>` synopsis <a id="memory.syn">[[memory.syn]]</a>
|
| 2071 |
|
| 2072 |
The header `<memory>` defines several types and function templates that
|
| 2073 |
describe properties of pointers and pointer-like types, manage memory
|
| 2074 |
-
for containers and other template types,
|
| 2075 |
-
in uninitialized memory buffers ([[pointer.traits]]–
|
| 2076 |
[[specialized.algorithms]]). The header also defines the templates
|
| 2077 |
`unique_ptr`, `shared_ptr`, `weak_ptr`, and various function templates
|
| 2078 |
that operate on objects of these types ([[smartptr]]).
|
| 2079 |
|
| 2080 |
``` cpp
|
|
@@ -2090,55 +5028,106 @@ namespace std {
|
|
| 2090 |
void declare_no_pointers(char* p, size_t n);
|
| 2091 |
void undeclare_no_pointers(char* p, size_t n);
|
| 2092 |
pointer_safety get_pointer_safety() noexcept;
|
| 2093 |
|
| 2094 |
// [ptr.align], pointer alignment function
|
| 2095 |
-
void* align(
|
| 2096 |
-
void*& ptr, std::size_t& space);
|
| 2097 |
|
| 2098 |
// [allocator.tag], allocator argument tag
|
| 2099 |
-
struct allocator_arg_t { };
|
| 2100 |
-
constexpr allocator_arg_t allocator_arg{};
|
| 2101 |
|
| 2102 |
// [allocator.uses], uses_allocator
|
| 2103 |
template <class T, class Alloc> struct uses_allocator;
|
| 2104 |
|
| 2105 |
// [allocator.traits], allocator traits
|
| 2106 |
template <class Alloc> struct allocator_traits;
|
| 2107 |
|
| 2108 |
-
// [default.allocator], the default allocator
|
| 2109 |
template <class T> class allocator;
|
| 2110 |
-
template <> class allocator<void>;
|
| 2111 |
template <class T, class U>
|
| 2112 |
bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
|
| 2113 |
template <class T, class U>
|
| 2114 |
bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
|
| 2115 |
|
| 2116 |
-
// [
|
| 2117 |
-
template <class
|
| 2118 |
-
|
| 2119 |
-
|
| 2120 |
-
|
| 2121 |
-
|
| 2122 |
-
|
| 2123 |
-
|
| 2124 |
-
|
| 2125 |
-
|
| 2126 |
-
template <class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2127 |
template <class InputIterator, class ForwardIterator>
|
| 2128 |
ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
|
| 2129 |
ForwardIterator result);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2130 |
template <class InputIterator, class Size, class ForwardIterator>
|
| 2131 |
ForwardIterator uninitialized_copy_n(InputIterator first, Size n,
|
| 2132 |
ForwardIterator result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2133 |
template <class ForwardIterator, class T>
|
| 2134 |
void uninitialized_fill(ForwardIterator first, ForwardIterator last,
|
| 2135 |
const T& x);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2136 |
template <class ForwardIterator, class Size, class T>
|
| 2137 |
ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2138 |
|
| 2139 |
-
// [unique.ptr] class template unique_ptr
|
| 2140 |
template <class T> struct default_delete;
|
| 2141 |
template <class T> struct default_delete<T[]>;
|
| 2142 |
template <class T, class D = default_delete<T>> class unique_ptr;
|
| 2143 |
template <class T, class D> class unique_ptr<T[], D>;
|
| 2144 |
|
|
@@ -2184,34 +5173,35 @@ namespace std {
|
|
| 2184 |
template <class T, class D>
|
| 2185 |
bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
|
| 2186 |
template <class T, class D>
|
| 2187 |
bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
|
| 2188 |
|
| 2189 |
-
// [util.smartptr.
|
| 2190 |
class bad_weak_ptr;
|
| 2191 |
|
| 2192 |
-
// [util.smartptr.shared], class template shared_ptr
|
| 2193 |
template<class T> class shared_ptr;
|
| 2194 |
|
| 2195 |
// [util.smartptr.shared.create], shared_ptr creation
|
| 2196 |
-
template<class T, class... Args>
|
|
|
|
| 2197 |
template<class T, class A, class... Args>
|
| 2198 |
shared_ptr<T> allocate_shared(const A& a, Args&&... args);
|
| 2199 |
|
| 2200 |
-
// [util.smartptr.shared.cmp], shared_ptr comparisons
|
| 2201 |
template<class T, class U>
|
| 2202 |
-
bool operator==(shared_ptr<T>
|
| 2203 |
template<class T, class U>
|
| 2204 |
-
bool operator!=(shared_ptr<T>
|
| 2205 |
template<class T, class U>
|
| 2206 |
-
bool operator<(shared_ptr<T>
|
| 2207 |
template<class T, class U>
|
| 2208 |
-
bool operator>(shared_ptr<T>
|
| 2209 |
template<class T, class U>
|
| 2210 |
-
bool operator<=(shared_ptr<T>
|
| 2211 |
template<class T, class U>
|
| 2212 |
-
bool operator>=(shared_ptr<T>
|
| 2213 |
|
| 2214 |
template <class T>
|
| 2215 |
bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
|
| 2216 |
template <class T>
|
| 2217 |
bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
|
|
@@ -2234,41 +5224,43 @@ namespace std {
|
|
| 2234 |
template <class T>
|
| 2235 |
bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
|
| 2236 |
template <class T>
|
| 2237 |
bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
|
| 2238 |
|
| 2239 |
-
// [util.smartptr.shared.spec], shared_ptr specialized algorithms
|
| 2240 |
-
template<class T>
|
|
|
|
| 2241 |
|
| 2242 |
-
// [util.smartptr.shared.cast], shared_ptr casts
|
| 2243 |
template<class T, class U>
|
| 2244 |
-
shared_ptr<T> static_pointer_cast(shared_ptr<U>
|
| 2245 |
template<class T, class U>
|
| 2246 |
-
shared_ptr<T> dynamic_pointer_cast(shared_ptr<U>
|
| 2247 |
template<class T, class U>
|
| 2248 |
-
shared_ptr<T> const_pointer_cast(shared_ptr<U>
|
| 2249 |
|
| 2250 |
-
// [util.smartptr.getdeleter], shared_ptr get_deleter
|
| 2251 |
-
template<class D, class T>
|
|
|
|
| 2252 |
|
| 2253 |
-
// [util.smartptr.shared.io], shared_ptr I/O
|
| 2254 |
template<class E, class T, class Y>
|
| 2255 |
-
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y>
|
| 2256 |
|
| 2257 |
-
// [util.smartptr.weak], class template weak_ptr
|
| 2258 |
template<class T> class weak_ptr;
|
| 2259 |
|
| 2260 |
-
// [util.smartptr.weak.spec], weak_ptr specialized algorithms
|
| 2261 |
template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
| 2262 |
|
| 2263 |
-
// [util.smartptr.ownerless], class template owner_less
|
| 2264 |
-
template<class T>
|
| 2265 |
|
| 2266 |
-
// [util.smartptr.enab], class template enable_shared_from_this
|
| 2267 |
template<class T> class enable_shared_from_this;
|
| 2268 |
|
| 2269 |
-
// [util.smartptr.shared.atomic], shared_ptr atomic access
|
| 2270 |
template<class T>
|
| 2271 |
bool atomic_is_lock_free(const shared_ptr<T>* p);
|
| 2272 |
|
| 2273 |
template<class T>
|
| 2274 |
shared_ptr<T> atomic_load(const shared_ptr<T>* p);
|
|
@@ -2281,12 +5273,11 @@ namespace std {
|
|
| 2281 |
void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
|
| 2282 |
|
| 2283 |
template<class T>
|
| 2284 |
shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
|
| 2285 |
template<class T>
|
| 2286 |
-
shared_ptr<T> atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r,
|
| 2287 |
-
memory_order mo);
|
| 2288 |
|
| 2289 |
template<class T>
|
| 2290 |
bool atomic_compare_exchange_weak(
|
| 2291 |
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
|
| 2292 |
template<class T>
|
|
@@ -2299,17 +5290,18 @@ namespace std {
|
|
| 2299 |
template<class T>
|
| 2300 |
bool atomic_compare_exchange_strong_explicit(
|
| 2301 |
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
|
| 2302 |
memory_order success, memory_order failure);
|
| 2303 |
|
| 2304 |
-
// [util.smartptr.hash] hash support
|
| 2305 |
template <class T> struct hash;
|
| 2306 |
template <class T, class D> struct hash<unique_ptr<T, D>>;
|
| 2307 |
template <class T> struct hash<shared_ptr<T>>;
|
| 2308 |
|
| 2309 |
-
// [
|
| 2310 |
-
template <class
|
|
|
|
| 2311 |
}
|
| 2312 |
```
|
| 2313 |
|
| 2314 |
### Pointer traits <a id="pointer.traits">[[pointer.traits]]</a>
|
| 2315 |
|
|
@@ -2317,23 +5309,23 @@ The class template `pointer_traits` supplies a uniform interface to
|
|
| 2317 |
certain attributes of pointer-like types.
|
| 2318 |
|
| 2319 |
``` cpp
|
| 2320 |
namespace std {
|
| 2321 |
template <class Ptr> struct pointer_traits {
|
| 2322 |
-
|
| 2323 |
-
|
| 2324 |
-
|
| 2325 |
|
| 2326 |
template <class U> using rebind = see below;
|
| 2327 |
|
| 2328 |
static pointer pointer_to(see below r);
|
| 2329 |
};
|
| 2330 |
|
| 2331 |
template <class T> struct pointer_traits<T*> {
|
| 2332 |
-
|
| 2333 |
-
|
| 2334 |
-
|
| 2335 |
|
| 2336 |
template <class U> using rebind = U*;
|
| 2337 |
|
| 2338 |
static pointer pointer_to(see below r) noexcept;
|
| 2339 |
};
|
|
@@ -2341,49 +5333,53 @@ namespace std {
|
|
| 2341 |
```
|
| 2342 |
|
| 2343 |
#### Pointer traits member types <a id="pointer.traits.types">[[pointer.traits.types]]</a>
|
| 2344 |
|
| 2345 |
``` cpp
|
| 2346 |
-
|
| 2347 |
```
|
| 2348 |
|
| 2349 |
-
*Type:* `Ptr::element_type` if
|
| 2350 |
-
|
| 2351 |
-
`SomePointer<T, Args>`, where
|
| 2352 |
-
otherwise, the specialization is
|
|
|
|
| 2353 |
|
| 2354 |
``` cpp
|
| 2355 |
-
|
| 2356 |
```
|
| 2357 |
|
| 2358 |
-
*Type:* `Ptr::difference_type` if
|
| 2359 |
-
`
|
|
|
|
| 2360 |
|
| 2361 |
``` cpp
|
| 2362 |
template <class U> using rebind = see below;
|
| 2363 |
```
|
| 2364 |
|
| 2365 |
-
*Alias template:* `Ptr::rebind<U>` if
|
| 2366 |
-
`
|
| 2367 |
-
|
| 2368 |
-
|
|
|
|
|
|
|
| 2369 |
|
| 2370 |
#### Pointer traits member functions <a id="pointer.traits.functions">[[pointer.traits.functions]]</a>
|
| 2371 |
|
| 2372 |
``` cpp
|
| 2373 |
static pointer pointer_traits::pointer_to(see below r);
|
| 2374 |
static pointer pointer_traits<T*>::pointer_to(see below r) noexcept;
|
| 2375 |
```
|
| 2376 |
|
| 2377 |
-
If `element_type` is
|
| 2378 |
unspecified; otherwise, it is `element_type&`.
|
| 2379 |
|
| 2380 |
*Returns:* The first member function returns a pointer to `r` obtained
|
| 2381 |
by calling `Ptr::pointer_to(r)` through which indirection is valid; an
|
| 2382 |
instantiation of this function is ill-formed if `Ptr` does not have a
|
| 2383 |
matching `pointer_to` static member function. The second member function
|
| 2384 |
-
returns `
|
| 2385 |
|
| 2386 |
### Pointer safety <a id="util.dynamic.safety">[[util.dynamic.safety]]</a>
|
| 2387 |
|
| 2388 |
A complete object is *declared reachable* while the number of calls to
|
| 2389 |
`declare_reachable` with an argument referencing the object exceeds the
|
|
@@ -2398,13 +5394,12 @@ void declare_reachable(void* p);
|
|
| 2398 |
pointer ([[basic.stc.dynamic.safety]]) or a null pointer value.
|
| 2399 |
|
| 2400 |
*Effects:* If `p` is not null, the complete object referenced by `p` is
|
| 2401 |
subsequently declared reachable ([[basic.stc.dynamic.safety]]).
|
| 2402 |
|
| 2403 |
-
*Throws:* May throw `
|
| 2404 |
-
|
| 2405 |
-
reachable.
|
| 2406 |
|
| 2407 |
``` cpp
|
| 2408 |
template <class T> T* undeclare_reachable(T* p);
|
| 2409 |
```
|
| 2410 |
|
|
@@ -2416,38 +5411,43 @@ live ([[basic.life]]) from the time of the call until the last
|
|
| 2416 |
*Returns:* A safely derived copy of `p` which shall compare equal to
|
| 2417 |
`p`.
|
| 2418 |
|
| 2419 |
*Throws:* Nothing.
|
| 2420 |
|
| 2421 |
-
It is expected that calls to `declare_reachable(p)` will
|
| 2422 |
-
amount of memory in addition to that occupied by the
|
| 2423 |
-
until the matching call to `undeclare_reachable(p)` is
|
| 2424 |
-
running programs should arrange that calls are
|
|
|
|
| 2425 |
|
| 2426 |
``` cpp
|
| 2427 |
void declare_no_pointers(char* p, size_t n);
|
| 2428 |
```
|
| 2429 |
|
| 2430 |
*Requires:* No bytes in the specified range are currently registered
|
| 2431 |
with `declare_no_pointers()`. If the specified range is in an allocated
|
| 2432 |
object, then it must be entirely within a single allocated object. The
|
| 2433 |
object must be live until the corresponding `undeclare_no_pointers()`
|
| 2434 |
-
call.
|
| 2435 |
-
|
| 2436 |
-
|
|
|
|
|
|
|
| 2437 |
|
| 2438 |
*Effects:* The `n` bytes starting at `p` no longer contain traceable
|
| 2439 |
pointer locations, independent of their type. Hence indirection through
|
| 2440 |
a pointer located there is undefined if the object it points to was
|
| 2441 |
created by global `operator new` and not previously declared reachable.
|
| 2442 |
-
|
| 2443 |
-
|
|
|
|
| 2444 |
|
| 2445 |
*Throws:* Nothing.
|
| 2446 |
|
| 2447 |
-
Under some conditions implementations may need to allocate
|
| 2448 |
-
However, the request can be ignored if memory allocation
|
|
|
|
| 2449 |
|
| 2450 |
``` cpp
|
| 2451 |
void undeclare_no_pointers(char* p, size_t n);
|
| 2452 |
```
|
| 2453 |
|
|
@@ -2463,47 +5463,46 @@ ends.
|
|
| 2463 |
``` cpp
|
| 2464 |
pointer_safety get_pointer_safety() noexcept;
|
| 2465 |
```
|
| 2466 |
|
| 2467 |
*Returns:* `pointer_safety::strict` if the implementation has strict
|
| 2468 |
-
pointer safety ([[basic.stc.dynamic.safety]]). It is
|
| 2469 |
-
defined whether `get_pointer_safety` returns
|
| 2470 |
-
or `pointer_safety::preferred` if the
|
| 2471 |
-
safety.[^1]
|
| 2472 |
|
| 2473 |
### Align <a id="ptr.align">[[ptr.align]]</a>
|
| 2474 |
|
| 2475 |
``` cpp
|
| 2476 |
-
void* align(
|
| 2477 |
-
void*& ptr, std::size_t& space);
|
| 2478 |
```
|
| 2479 |
|
| 2480 |
*Effects:* If it is possible to fit `size` bytes of storage aligned by
|
| 2481 |
`alignment` into the buffer pointed to by `ptr` with length `space`, the
|
| 2482 |
-
function updates `ptr` to
|
| 2483 |
storage and decreases `space` by the number of bytes used for alignment.
|
| 2484 |
Otherwise, the function does nothing.
|
| 2485 |
|
| 2486 |
*Requires:*
|
| 2487 |
|
| 2488 |
-
- `alignment` shall be a
|
| 2489 |
-
|
| 2490 |
-
|
| 2491 |
|
| 2492 |
*Returns:* A null pointer if the requested aligned buffer would not fit
|
| 2493 |
into the available space, otherwise the adjusted value of `ptr`.
|
| 2494 |
|
| 2495 |
-
The function updates its `ptr` and `space` arguments so that
|
| 2496 |
-
called repeatedly with possibly different `alignment` and
|
| 2497 |
-
arguments for the same buffer.
|
| 2498 |
|
| 2499 |
### Allocator argument tag <a id="allocator.tag">[[allocator.tag]]</a>
|
| 2500 |
|
| 2501 |
``` cpp
|
| 2502 |
namespace std {
|
| 2503 |
-
struct allocator_arg_t { };
|
| 2504 |
-
constexpr allocator_arg_t allocator_arg{};
|
| 2505 |
}
|
| 2506 |
```
|
| 2507 |
|
| 2508 |
The `allocator_arg_t` struct is an empty structure type used as a unique
|
| 2509 |
type to disambiguate constructor and function overloading. Specifically,
|
|
@@ -2518,74 +5517,77 @@ argument of a type that satisfies the `Allocator` requirements (
|
|
| 2518 |
|
| 2519 |
``` cpp
|
| 2520 |
template <class T, class Alloc> struct uses_allocator;
|
| 2521 |
```
|
| 2522 |
|
| 2523 |
-
|
| 2524 |
-
convertible from `Alloc`. Meets the
|
| 2525 |
-
requirements ([[meta.rqmts]]). The implementation
|
| 2526 |
-
definition that is derived from `true_type` if
|
| 2527 |
-
`T::allocator_type`
|
| 2528 |
-
|
|
|
|
| 2529 |
shall be derived from `false_type`. A program may specialize this
|
| 2530 |
template to derive from `true_type` for a user-defined type `T` that
|
| 2531 |
does not have a nested `allocator_type` but nonetheless can be
|
| 2532 |
constructed with an allocator where either:
|
| 2533 |
|
| 2534 |
- the first argument of a constructor has type `allocator_arg_t` and the
|
| 2535 |
second argument has type `Alloc` or
|
| 2536 |
- the last argument of a constructor has type `Alloc`.
|
| 2537 |
|
| 2538 |
-
####
|
| 2539 |
|
| 2540 |
*Uses-allocator construction* with allocator `Alloc` refers to the
|
| 2541 |
construction of an object `obj` of type `T`, using constructor arguments
|
| 2542 |
`v1, v2, ..., vN` of types `V1, V2, ..., VN`, respectively, and an
|
| 2543 |
allocator `alloc` of type `Alloc`, according to the following rules:
|
| 2544 |
|
| 2545 |
-
- if `
|
| 2546 |
-
`
|
| 2547 |
initialized as `obj(v1, v2, ..., vN)`;
|
| 2548 |
-
- otherwise, if `
|
| 2549 |
-
`
|
| 2550 |
-
`
|
| 2551 |
-
`obj(allocator_arg, alloc, v1,
|
| 2552 |
v2, ..., vN)`;
|
| 2553 |
-
- otherwise, if `
|
| 2554 |
-
`
|
| 2555 |
-
|
| 2556 |
- otherwise, the request for uses-allocator construction is ill-formed.
|
| 2557 |
-
An error will result if `
|
| 2558 |
-
but the specific constructor does not take an allocator. This
|
| 2559 |
definition prevents a silent failure to pass the allocator to an
|
| 2560 |
-
element.
|
| 2561 |
|
| 2562 |
### Allocator traits <a id="allocator.traits">[[allocator.traits]]</a>
|
| 2563 |
|
| 2564 |
The class template `allocator_traits` supplies a uniform interface to
|
| 2565 |
all allocator types. An allocator cannot be a non-class type, however,
|
| 2566 |
-
even if `allocator_traits` supplies the entire required interface.
|
| 2567 |
-
|
|
|
|
|
|
|
| 2568 |
|
| 2569 |
``` cpp
|
| 2570 |
namespace std {
|
| 2571 |
template <class Alloc> struct allocator_traits {
|
| 2572 |
-
|
| 2573 |
|
| 2574 |
-
|
| 2575 |
|
| 2576 |
-
|
| 2577 |
-
|
| 2578 |
-
|
| 2579 |
-
|
| 2580 |
|
| 2581 |
-
|
| 2582 |
-
|
| 2583 |
|
| 2584 |
-
|
| 2585 |
-
|
| 2586 |
-
|
|
|
|
| 2587 |
|
| 2588 |
template <class T> using rebind_alloc = see below;
|
| 2589 |
template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
|
| 2590 |
|
| 2591 |
static pointer allocate(Alloc& a, size_type n);
|
|
@@ -2607,80 +5609,99 @@ namespace std {
|
|
| 2607 |
```
|
| 2608 |
|
| 2609 |
#### Allocator traits member types <a id="allocator.traits.types">[[allocator.traits.types]]</a>
|
| 2610 |
|
| 2611 |
``` cpp
|
| 2612 |
-
|
| 2613 |
```
|
| 2614 |
|
| 2615 |
-
*Type:* `Alloc::pointer` if
|
| 2616 |
-
`value_type*`.
|
| 2617 |
|
| 2618 |
``` cpp
|
| 2619 |
-
|
| 2620 |
```
|
| 2621 |
|
| 2622 |
-
*Type:* `Alloc::const_pointer` if
|
| 2623 |
-
`
|
|
|
|
| 2624 |
|
| 2625 |
``` cpp
|
| 2626 |
-
|
| 2627 |
```
|
| 2628 |
|
| 2629 |
-
*Type:* `Alloc::void_pointer` if
|
| 2630 |
-
`
|
|
|
|
| 2631 |
|
| 2632 |
``` cpp
|
| 2633 |
-
|
| 2634 |
```
|
| 2635 |
|
| 2636 |
-
*Type:* `Alloc::const_void_pointer` if
|
|
|
|
|
|
|
| 2637 |
`pointer_traits<pointer>::rebind<const void>`.
|
| 2638 |
|
| 2639 |
``` cpp
|
| 2640 |
-
|
| 2641 |
```
|
| 2642 |
|
| 2643 |
-
*Type:* `Alloc::difference_type` if
|
| 2644 |
-
`
|
|
|
|
| 2645 |
|
| 2646 |
``` cpp
|
| 2647 |
-
|
| 2648 |
```
|
| 2649 |
|
| 2650 |
-
*Type:* `Alloc::size_type` if
|
|
|
|
| 2651 |
`make_unsigned_t<difference_type>`.
|
| 2652 |
|
| 2653 |
``` cpp
|
| 2654 |
-
|
| 2655 |
```
|
| 2656 |
|
| 2657 |
-
*Type:* `Alloc::propagate_on_container_copy_assignment` if
|
| 2658 |
-
|
|
|
|
| 2659 |
|
| 2660 |
``` cpp
|
| 2661 |
-
|
| 2662 |
```
|
| 2663 |
|
| 2664 |
-
*Type:* `Alloc::propagate_on_container_move_assignment` if
|
| 2665 |
-
|
|
|
|
| 2666 |
|
| 2667 |
``` cpp
|
| 2668 |
-
|
| 2669 |
```
|
| 2670 |
|
| 2671 |
-
*Type:* `Alloc::propagate_on_container_swap` if
|
| 2672 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2673 |
|
| 2674 |
``` cpp
|
| 2675 |
template <class T> using rebind_alloc = see below;
|
| 2676 |
```
|
| 2677 |
|
| 2678 |
-
*Alias template:* `Alloc::rebind<T>::other` if
|
| 2679 |
-
|
| 2680 |
-
|
| 2681 |
-
|
|
|
|
|
|
|
| 2682 |
|
| 2683 |
#### Allocator traits static member functions <a id="allocator.traits.members">[[allocator.traits.members]]</a>
|
| 2684 |
|
| 2685 |
``` cpp
|
| 2686 |
static pointer allocate(Alloc& a, size_type n);
|
|
@@ -2697,90 +5718,65 @@ otherwise, `a.allocate(n)`.
|
|
| 2697 |
|
| 2698 |
``` cpp
|
| 2699 |
static void deallocate(Alloc& a, pointer p, size_type n);
|
| 2700 |
```
|
| 2701 |
|
| 2702 |
-
*Effects:*
|
| 2703 |
|
| 2704 |
*Throws:* Nothing.
|
| 2705 |
|
| 2706 |
``` cpp
|
| 2707 |
template <class T, class... Args>
|
| 2708 |
static void construct(Alloc& a, T* p, Args&&... args);
|
| 2709 |
```
|
| 2710 |
|
| 2711 |
-
*Effects:*
|
| 2712 |
call is well-formed; otherwise, invokes
|
| 2713 |
`::new (static_cast<void*>(p)) T(std::forward<Args>(args)...)`.
|
| 2714 |
|
| 2715 |
``` cpp
|
| 2716 |
template <class T>
|
| 2717 |
static void destroy(Alloc& a, T* p);
|
| 2718 |
```
|
| 2719 |
|
| 2720 |
-
*Effects:*
|
| 2721 |
invokes `p->~T()`.
|
| 2722 |
|
| 2723 |
``` cpp
|
| 2724 |
static size_type max_size(const Alloc& a) noexcept;
|
| 2725 |
```
|
| 2726 |
|
| 2727 |
*Returns:* `a.max_size()` if that expression is well-formed; otherwise,
|
| 2728 |
-
`numeric_limits<size_type>::max()`.
|
| 2729 |
|
| 2730 |
``` cpp
|
| 2731 |
static Alloc select_on_container_copy_construction(const Alloc& rhs);
|
| 2732 |
```
|
| 2733 |
|
| 2734 |
*Returns:* `rhs.select_on_container_copy_construction()` if that
|
| 2735 |
expression is well-formed; otherwise, `rhs`.
|
| 2736 |
|
| 2737 |
### The default allocator <a id="default.allocator">[[default.allocator]]</a>
|
| 2738 |
|
|
|
|
|
|
|
|
|
|
| 2739 |
``` cpp
|
| 2740 |
namespace std {
|
| 2741 |
-
template <class T> class allocator;
|
| 2742 |
-
|
| 2743 |
-
// specialize for void:
|
| 2744 |
-
template <> class allocator<void> {
|
| 2745 |
-
public:
|
| 2746 |
-
typedef void* pointer;
|
| 2747 |
-
typedef const void* const_pointer;
|
| 2748 |
-
// reference-to-void members are impossible.
|
| 2749 |
-
typedef void value_type;
|
| 2750 |
-
template <class U> struct rebind { typedef allocator<U> other; };
|
| 2751 |
-
};
|
| 2752 |
-
|
| 2753 |
template <class T> class allocator {
|
| 2754 |
public:
|
| 2755 |
-
|
| 2756 |
-
|
| 2757 |
-
|
| 2758 |
-
typedef const T* const_pointer;
|
| 2759 |
-
typedef T& reference;
|
| 2760 |
-
typedef const T& const_reference;
|
| 2761 |
-
typedef T value_type;
|
| 2762 |
-
template <class U> struct rebind { typedef allocator<U> other; };
|
| 2763 |
-
typedef true_type propagate_on_container_move_assignment;
|
| 2764 |
|
| 2765 |
allocator() noexcept;
|
| 2766 |
allocator(const allocator&) noexcept;
|
| 2767 |
template <class U> allocator(const allocator<U>&) noexcept;
|
| 2768 |
~allocator();
|
| 2769 |
|
| 2770 |
-
|
| 2771 |
-
|
| 2772 |
-
|
| 2773 |
-
pointer allocate(
|
| 2774 |
-
size_type, allocator<void>::const_pointer hint = 0);
|
| 2775 |
-
void deallocate(pointer p, size_type n);
|
| 2776 |
-
size_type max_size() const noexcept;
|
| 2777 |
-
|
| 2778 |
-
template<class U, class... Args>
|
| 2779 |
-
void construct(U* p, Args&&... args);
|
| 2780 |
-
template <class U>
|
| 2781 |
-
void destroy(U* p);
|
| 2782 |
};
|
| 2783 |
}
|
| 2784 |
```
|
| 2785 |
|
| 2786 |
#### `allocator` members <a id="allocator.members">[[allocator.members]]</a>
|
|
@@ -2791,304 +5787,326 @@ concurrent calls to those member functions from different threads. Calls
|
|
| 2791 |
to these functions that allocate or deallocate a particular unit of
|
| 2792 |
storage shall occur in a single total order, and each such deallocation
|
| 2793 |
call shall happen before the next allocation (if any) in this order.
|
| 2794 |
|
| 2795 |
``` cpp
|
| 2796 |
-
|
| 2797 |
```
|
| 2798 |
|
| 2799 |
-
*Returns:* The actual address of the object referenced by `x`, even in
|
| 2800 |
-
the presence of an overloaded operator&.
|
| 2801 |
-
|
| 2802 |
-
``` cpp
|
| 2803 |
-
const_pointer address(const_reference x) const noexcept;
|
| 2804 |
-
```
|
| 2805 |
-
|
| 2806 |
-
*Returns:* The actual address of the object referenced by `x`, even in
|
| 2807 |
-
the presence of an overloaded operator&.
|
| 2808 |
-
|
| 2809 |
-
``` cpp
|
| 2810 |
-
pointer allocate(size_type n, allocator<void>::const_pointer hint = 0);
|
| 2811 |
-
```
|
| 2812 |
-
|
| 2813 |
-
In a container member function, the address of an adjacent element is
|
| 2814 |
-
often a good choice to pass for the `hint` argument.
|
| 2815 |
-
|
| 2816 |
*Returns:* A pointer to the initial element of an array of storage of
|
| 2817 |
size `n` `* sizeof(T)`, aligned appropriately for objects of type `T`.
|
| 2818 |
-
It is *implementation-defined* whether over-aligned types are
|
| 2819 |
-
supported ([[basic.align]]).
|
| 2820 |
|
| 2821 |
-
the storage is obtained by calling
|
| 2822 |
-
`::operator new
|
| 2823 |
-
|
| 2824 |
-
unspecified, but intended as an aid to locality if an implementation so
|
| 2825 |
-
desires.
|
| 2826 |
|
| 2827 |
*Throws:* `bad_alloc` if the storage cannot be obtained.
|
| 2828 |
|
| 2829 |
``` cpp
|
| 2830 |
-
void deallocate(
|
| 2831 |
```
|
| 2832 |
|
| 2833 |
*Requires:* `p` shall be a pointer value obtained from `allocate()`. `n`
|
| 2834 |
shall equal the value passed as the first argument to the invocation of
|
| 2835 |
allocate which returned `p`.
|
| 2836 |
|
| 2837 |
*Effects:* Deallocates the storage referenced by `p` .
|
| 2838 |
|
| 2839 |
-
*Remarks:* Uses
|
| 2840 |
-
`::operator delete(void*, std::size_t)` ([[new.delete]]), but it is
|
| 2841 |
unspecified when this function is called.
|
| 2842 |
|
| 2843 |
-
``` cpp
|
| 2844 |
-
size_type max_size() const noexcept;
|
| 2845 |
-
```
|
| 2846 |
-
|
| 2847 |
-
*Returns:* The largest value *N* for which the call `allocate(N,0)`
|
| 2848 |
-
might succeed.
|
| 2849 |
-
|
| 2850 |
-
``` cpp
|
| 2851 |
-
template <class U, class... Args>
|
| 2852 |
-
void construct(U* p, Args&&... args);
|
| 2853 |
-
```
|
| 2854 |
-
|
| 2855 |
-
*Effects:* `::new((void *)p) U(std::forward<Args>(args)...)`
|
| 2856 |
-
|
| 2857 |
-
``` cpp
|
| 2858 |
-
template <class U>
|
| 2859 |
-
void destroy(U* p);
|
| 2860 |
-
```
|
| 2861 |
-
|
| 2862 |
-
*Effects:* `p->~U()`
|
| 2863 |
-
|
| 2864 |
#### `allocator` globals <a id="allocator.globals">[[allocator.globals]]</a>
|
| 2865 |
|
| 2866 |
``` cpp
|
| 2867 |
-
template <class
|
| 2868 |
-
bool operator==(const allocator<
|
| 2869 |
```
|
| 2870 |
|
| 2871 |
*Returns:* `true`.
|
| 2872 |
|
| 2873 |
``` cpp
|
| 2874 |
-
template <class
|
| 2875 |
-
bool operator!=(const allocator<
|
| 2876 |
```
|
| 2877 |
|
| 2878 |
*Returns:* `false`.
|
| 2879 |
|
| 2880 |
-
### Raw storage iterator <a id="storage.iterator">[[storage.iterator]]</a>
|
| 2881 |
-
|
| 2882 |
-
`raw_storage_iterator` is provided to enable algorithms to store their
|
| 2883 |
-
results into uninitialized memory. The template parameter
|
| 2884 |
-
`OutputIterator` is required to have its `operator*` return an object
|
| 2885 |
-
for which `operator&` is defined and returns a pointer to `T`, and is
|
| 2886 |
-
also required to satisfy the requirements of an output iterator (
|
| 2887 |
-
[[output.iterators]]).
|
| 2888 |
-
|
| 2889 |
-
``` cpp
|
| 2890 |
-
namespace std {
|
| 2891 |
-
template <class OutputIterator, class T>
|
| 2892 |
-
class raw_storage_iterator
|
| 2893 |
-
: public iterator<output_iterator_tag,void,void,void,void> {
|
| 2894 |
-
public:
|
| 2895 |
-
explicit raw_storage_iterator(OutputIterator x);
|
| 2896 |
-
|
| 2897 |
-
raw_storage_iterator& operator*();
|
| 2898 |
-
raw_storage_iterator& operator=(const T& element);
|
| 2899 |
-
raw_storage_iterator& operator++();
|
| 2900 |
-
raw_storage_iterator operator++(int);
|
| 2901 |
-
};
|
| 2902 |
-
}
|
| 2903 |
-
```
|
| 2904 |
-
|
| 2905 |
-
``` cpp
|
| 2906 |
-
explicit raw_storage_iterator(OutputIterator x);
|
| 2907 |
-
```
|
| 2908 |
-
|
| 2909 |
-
*Effects:* Initializes the iterator to point to the same value to which
|
| 2910 |
-
`x` points.
|
| 2911 |
-
|
| 2912 |
-
``` cpp
|
| 2913 |
-
raw_storage_iterator& operator*();
|
| 2914 |
-
```
|
| 2915 |
-
|
| 2916 |
-
*Returns:* `*this`
|
| 2917 |
-
|
| 2918 |
-
``` cpp
|
| 2919 |
-
raw_storage_iterator& operator=(const T& element);
|
| 2920 |
-
```
|
| 2921 |
-
|
| 2922 |
-
*Effects:* Constructs a value from `element` at the location to which
|
| 2923 |
-
the iterator points.
|
| 2924 |
-
|
| 2925 |
-
*Returns:* A reference to the iterator.
|
| 2926 |
-
|
| 2927 |
-
``` cpp
|
| 2928 |
-
raw_storage_iterator& operator++();
|
| 2929 |
-
```
|
| 2930 |
-
|
| 2931 |
-
*Effects:* Pre-increment: advances the iterator and returns a reference
|
| 2932 |
-
to the updated iterator.
|
| 2933 |
-
|
| 2934 |
-
``` cpp
|
| 2935 |
-
raw_storage_iterator operator++(int);
|
| 2936 |
-
```
|
| 2937 |
-
|
| 2938 |
-
*Effects:* Post-increment: advances the iterator and returns the old
|
| 2939 |
-
value of the iterator.
|
| 2940 |
-
|
| 2941 |
-
### Temporary buffers <a id="temporary.buffer">[[temporary.buffer]]</a>
|
| 2942 |
-
|
| 2943 |
-
``` cpp
|
| 2944 |
-
template <class T>
|
| 2945 |
-
pair<T*, ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
|
| 2946 |
-
```
|
| 2947 |
-
|
| 2948 |
-
*Effects:* Obtains a pointer to storage sufficient to store up to `n`
|
| 2949 |
-
adjacent `T` objects. It is *implementation-defined* whether
|
| 2950 |
-
over-aligned types are supported ([[basic.align]]).
|
| 2951 |
-
|
| 2952 |
-
*Returns:* A `pair` containing the buffer’s address and capacity (in the
|
| 2953 |
-
units of `sizeof(T)`), or a pair of 0 values if no storage can be
|
| 2954 |
-
obtained or if `n <= 0`.
|
| 2955 |
-
|
| 2956 |
-
``` cpp
|
| 2957 |
-
template <class T> void return_temporary_buffer(T* p);
|
| 2958 |
-
```
|
| 2959 |
-
|
| 2960 |
-
*Effects:* Deallocates the buffer to which `p` points.
|
| 2961 |
-
|
| 2962 |
-
*Requires:* The buffer shall have been previously allocated by
|
| 2963 |
-
`get_temporary_buffer`.
|
| 2964 |
-
|
| 2965 |
### Specialized algorithms <a id="specialized.algorithms">[[specialized.algorithms]]</a>
|
| 2966 |
|
| 2967 |
-
|
| 2968 |
-
|
| 2969 |
-
|
| 2970 |
-
|
| 2971 |
-
|
| 2972 |
-
[[input.iterators]]).
|
| 2973 |
-
|
| 2974 |
-
|
|
|
|
| 2975 |
property that no exceptions are thrown from increment, assignment,
|
| 2976 |
-
comparison, or indirection through valid iterators.
|
| 2977 |
-
|
|
|
|
|
|
|
| 2978 |
|
| 2979 |
#### `addressof` <a id="specialized.addressof">[[specialized.addressof]]</a>
|
| 2980 |
|
| 2981 |
``` cpp
|
| 2982 |
-
template <class T> T* addressof(T& r) noexcept;
|
| 2983 |
```
|
| 2984 |
|
| 2985 |
*Returns:* The actual address of the object or function referenced by
|
| 2986 |
`r`, even in the presence of an overloaded `operator&`.
|
| 2987 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2988 |
#### `uninitialized_copy` <a id="uninitialized.copy">[[uninitialized.copy]]</a>
|
| 2989 |
|
| 2990 |
``` cpp
|
| 2991 |
template <class InputIterator, class ForwardIterator>
|
| 2992 |
ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
|
| 2993 |
ForwardIterator result);
|
| 2994 |
```
|
| 2995 |
|
| 2996 |
-
*Effects:*
|
| 2997 |
|
| 2998 |
``` cpp
|
| 2999 |
-
for (; first != last; ++result, ++first)
|
| 3000 |
-
::new (static_cast<void*>(
|
| 3001 |
typename iterator_traits<ForwardIterator>::value_type(*first);
|
| 3002 |
```
|
| 3003 |
|
| 3004 |
-
*Returns:* `result`
|
| 3005 |
|
| 3006 |
``` cpp
|
| 3007 |
template <class InputIterator, class Size, class ForwardIterator>
|
| 3008 |
ForwardIterator uninitialized_copy_n(InputIterator first, Size n,
|
| 3009 |
ForwardIterator result);
|
| 3010 |
```
|
| 3011 |
|
| 3012 |
-
*Effects:*
|
| 3013 |
|
| 3014 |
``` cpp
|
| 3015 |
-
for ( ; n > 0; ++result, ++first, --n) {
|
| 3016 |
-
::new (static_cast<void*>(
|
| 3017 |
typename iterator_traits<ForwardIterator>::value_type(*first);
|
| 3018 |
}
|
| 3019 |
```
|
| 3020 |
|
| 3021 |
-
*Returns:* `result`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3022 |
|
| 3023 |
#### `uninitialized_fill` <a id="uninitialized.fill">[[uninitialized.fill]]</a>
|
| 3024 |
|
| 3025 |
``` cpp
|
| 3026 |
template <class ForwardIterator, class T>
|
| 3027 |
void uninitialized_fill(ForwardIterator first, ForwardIterator last,
|
| 3028 |
const T& x);
|
| 3029 |
```
|
| 3030 |
|
| 3031 |
-
*Effects:*
|
| 3032 |
|
| 3033 |
``` cpp
|
| 3034 |
for (; first != last; ++first)
|
| 3035 |
-
::new (static_cast<void*>(
|
| 3036 |
typename iterator_traits<ForwardIterator>::value_type(x);
|
| 3037 |
```
|
| 3038 |
|
| 3039 |
-
#### `uninitialized_fill_n` <a id="uninitialized.fill.n">[[uninitialized.fill.n]]</a>
|
| 3040 |
-
|
| 3041 |
``` cpp
|
| 3042 |
template <class ForwardIterator, class Size, class T>
|
| 3043 |
ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
|
| 3044 |
```
|
| 3045 |
|
| 3046 |
-
*Effects:*
|
| 3047 |
|
| 3048 |
``` cpp
|
| 3049 |
for (; n--; ++first)
|
| 3050 |
-
::new (static_cast<void*>(
|
| 3051 |
typename iterator_traits<ForwardIterator>::value_type(x);
|
| 3052 |
return first;
|
| 3053 |
```
|
| 3054 |
|
| 3055 |
-
###
|
| 3056 |
|
| 3057 |
-
|
|
|
|
|
|
|
|
|
|
| 3058 |
|
| 3059 |
-
|
| 3060 |
-
with the following changes:
|
| 3061 |
|
| 3062 |
-
|
| 3063 |
-
|
|
|
|
| 3064 |
|
| 3065 |
-
|
| 3066 |
-
|
|
|
|
|
|
|
| 3067 |
|
| 3068 |
-
|
| 3069 |
|
| 3070 |
-
|
| 3071 |
-
|
| 3072 |
-
|
| 3073 |
-
|
| 3074 |
-
|
| 3075 |
-
|
| 3076 |
-
|
| 3077 |
-
|
| 3078 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3079 |
`declare_reachable()` implementation. The above functions should never
|
| 3080 |
intentionally be used as a replacement for `declare_reachable()`, and
|
| 3081 |
newly written code is strongly encouraged to treat memory allocated with
|
| 3082 |
-
these functions as though it were allocated with
|
|
|
|
| 3083 |
|
| 3084 |
-
|
|
|
|
|
|
|
| 3085 |
|
| 3086 |
-
|
| 3087 |
-
|
| 3088 |
|
| 3089 |
-
|
|
|
|
|
|
|
|
|
|
| 3090 |
|
| 3091 |
## Smart pointers <a id="smartptr">[[smartptr]]</a>
|
| 3092 |
|
| 3093 |
### Class template `unique_ptr` <a id="unique.ptr">[[unique.ptr]]</a>
|
| 3094 |
|
|
@@ -3117,24 +6135,26 @@ postconditions hold:
|
|
| 3117 |
- if the pre-transfer *u.d* maintained state, such state has been
|
| 3118 |
transferred to *u2.d*.
|
| 3119 |
|
| 3120 |
As in the case of a reset, *u2* must properly dispose of its
|
| 3121 |
pre-transfer owned object via the pre-transfer associated deleter before
|
| 3122 |
-
the ownership transfer is considered complete.
|
| 3123 |
-
|
|
|
|
|
|
|
| 3124 |
|
| 3125 |
Each object of a type `U` instantiated from the `unique_ptr` template
|
| 3126 |
specified in this subclause has the strict ownership semantics,
|
| 3127 |
specified above, of a unique pointer. In partial satisfaction of these
|
| 3128 |
semantics, each such `U` is `MoveConstructible` and `MoveAssignable`,
|
| 3129 |
but is not `CopyConstructible` nor `CopyAssignable`. The template
|
| 3130 |
parameter `T` of `unique_ptr` may be an incomplete type.
|
| 3131 |
|
| 3132 |
-
The uses of `unique_ptr` include providing exception safety
|
| 3133 |
-
dynamically allocated memory, passing ownership of dynamically
|
| 3134 |
-
memory to a function, and returning dynamically allocated
|
| 3135 |
-
function.
|
| 3136 |
|
| 3137 |
``` cpp
|
| 3138 |
namespace std {
|
| 3139 |
template<class T> struct default_delete;
|
| 3140 |
template<class T> struct default_delete<T[]>;
|
|
@@ -3223,56 +6243,65 @@ unless `U*` is implicitly convertible to `T*`.
|
|
| 3223 |
|
| 3224 |
``` cpp
|
| 3225 |
void operator()(T* ptr) const;
|
| 3226 |
```
|
| 3227 |
|
| 3228 |
-
*Effects:*
|
| 3229 |
|
| 3230 |
*Remarks:* If `T` is an incomplete type, the program is ill-formed.
|
| 3231 |
|
| 3232 |
##### `default_delete<T[]>` <a id="unique.ptr.dltr.dflt1">[[unique.ptr.dltr.dflt1]]</a>
|
| 3233 |
|
| 3234 |
``` cpp
|
| 3235 |
namespace std {
|
| 3236 |
template <class T> struct default_delete<T[]> {
|
| 3237 |
constexpr default_delete() noexcept = default;
|
| 3238 |
-
|
| 3239 |
-
template <class U> void operator()(U*) const
|
| 3240 |
};
|
| 3241 |
}
|
| 3242 |
```
|
| 3243 |
|
| 3244 |
``` cpp
|
| 3245 |
-
|
| 3246 |
```
|
| 3247 |
|
| 3248 |
-
*Effects:*
|
|
|
|
| 3249 |
|
| 3250 |
-
*Remarks:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3251 |
|
| 3252 |
#### `unique_ptr` for single objects <a id="unique.ptr.single">[[unique.ptr.single]]</a>
|
| 3253 |
|
| 3254 |
``` cpp
|
| 3255 |
namespace std {
|
| 3256 |
template <class T, class D = default_delete<T>> class unique_ptr {
|
| 3257 |
public:
|
| 3258 |
-
|
| 3259 |
-
|
| 3260 |
-
|
| 3261 |
|
| 3262 |
// [unique.ptr.single.ctor], constructors
|
| 3263 |
constexpr unique_ptr() noexcept;
|
| 3264 |
explicit unique_ptr(pointer p) noexcept;
|
| 3265 |
unique_ptr(pointer p, see below d1) noexcept;
|
| 3266 |
unique_ptr(pointer p, see below d2) noexcept;
|
| 3267 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 3268 |
-
constexpr unique_ptr(nullptr_t) noexcept
|
| 3269 |
-
: unique_ptr() { }
|
| 3270 |
template <class U, class E>
|
| 3271 |
unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
| 3272 |
-
template <class U>
|
| 3273 |
-
unique_ptr(auto_ptr<U>&& u) noexcept;
|
| 3274 |
|
| 3275 |
// [unique.ptr.single.dtor], destructor
|
| 3276 |
~unique_ptr();
|
| 3277 |
|
| 3278 |
// [unique.ptr.single.asgn], assignment
|
|
@@ -3286,11 +6315,11 @@ namespace std {
|
|
| 3286 |
pointer get() const noexcept;
|
| 3287 |
deleter_type& get_deleter() noexcept;
|
| 3288 |
const deleter_type& get_deleter() const noexcept;
|
| 3289 |
explicit operator bool() const noexcept;
|
| 3290 |
|
| 3291 |
-
// [unique.ptr.single.modifiers] modifiers
|
| 3292 |
pointer release() noexcept;
|
| 3293 |
void reset(pointer p = pointer()) noexcept;
|
| 3294 |
void swap(unique_ptr& u) noexcept;
|
| 3295 |
|
| 3296 |
// disable copy from lvalue
|
|
@@ -3300,149 +6329,148 @@ namespace std {
|
|
| 3300 |
}
|
| 3301 |
```
|
| 3302 |
|
| 3303 |
The default type for the template parameter `D` is `default_delete`. A
|
| 3304 |
client-supplied template argument `D` shall be a function object type (
|
| 3305 |
-
[[function.objects]]), lvalue
|
| 3306 |
to function object type for which, given a value `d` of type `D` and a
|
| 3307 |
value `ptr` of type `unique_ptr<T, D>::pointer`, the expression `d(ptr)`
|
| 3308 |
is valid and has the effect of disposing of the pointer as appropriate
|
| 3309 |
for that deleter.
|
| 3310 |
|
| 3311 |
If the deleter’s type `D` is not a reference type, `D` shall satisfy the
|
| 3312 |
-
requirements of `Destructible` (Table [[destructible]]).
|
| 3313 |
|
| 3314 |
-
If the
|
|
|
|
| 3315 |
D>::pointer` shall be a synonym for `remove_reference_t<D>::pointer`.
|
| 3316 |
-
Otherwise `unique_ptr<T, D>::pointer` shall be a synonym for
|
| 3317 |
-
type `unique_ptr<T,
|
| 3318 |
D>::pointer` shall satisfy the requirements of `NullablePointer` (
|
| 3319 |
[[nullablepointer.requirements]]).
|
| 3320 |
|
| 3321 |
-
Given an allocator type `X` ([[allocator.requirements]])
|
| 3322 |
-
`A` be a synonym for `allocator_traits<X>`, the types
|
| 3323 |
-
`A::
|
| 3324 |
-
be used as
|
|
|
|
| 3325 |
|
| 3326 |
##### `unique_ptr` constructors <a id="unique.ptr.single.ctor">[[unique.ptr.single.ctor]]</a>
|
| 3327 |
|
| 3328 |
``` cpp
|
| 3329 |
constexpr unique_ptr() noexcept;
|
|
|
|
| 3330 |
```
|
| 3331 |
|
| 3332 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 3333 |
-
(Table [[defaultconstructible]]), and that construction shall not
|
| 3334 |
-
an exception.
|
| 3335 |
|
| 3336 |
*Effects:* Constructs a `unique_ptr` object that owns nothing,
|
| 3337 |
value-initializing the stored pointer and the stored deleter.
|
| 3338 |
|
| 3339 |
*Postconditions:* `get() == nullptr`. `get_deleter()` returns a
|
| 3340 |
reference to the stored deleter.
|
| 3341 |
|
| 3342 |
-
*Remarks:* If
|
| 3343 |
-
|
|
|
|
| 3344 |
|
| 3345 |
``` cpp
|
| 3346 |
explicit unique_ptr(pointer p) noexcept;
|
| 3347 |
```
|
| 3348 |
|
| 3349 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 3350 |
-
(Table [[defaultconstructible]]), and that construction shall not
|
| 3351 |
-
an exception.
|
| 3352 |
|
| 3353 |
*Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
|
| 3354 |
stored pointer with `p` and value-initializing the stored deleter.
|
| 3355 |
|
| 3356 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 3357 |
the stored deleter.
|
| 3358 |
|
| 3359 |
-
*Remarks:* If
|
| 3360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3361 |
|
| 3362 |
``` cpp
|
| 3363 |
unique_ptr(pointer p, see below d1) noexcept;
|
| 3364 |
unique_ptr(pointer p, see below d2) noexcept;
|
| 3365 |
```
|
| 3366 |
|
| 3367 |
The signature of these constructors depends upon whether `D` is a
|
| 3368 |
-
reference type. If `D` is non-reference type `A`, then the signatures
|
| 3369 |
are:
|
| 3370 |
|
| 3371 |
``` cpp
|
| 3372 |
-
unique_ptr(pointer p, const A& d);
|
| 3373 |
-
unique_ptr(pointer p, A&& d);
|
| 3374 |
```
|
| 3375 |
|
| 3376 |
-
If `D` is an lvalue
|
| 3377 |
|
| 3378 |
``` cpp
|
| 3379 |
-
unique_ptr(pointer p, A& d);
|
| 3380 |
-
unique_ptr(pointer p, A&& d);
|
| 3381 |
```
|
| 3382 |
|
| 3383 |
-
If `D` is an lvalue
|
| 3384 |
|
| 3385 |
``` cpp
|
| 3386 |
-
unique_ptr(pointer p, const A& d);
|
| 3387 |
-
unique_ptr(pointer p, const A&& d);
|
| 3388 |
```
|
| 3389 |
|
| 3390 |
-
*Requires:*
|
| 3391 |
-
|
| 3392 |
-
- If `D` is not an lvalue-reference type then
|
| 3393 |
-
- If `d` is an lvalue or `const` rvalue then the first constructor of
|
| 3394 |
-
this pair will be selected. `D` shall satisfy the requirements of
|
| 3395 |
-
`CopyConstructible` (Table [[copyconstructible]]), and the copy
|
| 3396 |
-
constructor of `D` shall not throw an exception. This `unique_ptr`
|
| 3397 |
-
will hold a copy of `d`.
|
| 3398 |
-
- Otherwise, `d` is a non-const rvalue and the second constructor of
|
| 3399 |
-
this pair will be selected. `D` shall satisfy the requirements of
|
| 3400 |
-
`MoveConstructible` (Table [[moveconstructible]]), and the move
|
| 3401 |
-
constructor of `D` shall not throw an exception. This `unique_ptr`
|
| 3402 |
-
will hold a value move constructed from `d`.
|
| 3403 |
-
- Otherwise `D` is an lvalue-reference type. `d` shall be
|
| 3404 |
-
reference-compatible with one of the constructors. If `d` is an
|
| 3405 |
-
rvalue, it will bind to the second constructor of this pair and the
|
| 3406 |
-
program is ill-formed. The diagnostic could be implemented using a
|
| 3407 |
-
`static_assert` which assures that `D` is not a reference type. Else
|
| 3408 |
-
`d` is an lvalue and will bind to the first constructor of this pair.
|
| 3409 |
-
The type which `D` references need not be `CopyConstructible` nor
|
| 3410 |
-
`MoveConstructible`. This `unique_ptr` will hold a `D` which refers to
|
| 3411 |
-
the lvalue `d`. `D` may not be an rvalue-reference type.
|
| 3412 |
-
|
| 3413 |
*Effects:* Constructs a `unique_ptr` object which owns `p`, initializing
|
| 3414 |
-
the stored pointer with `p` and initializing the deleter
|
| 3415 |
-
|
|
|
|
|
|
|
|
|
|
| 3416 |
|
| 3417 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 3418 |
the stored deleter. If `D` is a reference type then `get_deleter()`
|
| 3419 |
returns a reference to the lvalue `d`.
|
| 3420 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3421 |
``` cpp
|
| 3422 |
D d;
|
| 3423 |
unique_ptr<int, D> p1(new int, D()); // D must be MoveConstructible
|
| 3424 |
unique_ptr<int, D> p2(new int, d); // D must be CopyConstructible
|
| 3425 |
unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d
|
| 3426 |
unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined
|
| 3427 |
// with reference deleter type
|
| 3428 |
```
|
| 3429 |
|
|
|
|
|
|
|
| 3430 |
``` cpp
|
| 3431 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 3432 |
```
|
| 3433 |
|
| 3434 |
*Requires:* If `D` is not a reference type, `D` shall satisfy the
|
| 3435 |
-
requirements of `MoveConstructible` (Table [[moveconstructible]]).
|
| 3436 |
Construction of the deleter from an rvalue of type `D` shall not throw
|
| 3437 |
an exception.
|
| 3438 |
|
| 3439 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 3440 |
to `*this`. If `D` is a reference type, this deleter is copy constructed
|
| 3441 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 3442 |
-
`u`’s deleter.
|
| 3443 |
-
|
|
|
|
|
|
|
| 3444 |
|
| 3445 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 3446 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 3447 |
that was constructed from `u.get_deleter()`. If `D` is a reference type
|
| 3448 |
then `get_deleter()` and `u.get_deleter()` both reference the same
|
|
@@ -3467,42 +6495,30 @@ unless:
|
|
| 3467 |
is not a reference type and `E` is implicitly convertible to `D`.
|
| 3468 |
|
| 3469 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 3470 |
to `*this`. If `E` is a reference type, this deleter is copy constructed
|
| 3471 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 3472 |
-
`u`’s deleter.
|
| 3473 |
-
|
|
|
|
|
|
|
| 3474 |
|
| 3475 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 3476 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 3477 |
that was constructed from `u.get_deleter()`.
|
| 3478 |
|
| 3479 |
-
``` cpp
|
| 3480 |
-
template <class U>
|
| 3481 |
-
unique_ptr(auto_ptr<U>&& u) noexcept;
|
| 3482 |
-
```
|
| 3483 |
-
|
| 3484 |
-
*Effects:* Constructs a `unique_ptr` object, initializing the stored
|
| 3485 |
-
pointer with `u.release()` and value-initializing the stored deleter.
|
| 3486 |
-
|
| 3487 |
-
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 3488 |
-
construction. `u.get() == nullptr`. `get_deleter()` returns a reference
|
| 3489 |
-
to the stored deleter.
|
| 3490 |
-
|
| 3491 |
-
*Remarks:* This constructor shall not participate in overload resolution
|
| 3492 |
-
unless `U*` is implicitly convertible to `T*` and `D` is the same type
|
| 3493 |
-
as `default_delete<T>`.
|
| 3494 |
-
|
| 3495 |
##### `unique_ptr` destructor <a id="unique.ptr.single.dtor">[[unique.ptr.single.dtor]]</a>
|
| 3496 |
|
| 3497 |
``` cpp
|
| 3498 |
~unique_ptr();
|
| 3499 |
```
|
| 3500 |
|
| 3501 |
*Requires:* The expression `get_deleter()(get())` shall be well formed,
|
| 3502 |
-
shall have well-defined behavior, and shall not throw exceptions.
|
| 3503 |
-
|
|
|
|
|
|
|
| 3504 |
|
| 3505 |
*Effects:* If `get() == nullptr` there are no effects. Otherwise
|
| 3506 |
`get_deleter()(get())`.
|
| 3507 |
|
| 3508 |
##### `unique_ptr` assignment <a id="unique.ptr.single.asgn">[[unique.ptr.single.asgn]]</a>
|
|
@@ -3510,11 +6526,11 @@ use of `default_delete` requires `T` to be a complete type.
|
|
| 3510 |
``` cpp
|
| 3511 |
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
| 3512 |
```
|
| 3513 |
|
| 3514 |
*Requires:* If `D` is not a reference type, `D` shall satisfy the
|
| 3515 |
-
requirements of `MoveAssignable` (Table [[moveassignable]]) and
|
| 3516 |
assignment of the deleter from an rvalue of type `D` shall not throw an
|
| 3517 |
exception. Otherwise, `D` is a reference type; `remove_reference_t<D>`
|
| 3518 |
shall satisfy the `CopyAssignable` requirements and assignment of the
|
| 3519 |
deleter from an lvalue of type `D` shall not throw an exception.
|
| 3520 |
|
|
@@ -3535,12 +6551,14 @@ deleter from an lvalue of type `E` shall be well-formed and shall not
|
|
| 3535 |
throw an exception.
|
| 3536 |
|
| 3537 |
*Remarks:* This operator shall not participate in overload resolution
|
| 3538 |
unless:
|
| 3539 |
|
| 3540 |
-
- `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`
|
| 3541 |
-
|
|
|
|
|
|
|
| 3542 |
|
| 3543 |
*Effects:* Transfers ownership from `u` to `*this` as if by calling
|
| 3544 |
`reset(u.release())` followed by
|
| 3545 |
`get_deleter() = std::forward<E>(u.get_deleter())`.
|
| 3546 |
|
|
@@ -3548,13 +6566,13 @@ unless:
|
|
| 3548 |
|
| 3549 |
``` cpp
|
| 3550 |
unique_ptr& operator=(nullptr_t) noexcept;
|
| 3551 |
```
|
| 3552 |
|
| 3553 |
-
*Effects:* `reset()`.
|
| 3554 |
|
| 3555 |
-
`get() == nullptr`
|
| 3556 |
|
| 3557 |
*Returns:* `*this`.
|
| 3558 |
|
| 3559 |
##### `unique_ptr` observers <a id="unique.ptr.single.observers">[[unique.ptr.single.observers]]</a>
|
| 3560 |
|
|
@@ -3572,11 +6590,12 @@ pointer operator->() const noexcept;
|
|
| 3572 |
|
| 3573 |
*Requires:* `get() != nullptr`.
|
| 3574 |
|
| 3575 |
*Returns:* `get()`.
|
| 3576 |
|
| 3577 |
-
*Note
|
|
|
|
| 3578 |
|
| 3579 |
``` cpp
|
| 3580 |
pointer get() const noexcept;
|
| 3581 |
```
|
| 3582 |
|
|
@@ -3599,29 +6618,33 @@ explicit operator bool() const noexcept;
|
|
| 3599 |
|
| 3600 |
``` cpp
|
| 3601 |
pointer release() noexcept;
|
| 3602 |
```
|
| 3603 |
|
| 3604 |
-
`get() == nullptr`.
|
| 3605 |
|
| 3606 |
*Returns:* The value `get()` had at the start of the call to `release`.
|
| 3607 |
|
| 3608 |
``` cpp
|
| 3609 |
void reset(pointer p = pointer()) noexcept;
|
| 3610 |
```
|
| 3611 |
|
| 3612 |
*Requires:* The expression `get_deleter()(get())` shall be well formed,
|
| 3613 |
shall have well-defined behavior, and shall not throw exceptions.
|
| 3614 |
|
| 3615 |
-
*Effects:*
|
| 3616 |
-
of the stored pointer, `old_p`, was not equal to
|
| 3617 |
-
`get_deleter()(old_p)`.
|
| 3618 |
-
because the call to `get_deleter()` may destroy `*this`.
|
| 3619 |
|
| 3620 |
-
*
|
| 3621 |
-
call to `get_deleter()`
|
| 3622 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3623 |
|
| 3624 |
``` cpp
|
| 3625 |
void swap(unique_ptr& u) noexcept;
|
| 3626 |
```
|
| 3627 |
|
|
@@ -3636,41 +6659,44 @@ deleters of `*this` and `u`.
|
|
| 3636 |
|
| 3637 |
``` cpp
|
| 3638 |
namespace std {
|
| 3639 |
template <class T, class D> class unique_ptr<T[], D> {
|
| 3640 |
public:
|
| 3641 |
-
|
| 3642 |
-
|
| 3643 |
-
|
| 3644 |
|
| 3645 |
// [unique.ptr.runtime.ctor], constructors
|
| 3646 |
constexpr unique_ptr() noexcept;
|
| 3647 |
-
explicit unique_ptr(
|
| 3648 |
-
unique_ptr(
|
| 3649 |
-
unique_ptr(
|
| 3650 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 3651 |
-
|
|
|
|
|
|
|
| 3652 |
|
| 3653 |
// destructor
|
| 3654 |
~unique_ptr();
|
| 3655 |
|
| 3656 |
// assignment
|
| 3657 |
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
|
|
|
|
|
|
| 3658 |
unique_ptr& operator=(nullptr_t) noexcept;
|
| 3659 |
|
| 3660 |
// [unique.ptr.runtime.observers], observers
|
| 3661 |
T& operator[](size_t i) const;
|
| 3662 |
pointer get() const noexcept;
|
| 3663 |
deleter_type& get_deleter() noexcept;
|
| 3664 |
const deleter_type& get_deleter() const noexcept;
|
| 3665 |
explicit operator bool() const noexcept;
|
| 3666 |
|
| 3667 |
-
// [unique.ptr.runtime.modifiers] modifiers
|
| 3668 |
pointer release() noexcept;
|
| 3669 |
-
void reset(
|
| 3670 |
-
void reset(nullptr_t) noexcept;
|
| 3671 |
-
template <class U> void reset(U) = delete;
|
| 3672 |
void swap(unique_ptr& u) noexcept;
|
| 3673 |
|
| 3674 |
// disable copy from lvalue
|
| 3675 |
unique_ptr(const unique_ptr&) = delete;
|
| 3676 |
unique_ptr& operator=(const unique_ptr&) = delete;
|
|
@@ -3679,36 +6705,92 @@ namespace std {
|
|
| 3679 |
```
|
| 3680 |
|
| 3681 |
A specialization for array types is provided with a slightly altered
|
| 3682 |
interface.
|
| 3683 |
|
| 3684 |
-
- Conversions between different types of `unique_ptr<T[], D>`
|
| 3685 |
-
|
| 3686 |
-
|
|
|
|
| 3687 |
- Pointers to types derived from `T` are rejected by the constructors,
|
| 3688 |
and by `reset`.
|
| 3689 |
- The observers `operator*` and `operator->` are not provided.
|
| 3690 |
- The indexing observer `operator[]` is provided.
|
| 3691 |
- The default deleter will call `delete[]`.
|
| 3692 |
|
| 3693 |
-
Descriptions are provided below only for
|
| 3694 |
-
|
| 3695 |
|
| 3696 |
The template argument `T` shall be a complete type.
|
| 3697 |
|
| 3698 |
##### `unique_ptr` constructors <a id="unique.ptr.runtime.ctor">[[unique.ptr.runtime.ctor]]</a>
|
| 3699 |
|
| 3700 |
``` cpp
|
| 3701 |
-
explicit unique_ptr(
|
| 3702 |
-
unique_ptr(pointer p, see below d) noexcept;
|
| 3703 |
-
unique_ptr(pointer p, see below d) noexcept;
|
| 3704 |
```
|
| 3705 |
|
| 3706 |
-
|
| 3707 |
-
that
|
| 3708 |
-
|
| 3709 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3710 |
|
| 3711 |
##### `unique_ptr` observers <a id="unique.ptr.runtime.observers">[[unique.ptr.runtime.observers]]</a>
|
| 3712 |
|
| 3713 |
``` cpp
|
| 3714 |
T& operator[](size_t i) const;
|
|
@@ -3720,15 +6802,27 @@ stored pointer points.
|
|
| 3720 |
*Returns:* `get()[i]`.
|
| 3721 |
|
| 3722 |
##### `unique_ptr` modifiers <a id="unique.ptr.runtime.modifiers">[[unique.ptr.runtime.modifiers]]</a>
|
| 3723 |
|
| 3724 |
``` cpp
|
| 3725 |
-
void reset(nullptr_t p) noexcept;
|
| 3726 |
```
|
| 3727 |
|
| 3728 |
*Effects:* Equivalent to `reset(pointer())`.
|
| 3729 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3730 |
#### `unique_ptr` creation <a id="unique.ptr.create">[[unique.ptr.create]]</a>
|
| 3731 |
|
| 3732 |
``` cpp
|
| 3733 |
template <class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
|
| 3734 |
```
|
|
@@ -3758,10 +6852,13 @@ unless `T` is an array of known bound.
|
|
| 3758 |
|
| 3759 |
``` cpp
|
| 3760 |
template <class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
|
| 3761 |
```
|
| 3762 |
|
|
|
|
|
|
|
|
|
|
| 3763 |
*Effects:* Calls `x.swap(y)`.
|
| 3764 |
|
| 3765 |
``` cpp
|
| 3766 |
template <class T1, class D1, class T2, class D2>
|
| 3767 |
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
@@ -3779,20 +6876,26 @@ template <class T1, class D1, class T2, class D2>
|
|
| 3779 |
``` cpp
|
| 3780 |
template <class T1, class D1, class T2, class D2>
|
| 3781 |
bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 3782 |
```
|
| 3783 |
|
| 3784 |
-
*Requires:* Let `CT`
|
| 3785 |
-
`unique_ptr<T2, D2>::pointer>::type`. Then the specialization `less<CT>`
|
| 3786 |
-
shall be a function object type ([[function.objects]]) that induces a
|
| 3787 |
-
strict weak ordering ([[alg.sorting]]) on the pointer values.
|
| 3788 |
|
| 3789 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3790 |
|
| 3791 |
*Remarks:* If `unique_ptr<T1, D1>::pointer` is not implicitly
|
| 3792 |
-
convertible to `CT` or `unique_ptr<T2, D2>::pointer` is not implicitly
|
| 3793 |
-
convertible to `CT`, the program is ill-formed.
|
| 3794 |
|
| 3795 |
``` cpp
|
| 3796 |
template <class T1, class D1, class T2, class D2>
|
| 3797 |
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 3798 |
```
|
|
@@ -3877,96 +6980,99 @@ template <class T, class D>
|
|
| 3877 |
*Returns:* The first function template returns `!(x < nullptr)`. The
|
| 3878 |
second function template returns `!(nullptr < x)`.
|
| 3879 |
|
| 3880 |
### Shared-ownership pointers <a id="util.smartptr">[[util.smartptr]]</a>
|
| 3881 |
|
| 3882 |
-
#### Class `bad_weak_ptr` <a id="util.smartptr.
|
| 3883 |
|
| 3884 |
``` cpp
|
| 3885 |
namespace std {
|
| 3886 |
-
class bad_weak_ptr: public
|
| 3887 |
public:
|
| 3888 |
bad_weak_ptr() noexcept;
|
| 3889 |
};
|
| 3890 |
-
}
|
| 3891 |
```
|
| 3892 |
|
| 3893 |
An exception of type `bad_weak_ptr` is thrown by the `shared_ptr`
|
| 3894 |
constructor taking a `weak_ptr`.
|
| 3895 |
|
| 3896 |
``` cpp
|
| 3897 |
bad_weak_ptr() noexcept;
|
| 3898 |
```
|
| 3899 |
|
| 3900 |
-
*Postconditions:* `what()` returns
|
| 3901 |
|
| 3902 |
#### Class template `shared_ptr` <a id="util.smartptr.shared">[[util.smartptr.shared]]</a>
|
| 3903 |
|
| 3904 |
The `shared_ptr` class template stores a pointer, usually obtained via
|
| 3905 |
`new`. `shared_ptr` implements semantics of shared ownership; the last
|
| 3906 |
remaining owner of the pointer is responsible for destroying the object,
|
| 3907 |
or otherwise releasing the resources associated with the stored pointer.
|
| 3908 |
-
A `shared_ptr`
|
| 3909 |
|
| 3910 |
``` cpp
|
| 3911 |
namespace std {
|
| 3912 |
template<class T> class shared_ptr {
|
| 3913 |
public:
|
| 3914 |
-
|
|
|
|
| 3915 |
|
| 3916 |
-
// [util.smartptr.shared.const], constructors
|
| 3917 |
constexpr shared_ptr() noexcept;
|
| 3918 |
template<class Y> explicit shared_ptr(Y* p);
|
| 3919 |
template<class Y, class D> shared_ptr(Y* p, D d);
|
| 3920 |
template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
|
| 3921 |
template <class D> shared_ptr(nullptr_t p, D d);
|
| 3922 |
template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
|
| 3923 |
-
template<class Y> shared_ptr(const shared_ptr<Y>& r,
|
| 3924 |
shared_ptr(const shared_ptr& r) noexcept;
|
| 3925 |
template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
|
| 3926 |
shared_ptr(shared_ptr&& r) noexcept;
|
| 3927 |
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
|
| 3928 |
template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
|
| 3929 |
-
template<class Y> shared_ptr(auto_ptr<Y>&& r);
|
| 3930 |
template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
|
| 3931 |
-
constexpr shared_ptr(nullptr_t) : shared_ptr() { }
|
| 3932 |
|
| 3933 |
-
// [util.smartptr.shared.dest], destructor
|
| 3934 |
~shared_ptr();
|
| 3935 |
|
| 3936 |
-
// [util.smartptr.shared.assign], assignment
|
| 3937 |
shared_ptr& operator=(const shared_ptr& r) noexcept;
|
| 3938 |
template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 3939 |
shared_ptr& operator=(shared_ptr&& r) noexcept;
|
| 3940 |
template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r) noexcept;
|
| 3941 |
-
template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
|
| 3942 |
template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
|
| 3943 |
|
| 3944 |
-
// [util.smartptr.shared.mod], modifiers
|
| 3945 |
void swap(shared_ptr& r) noexcept;
|
| 3946 |
void reset() noexcept;
|
| 3947 |
template<class Y> void reset(Y* p);
|
| 3948 |
template<class Y, class D> void reset(Y* p, D d);
|
| 3949 |
template<class Y, class D, class A> void reset(Y* p, D d, A a);
|
| 3950 |
|
| 3951 |
-
// [util.smartptr.shared.obs], observers
|
| 3952 |
-
|
| 3953 |
T& operator*() const noexcept;
|
| 3954 |
T* operator->() const noexcept;
|
|
|
|
| 3955 |
long use_count() const noexcept;
|
| 3956 |
-
bool unique() const noexcept;
|
| 3957 |
explicit operator bool() const noexcept;
|
| 3958 |
-
template<class U> bool owner_before(shared_ptr<U>
|
| 3959 |
-
template<class U> bool owner_before(weak_ptr<U>
|
| 3960 |
};
|
| 3961 |
|
|
|
|
|
|
|
|
|
|
| 3962 |
// [util.smartptr.shared.create], shared_ptr creation
|
| 3963 |
-
template<class T, class... Args>
|
|
|
|
| 3964 |
template<class T, class A, class... Args>
|
| 3965 |
shared_ptr<T> allocate_shared(const A& a, Args&&... args);
|
| 3966 |
|
| 3967 |
-
// [util.smartptr.shared.cmp], shared_ptr comparisons
|
| 3968 |
template<class T, class U>
|
| 3969 |
bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 3970 |
template<class T, class U>
|
| 3971 |
bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 3972 |
template<class T, class U>
|
|
@@ -4001,218 +7107,252 @@ namespace std {
|
|
| 4001 |
template <class T>
|
| 4002 |
bool operator>=(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 4003 |
template <class T>
|
| 4004 |
bool operator>=(nullptr_t, const shared_ptr<T>& b) noexcept;
|
| 4005 |
|
| 4006 |
-
// [util.smartptr.shared.spec], shared_ptr specialized algorithms
|
| 4007 |
-
template<class T>
|
|
|
|
| 4008 |
|
| 4009 |
-
// [util.smartptr.shared.cast], shared_ptr casts
|
| 4010 |
template<class T, class U>
|
| 4011 |
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 4012 |
template<class T, class U>
|
| 4013 |
shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 4014 |
template<class T, class U>
|
| 4015 |
shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
|
|
|
|
|
|
|
| 4016 |
|
| 4017 |
-
// [util.smartptr.getdeleter], shared_ptr get_deleter
|
| 4018 |
-
template<class D, class T>
|
|
|
|
| 4019 |
|
| 4020 |
-
// [util.smartptr.shared.io], shared_ptr I/O
|
| 4021 |
template<class E, class T, class Y>
|
| 4022 |
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, const shared_ptr<Y>& p);
|
| 4023 |
-
}
|
| 4024 |
```
|
| 4025 |
|
| 4026 |
Specializations of `shared_ptr` shall be `CopyConstructible`,
|
| 4027 |
`CopyAssignable`, and `LessThanComparable`, allowing their use in
|
| 4028 |
standard containers. Specializations of `shared_ptr` shall be
|
| 4029 |
-
convertible to `bool`, allowing their use in boolean
|
| 4030 |
-
declarations in conditions. The template parameter `T`
|
| 4031 |
-
may be an incomplete type.
|
|
|
|
|
|
|
| 4032 |
|
| 4033 |
``` cpp
|
| 4034 |
if (shared_ptr<X> px = dynamic_pointer_cast<X>(py)) {
|
| 4035 |
// do something with px
|
| 4036 |
}
|
| 4037 |
```
|
| 4038 |
|
|
|
|
|
|
|
| 4039 |
For purposes of determining the presence of a data race, member
|
| 4040 |
functions shall access and modify only the `shared_ptr` and `weak_ptr`
|
| 4041 |
objects themselves and not objects they refer to. Changes in
|
| 4042 |
`use_count()` do not reflect modifications that can introduce data
|
| 4043 |
races.
|
| 4044 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4045 |
##### `shared_ptr` constructors <a id="util.smartptr.shared.const">[[util.smartptr.shared.const]]</a>
|
| 4046 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4047 |
``` cpp
|
| 4048 |
constexpr shared_ptr() noexcept;
|
| 4049 |
```
|
| 4050 |
|
| 4051 |
-
*Effects:* Constructs an
|
| 4052 |
|
| 4053 |
*Postconditions:* `use_count() == 0 && get() == nullptr`.
|
| 4054 |
|
| 4055 |
``` cpp
|
| 4056 |
template<class Y> explicit shared_ptr(Y* p);
|
| 4057 |
```
|
| 4058 |
|
| 4059 |
-
*Requires:* `
|
| 4060 |
-
|
| 4061 |
-
defined behavior, and shall not throw exceptions.
|
| 4062 |
|
| 4063 |
-
*Effects:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4064 |
|
| 4065 |
*Postconditions:* `use_count() == 1 && get() == p`.
|
| 4066 |
|
| 4067 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 4068 |
resource other than memory could not be obtained.
|
| 4069 |
|
| 4070 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4071 |
|
| 4072 |
``` cpp
|
| 4073 |
template<class Y, class D> shared_ptr(Y* p, D d);
|
| 4074 |
template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
|
| 4075 |
template <class D> shared_ptr(nullptr_t p, D d);
|
| 4076 |
template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
|
| 4077 |
```
|
| 4078 |
|
| 4079 |
-
*Requires:* `
|
| 4080 |
-
`
|
| 4081 |
-
|
| 4082 |
-
|
| 4083 |
-
an allocator ([[allocator.requirements]]). The copy constructor and
|
| 4084 |
-
destructor of `A` shall not throw exceptions.
|
| 4085 |
|
| 4086 |
-
*Effects:* Constructs a `shared_ptr` object that
|
| 4087 |
-
|
| 4088 |
-
|
|
|
|
|
|
|
| 4089 |
|
| 4090 |
*Postconditions:* `use_count() == 1 && get() == p`.
|
| 4091 |
|
| 4092 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 4093 |
resource other than memory could not be obtained.
|
| 4094 |
|
| 4095 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4096 |
|
| 4097 |
``` cpp
|
| 4098 |
-
template<class Y> shared_ptr(const shared_ptr<Y>& r,
|
| 4099 |
```
|
| 4100 |
|
| 4101 |
-
*Effects:* Constructs a `shared_ptr` instance that stores `p` and
|
| 4102 |
-
|
| 4103 |
|
| 4104 |
-
*Postconditions:* `get() == p && use_count() == r.use_count()`
|
| 4105 |
|
| 4106 |
-
To avoid the possibility of a dangling pointer, the user of
|
| 4107 |
-
constructor must ensure that `p` remains valid at least until the
|
| 4108 |
-
ownership group of `r` is destroyed.
|
| 4109 |
|
| 4110 |
-
This constructor allows creation of an
|
| 4111 |
-
with a non-null stored pointer.
|
| 4112 |
|
| 4113 |
``` cpp
|
| 4114 |
shared_ptr(const shared_ptr& r) noexcept;
|
| 4115 |
template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
|
| 4116 |
```
|
| 4117 |
|
| 4118 |
-
The second constructor shall not participate in overload
|
| 4119 |
-
unless `Y*` is
|
| 4120 |
|
| 4121 |
-
*Effects:* If `r` is
|
| 4122 |
-
otherwise, constructs a `shared_ptr` object that
|
| 4123 |
`r`.
|
| 4124 |
|
| 4125 |
*Postconditions:* `get() == r.get() && use_count() == r.use_count()`.
|
| 4126 |
|
| 4127 |
``` cpp
|
| 4128 |
shared_ptr(shared_ptr&& r) noexcept;
|
| 4129 |
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
|
| 4130 |
```
|
| 4131 |
|
| 4132 |
-
The second constructor shall not participate in overload
|
| 4133 |
-
unless `Y*` is
|
| 4134 |
|
| 4135 |
-
*Effects:* Move
|
| 4136 |
|
| 4137 |
*Postconditions:* `*this` shall contain the old value of `r`. `r` shall
|
| 4138 |
-
be
|
| 4139 |
|
| 4140 |
``` cpp
|
| 4141 |
template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
|
| 4142 |
```
|
| 4143 |
|
| 4144 |
-
*
|
| 4145 |
-
|
| 4146 |
-
|
| 4147 |
-
`r` and stores a copy of the pointer stored in `r`.
|
| 4148 |
|
| 4149 |
*Postconditions:* `use_count() == r.use_count()`.
|
| 4150 |
|
| 4151 |
*Throws:* `bad_weak_ptr` when `r.expired()`.
|
| 4152 |
|
| 4153 |
-
|
| 4154 |
-
|
| 4155 |
-
``` cpp
|
| 4156 |
-
template<class Y> shared_ptr(auto_ptr<Y>&& r);
|
| 4157 |
-
```
|
| 4158 |
-
|
| 4159 |
-
*Requires:* `r.release()` shall be convertible to `T*`. `Y` shall be a
|
| 4160 |
-
complete type. The expression `delete r.release()` shall be well formed,
|
| 4161 |
-
shall have well defined behavior, and shall not throw exceptions.
|
| 4162 |
-
|
| 4163 |
-
*Effects:* Constructs a `shared_ptr` object that stores and *owns*
|
| 4164 |
-
`r.release()`.
|
| 4165 |
-
|
| 4166 |
-
*Postconditions:* `use_count() == 1` `&&` `r.get() == nullptr`.
|
| 4167 |
-
|
| 4168 |
-
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 4169 |
-
resource other than memory could not be obtained.
|
| 4170 |
-
|
| 4171 |
-
If an exception is thrown, the constructor has no effect.
|
| 4172 |
|
| 4173 |
``` cpp
|
| 4174 |
template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
|
| 4175 |
```
|
| 4176 |
|
| 4177 |
-
*
|
| 4178 |
-
`
|
| 4179 |
-
|
| 4180 |
|
| 4181 |
-
If
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4182 |
|
| 4183 |
##### `shared_ptr` destructor <a id="util.smartptr.shared.dest">[[util.smartptr.shared.dest]]</a>
|
| 4184 |
|
| 4185 |
``` cpp
|
| 4186 |
~shared_ptr();
|
| 4187 |
```
|
| 4188 |
|
| 4189 |
*Effects:*
|
| 4190 |
|
| 4191 |
-
- If `*this` is
|
| 4192 |
instance (`use_count() > 1`), there are no side effects.
|
| 4193 |
-
- Otherwise, if `*this`
|
| 4194 |
-
|
| 4195 |
-
- Otherwise, `*this`
|
| 4196 |
|
| 4197 |
-
Since the destruction of `*this` decreases the number of
|
| 4198 |
-
share ownership with `*this` by one, after `*this` has
|
| 4199 |
-
all `shared_ptr` instances that shared ownership with
|
| 4200 |
-
report a `use_count()` that is one less than its previous
|
|
|
|
| 4201 |
|
| 4202 |
##### `shared_ptr` assignment <a id="util.smartptr.shared.assign">[[util.smartptr.shared.assign]]</a>
|
| 4203 |
|
| 4204 |
``` cpp
|
| 4205 |
shared_ptr& operator=(const shared_ptr& r) noexcept;
|
| 4206 |
template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 4207 |
-
template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
|
| 4208 |
```
|
| 4209 |
|
| 4210 |
*Effects:* Equivalent to `shared_ptr(r).swap(*this)`.
|
| 4211 |
|
| 4212 |
*Returns:* `*this`.
|
| 4213 |
|
|
|
|
|
|
|
| 4214 |
The use count updates caused by the temporary object construction and
|
| 4215 |
destruction are not observable side effects, so the implementation may
|
| 4216 |
meet the effects (and the implied guarantees) via different means,
|
| 4217 |
without creating a temporary. In particular, in the example:
|
| 4218 |
|
|
@@ -4223,10 +7363,12 @@ p = p;
|
|
| 4223 |
q = p;
|
| 4224 |
```
|
| 4225 |
|
| 4226 |
both assignments may be no-ops.
|
| 4227 |
|
|
|
|
|
|
|
| 4228 |
``` cpp
|
| 4229 |
shared_ptr& operator=(shared_ptr&& r) noexcept;
|
| 4230 |
template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r) noexcept;
|
| 4231 |
```
|
| 4232 |
|
|
@@ -4238,11 +7380,11 @@ template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r) noexcept;
|
|
| 4238 |
template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
|
| 4239 |
```
|
| 4240 |
|
| 4241 |
*Effects:* Equivalent to `shared_ptr(std::move(r)).swap(*this)`.
|
| 4242 |
|
| 4243 |
-
*Returns:* `*this`
|
| 4244 |
|
| 4245 |
##### `shared_ptr` modifiers <a id="util.smartptr.shared.mod">[[util.smartptr.shared.mod]]</a>
|
| 4246 |
|
| 4247 |
``` cpp
|
| 4248 |
void swap(shared_ptr& r) noexcept;
|
|
@@ -4275,64 +7417,87 @@ template<class Y, class D, class A> void reset(Y* p, D d, A a);
|
|
| 4275 |
*Effects:* Equivalent to `shared_ptr(p, d, a).swap(*this)`.
|
| 4276 |
|
| 4277 |
##### `shared_ptr` observers <a id="util.smartptr.shared.obs">[[util.smartptr.shared.obs]]</a>
|
| 4278 |
|
| 4279 |
``` cpp
|
| 4280 |
-
|
| 4281 |
```
|
| 4282 |
|
| 4283 |
-
*Returns:*
|
| 4284 |
|
| 4285 |
``` cpp
|
| 4286 |
T& operator*() const noexcept;
|
| 4287 |
```
|
| 4288 |
|
| 4289 |
*Requires:* `get() != 0`.
|
| 4290 |
|
| 4291 |
*Returns:* `*get()`.
|
| 4292 |
|
| 4293 |
-
*Remarks:* When `T` is `void`, it is unspecified
|
| 4294 |
-
function is declared. If it is declared, it is
|
| 4295 |
-
return type is, except that the declaration
|
| 4296 |
-
the definition) of the function shall be well
|
|
|
|
| 4297 |
|
| 4298 |
``` cpp
|
| 4299 |
T* operator->() const noexcept;
|
| 4300 |
```
|
| 4301 |
|
| 4302 |
*Requires:* `get() != 0`.
|
| 4303 |
|
| 4304 |
*Returns:* `get()`.
|
| 4305 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4306 |
``` cpp
|
| 4307 |
long use_count() const noexcept;
|
| 4308 |
```
|
| 4309 |
|
| 4310 |
-
*Returns:*
|
| 4311 |
-
|
| 4312 |
|
| 4313 |
-
|
| 4314 |
|
| 4315 |
-
``
|
| 4316 |
-
|
| 4317 |
-
```
|
| 4318 |
|
| 4319 |
-
*
|
|
|
|
| 4320 |
|
| 4321 |
-
|
| 4322 |
-
|
| 4323 |
-
`
|
|
|
|
|
|
|
| 4324 |
|
| 4325 |
``` cpp
|
| 4326 |
explicit operator bool() const noexcept;
|
| 4327 |
```
|
| 4328 |
|
| 4329 |
*Returns:* `get() != 0`.
|
| 4330 |
|
| 4331 |
``` cpp
|
| 4332 |
-
template<class U> bool owner_before(shared_ptr<U>
|
| 4333 |
-
template<class U> bool owner_before(weak_ptr<U>
|
| 4334 |
```
|
| 4335 |
|
| 4336 |
*Returns:* An unspecified value such that
|
| 4337 |
|
| 4338 |
- `x.owner_before(y)` defines a strict weak ordering as defined
|
|
@@ -4343,59 +7508,66 @@ template<class U> bool owner_before(weak_ptr<U> const& b) const;
|
|
| 4343 |
ownership or are both empty.
|
| 4344 |
|
| 4345 |
##### `shared_ptr` creation <a id="util.smartptr.shared.create">[[util.smartptr.shared.create]]</a>
|
| 4346 |
|
| 4347 |
``` cpp
|
| 4348 |
-
template<class T, class... Args>
|
|
|
|
| 4349 |
template<class T, class A, class... Args>
|
| 4350 |
shared_ptr<T> allocate_shared(const A& a, Args&&... args);
|
| 4351 |
```
|
| 4352 |
|
| 4353 |
*Requires:* The expression `::new (pv) T(std::forward<Args>(args)...)`,
|
| 4354 |
where `pv` has type `void*` and points to storage suitable to hold an
|
| 4355 |
object of type `T`, shall be well formed. `A` shall be an
|
| 4356 |
-
|
| 4357 |
destructor of `A` shall not throw exceptions.
|
| 4358 |
|
| 4359 |
*Effects:* Allocates memory suitable for an object of type `T` and
|
| 4360 |
-
constructs an object in that memory via the placement new
|
| 4361 |
`::new (pv) T(std::forward<Args>(args)...)`. The template
|
| 4362 |
`allocate_shared` uses a copy of `a` to allocate memory. If an exception
|
| 4363 |
is thrown, the functions have no effect.
|
| 4364 |
|
| 4365 |
*Returns:* A `shared_ptr` instance that stores and owns the address of
|
| 4366 |
the newly constructed object of type `T`.
|
| 4367 |
|
| 4368 |
-
*Postconditions:* `get() != 0 && use_count() == 1`
|
| 4369 |
|
| 4370 |
*Throws:* `bad_alloc`, or an exception thrown from `A::allocate` or from
|
| 4371 |
the constructor of `T`.
|
| 4372 |
|
| 4373 |
-
*Remarks:*
|
| 4374 |
-
|
| 4375 |
-
|
|
|
|
| 4376 |
|
| 4377 |
-
|
| 4378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4379 |
|
| 4380 |
##### `shared_ptr` comparison <a id="util.smartptr.shared.cmp">[[util.smartptr.shared.cmp]]</a>
|
| 4381 |
|
| 4382 |
``` cpp
|
| 4383 |
-
template<class T, class U>
|
|
|
|
| 4384 |
```
|
| 4385 |
|
| 4386 |
*Returns:* `a.get() == b.get()`.
|
| 4387 |
|
| 4388 |
``` cpp
|
| 4389 |
-
template<class T, class U>
|
|
|
|
| 4390 |
```
|
| 4391 |
|
| 4392 |
-
*Returns:* `less<
|
| 4393 |
-
pointer type (Clause [[expr]]) of `T*` and `U*`.
|
| 4394 |
|
| 4395 |
-
Defining a comparison
|
| 4396 |
-
keys in associative containers.
|
| 4397 |
|
| 4398 |
``` cpp
|
| 4399 |
template <class T>
|
| 4400 |
bool operator==(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 4401 |
template <class T>
|
|
@@ -4419,12 +7591,13 @@ template <class T>
|
|
| 4419 |
template <class T>
|
| 4420 |
bool operator<(nullptr_t, const shared_ptr<T>& a) noexcept;
|
| 4421 |
```
|
| 4422 |
|
| 4423 |
*Returns:* The first function template returns
|
| 4424 |
-
`less<T*>()(a.get(), nullptr)`. The second
|
| 4425 |
-
|
|
|
|
| 4426 |
|
| 4427 |
``` cpp
|
| 4428 |
template <class T>
|
| 4429 |
bool operator>(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 4430 |
template <class T>
|
|
@@ -4455,94 +7628,118 @@ template <class T>
|
|
| 4455 |
second function template returns `!(nullptr < a)`.
|
| 4456 |
|
| 4457 |
##### `shared_ptr` specialized algorithms <a id="util.smartptr.shared.spec">[[util.smartptr.shared.spec]]</a>
|
| 4458 |
|
| 4459 |
``` cpp
|
| 4460 |
-
template<class T>
|
|
|
|
| 4461 |
```
|
| 4462 |
|
| 4463 |
*Effects:* Equivalent to `a.swap(b)`.
|
| 4464 |
|
| 4465 |
##### `shared_ptr` casts <a id="util.smartptr.shared.cast">[[util.smartptr.shared.cast]]</a>
|
| 4466 |
|
| 4467 |
``` cpp
|
| 4468 |
-
template<class T, class U>
|
|
|
|
| 4469 |
```
|
| 4470 |
|
| 4471 |
-
*Requires:* The expression `static_cast<T*>(
|
| 4472 |
formed.
|
| 4473 |
|
| 4474 |
-
*Returns:*
|
| 4475 |
-
`shared_ptr<T>` object that stores `static_cast<T*>(r.get())` and
|
| 4476 |
-
*shares ownership* with `r`.
|
| 4477 |
|
| 4478 |
-
|
| 4479 |
-
|
|
|
|
| 4480 |
|
| 4481 |
-
The seemingly equivalent expression
|
| 4482 |
`shared_ptr<T>(static_cast<T*>(r.get()))` will eventually result in
|
| 4483 |
-
undefined behavior, attempting to delete the same object
|
|
|
|
| 4484 |
|
| 4485 |
``` cpp
|
| 4486 |
-
template<class T, class U>
|
|
|
|
| 4487 |
```
|
| 4488 |
|
| 4489 |
-
*Requires:* The expression `dynamic_cast<T*>(
|
| 4490 |
formed and shall have well defined behavior.
|
| 4491 |
|
| 4492 |
*Returns:*
|
| 4493 |
|
| 4494 |
-
- When `dynamic_cast<T*>(r.get())`
|
| 4495 |
-
|
| 4496 |
-
|
| 4497 |
-
- Otherwise, an *empty* `shared_ptr<T>` object.
|
| 4498 |
|
| 4499 |
-
|
| 4500 |
-
|
| 4501 |
-
The seemingly equivalent expression
|
| 4502 |
`shared_ptr<T>(dynamic_cast<T*>(r.get()))` will eventually result in
|
| 4503 |
-
undefined behavior, attempting to delete the same object
|
|
|
|
| 4504 |
|
| 4505 |
``` cpp
|
| 4506 |
-
template<class T, class U>
|
|
|
|
| 4507 |
```
|
| 4508 |
|
| 4509 |
-
*Requires:* The expression `const_cast<T*>(
|
| 4510 |
-
formed.
|
| 4511 |
|
| 4512 |
-
*Returns:*
|
| 4513 |
-
`shared_ptr<T>` object that stores `const_cast<T*>(r.get())` and shares
|
| 4514 |
-
ownership with `r`.
|
| 4515 |
|
| 4516 |
-
|
| 4517 |
-
|
|
|
|
| 4518 |
|
| 4519 |
-
The seemingly equivalent expression
|
| 4520 |
`shared_ptr<T>(const_cast<T*>(r.get()))` will eventually result in
|
| 4521 |
-
undefined behavior, attempting to delete the same object
|
|
|
|
| 4522 |
|
| 4523 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4524 |
|
| 4525 |
``` cpp
|
| 4526 |
-
template<class D, class T>
|
|
|
|
| 4527 |
```
|
| 4528 |
|
| 4529 |
-
*Returns:* If `p`
|
| 4530 |
-
|
| 4531 |
-
valid as long as there exists a `shared_ptr` instance that owns
|
| 4532 |
-
|
| 4533 |
-
|
| 4534 |
-
|
|
|
|
|
|
|
|
|
|
| 4535 |
|
| 4536 |
##### `shared_ptr` I/O <a id="util.smartptr.shared.io">[[util.smartptr.shared.io]]</a>
|
| 4537 |
|
| 4538 |
``` cpp
|
| 4539 |
template<class E, class T, class Y>
|
| 4540 |
-
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y>
|
| 4541 |
```
|
| 4542 |
|
| 4543 |
-
*Effects:* `os << p.get();`
|
| 4544 |
|
| 4545 |
*Returns:* `os`.
|
| 4546 |
|
| 4547 |
#### Class template `weak_ptr` <a id="util.smartptr.weak">[[util.smartptr.weak]]</a>
|
| 4548 |
|
|
@@ -4552,27 +7749,27 @@ can be converted to a `shared_ptr` using the member function `lock`.
|
|
| 4552 |
|
| 4553 |
``` cpp
|
| 4554 |
namespace std {
|
| 4555 |
template<class T> class weak_ptr {
|
| 4556 |
public:
|
| 4557 |
-
|
| 4558 |
|
| 4559 |
// [util.smartptr.weak.const], constructors
|
| 4560 |
constexpr weak_ptr() noexcept;
|
| 4561 |
-
template<class Y> weak_ptr(shared_ptr<Y>
|
| 4562 |
-
weak_ptr(
|
| 4563 |
-
template<class Y> weak_ptr(weak_ptr<Y>
|
| 4564 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 4565 |
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
|
| 4566 |
|
| 4567 |
// [util.smartptr.weak.dest], destructor
|
| 4568 |
~weak_ptr();
|
| 4569 |
|
| 4570 |
// [util.smartptr.weak.assign], assignment
|
| 4571 |
-
weak_ptr& operator=(
|
| 4572 |
-
template<class Y> weak_ptr& operator=(weak_ptr<Y>
|
| 4573 |
-
template<class Y> weak_ptr& operator=(shared_ptr<Y>
|
| 4574 |
weak_ptr& operator=(weak_ptr&& r) noexcept;
|
| 4575 |
template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
|
| 4576 |
|
| 4577 |
// [util.smartptr.weak.mod], modifiers
|
| 4578 |
void swap(weak_ptr& r) noexcept;
|
|
@@ -4580,17 +7777,20 @@ namespace std {
|
|
| 4580 |
|
| 4581 |
// [util.smartptr.weak.obs], observers
|
| 4582 |
long use_count() const noexcept;
|
| 4583 |
bool expired() const noexcept;
|
| 4584 |
shared_ptr<T> lock() const noexcept;
|
| 4585 |
-
template<class U> bool owner_before(shared_ptr<U>
|
| 4586 |
-
template<class U> bool owner_before(weak_ptr<U>
|
| 4587 |
};
|
| 4588 |
|
|
|
|
|
|
|
|
|
|
| 4589 |
// [util.smartptr.weak.spec], specialized algorithms
|
| 4590 |
template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
| 4591 |
-
}
|
| 4592 |
```
|
| 4593 |
|
| 4594 |
Specializations of `weak_ptr` shall be `CopyConstructible` and
|
| 4595 |
`CopyAssignable`, allowing their use in standard containers. The
|
| 4596 |
template parameter `T` of `weak_ptr` may be an incomplete type.
|
|
@@ -4599,41 +7799,41 @@ template parameter `T` of `weak_ptr` may be an incomplete type.
|
|
| 4599 |
|
| 4600 |
``` cpp
|
| 4601 |
constexpr weak_ptr() noexcept;
|
| 4602 |
```
|
| 4603 |
|
| 4604 |
-
*Effects:* Constructs an
|
| 4605 |
|
| 4606 |
*Postconditions:* `use_count() == 0`.
|
| 4607 |
|
| 4608 |
``` cpp
|
| 4609 |
weak_ptr(const weak_ptr& r) noexcept;
|
| 4610 |
template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
|
| 4611 |
template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
|
| 4612 |
```
|
| 4613 |
|
| 4614 |
-
The second and third constructors shall not participate in
|
| 4615 |
-
resolution unless `Y*` is
|
| 4616 |
|
| 4617 |
-
*Effects:* If `r` is
|
| 4618 |
-
otherwise, constructs a `weak_ptr` object that
|
| 4619 |
-
|
| 4620 |
|
| 4621 |
*Postconditions:* `use_count() == r.use_count()`.
|
| 4622 |
|
| 4623 |
``` cpp
|
| 4624 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 4625 |
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
|
| 4626 |
```
|
| 4627 |
|
| 4628 |
-
The second constructor shall not participate in overload
|
| 4629 |
-
unless `Y*` is
|
| 4630 |
|
| 4631 |
-
*Effects:* Move
|
| 4632 |
|
| 4633 |
*Postconditions:* `*this` shall contain the old value of `r`. `r` shall
|
| 4634 |
-
be
|
| 4635 |
|
| 4636 |
##### `weak_ptr` destructor <a id="util.smartptr.weak.dest">[[util.smartptr.weak.dest]]</a>
|
| 4637 |
|
| 4638 |
``` cpp
|
| 4639 |
~weak_ptr();
|
|
@@ -4684,33 +7884,29 @@ void reset() noexcept;
|
|
| 4684 |
|
| 4685 |
``` cpp
|
| 4686 |
long use_count() const noexcept;
|
| 4687 |
```
|
| 4688 |
|
| 4689 |
-
*Returns:* `0` if `*this` is
|
| 4690 |
-
`shared_ptr` instances that
|
| 4691 |
-
|
| 4692 |
-
`use_count()` is not necessarily efficient.
|
| 4693 |
|
| 4694 |
``` cpp
|
| 4695 |
bool expired() const noexcept;
|
| 4696 |
```
|
| 4697 |
|
| 4698 |
*Returns:* `use_count() == 0`.
|
| 4699 |
|
| 4700 |
-
`expired()` may be faster than `use_count()`.
|
| 4701 |
-
|
| 4702 |
``` cpp
|
| 4703 |
shared_ptr<T> lock() const noexcept;
|
| 4704 |
```
|
| 4705 |
|
| 4706 |
-
*Returns:* `expired() ?
|
| 4707 |
executed atomically.
|
| 4708 |
|
| 4709 |
``` cpp
|
| 4710 |
-
template<class U> bool owner_before(shared_ptr<U>
|
| 4711 |
-
template<class U> bool owner_before(weak_ptr<U>
|
| 4712 |
```
|
| 4713 |
|
| 4714 |
*Returns:* An unspecified value such that
|
| 4715 |
|
| 4716 |
- `x.owner_before(y)` defines a strict weak ordering as defined
|
|
@@ -4721,11 +7917,12 @@ template<class U> bool owner_before(weak_ptr<U> const& b) const;
|
|
| 4721 |
ownership or are both empty.
|
| 4722 |
|
| 4723 |
##### `weak_ptr` specialized algorithms <a id="util.smartptr.weak.spec">[[util.smartptr.weak.spec]]</a>
|
| 4724 |
|
| 4725 |
``` cpp
|
| 4726 |
-
template<class T>
|
|
|
|
| 4727 |
```
|
| 4728 |
|
| 4729 |
*Effects:* Equivalent to `a.swap(b)`.
|
| 4730 |
|
| 4731 |
#### Class template `owner_less` <a id="util.smartptr.ownerless">[[util.smartptr.ownerless]]</a>
|
|
@@ -4733,130 +7930,125 @@ template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
|
| 4733 |
The class template `owner_less` allows ownership-based mixed comparisons
|
| 4734 |
of shared and weak pointers.
|
| 4735 |
|
| 4736 |
``` cpp
|
| 4737 |
namespace std {
|
| 4738 |
-
template<class T> struct owner_less;
|
| 4739 |
|
| 4740 |
template<class T> struct owner_less<shared_ptr<T>> {
|
| 4741 |
-
|
| 4742 |
-
|
| 4743 |
-
|
| 4744 |
-
bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
|
| 4745 |
-
bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
|
| 4746 |
-
bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
|
| 4747 |
};
|
| 4748 |
|
| 4749 |
template<class T> struct owner_less<weak_ptr<T>> {
|
| 4750 |
-
|
| 4751 |
-
|
| 4752 |
-
|
| 4753 |
-
|
| 4754 |
-
|
| 4755 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4756 |
};
|
| 4757 |
}
|
| 4758 |
```
|
| 4759 |
|
| 4760 |
-
`operator()(x,y)` shall return `x.owner_before(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4761 |
|
| 4762 |
- `operator()` defines a strict weak ordering as defined in
|
| 4763 |
[[alg.sorting]];
|
| 4764 |
- under the equivalence relation defined by `operator()`,
|
| 4765 |
`!operator()(a, b) && !operator()(b, a)`, two `shared_ptr` or
|
| 4766 |
`weak_ptr` instances are equivalent if and only if they share
|
| 4767 |
ownership or are both empty.
|
| 4768 |
|
|
|
|
|
|
|
| 4769 |
#### Class template `enable_shared_from_this` <a id="util.smartptr.enab">[[util.smartptr.enab]]</a>
|
| 4770 |
|
| 4771 |
A class `T` can inherit from `enable_shared_from_this<T>` to inherit the
|
| 4772 |
-
`shared_from_this` member functions that obtain a
|
| 4773 |
pointing to `*this`.
|
| 4774 |
|
|
|
|
|
|
|
| 4775 |
``` cpp
|
| 4776 |
-
struct X: public enable_shared_from_this<X> {
|
| 4777 |
-
};
|
| 4778 |
|
| 4779 |
int main() {
|
| 4780 |
shared_ptr<X> p(new X);
|
| 4781 |
shared_ptr<X> q = p->shared_from_this();
|
| 4782 |
assert(p == q);
|
| 4783 |
-
assert(!
|
| 4784 |
}
|
| 4785 |
```
|
| 4786 |
|
|
|
|
|
|
|
| 4787 |
``` cpp
|
| 4788 |
namespace std {
|
| 4789 |
template<class T> class enable_shared_from_this {
|
| 4790 |
protected:
|
| 4791 |
constexpr enable_shared_from_this() noexcept;
|
| 4792 |
-
enable_shared_from_this(
|
| 4793 |
-
enable_shared_from_this& operator=(
|
| 4794 |
~enable_shared_from_this();
|
| 4795 |
public:
|
| 4796 |
shared_ptr<T> shared_from_this();
|
| 4797 |
shared_ptr<T const> shared_from_this() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4798 |
};
|
| 4799 |
-
}
|
| 4800 |
```
|
| 4801 |
|
| 4802 |
The template parameter `T` of `enable_shared_from_this` may be an
|
| 4803 |
incomplete type.
|
| 4804 |
|
| 4805 |
``` cpp
|
| 4806 |
constexpr enable_shared_from_this() noexcept;
|
| 4807 |
enable_shared_from_this(const enable_shared_from_this<T>&) noexcept;
|
| 4808 |
```
|
| 4809 |
|
| 4810 |
-
*Effects:*
|
| 4811 |
|
| 4812 |
``` cpp
|
| 4813 |
enable_shared_from_this<T>& operator=(const enable_shared_from_this<T>&) noexcept;
|
| 4814 |
```
|
| 4815 |
|
| 4816 |
*Returns:* `*this`.
|
| 4817 |
|
| 4818 |
-
``
|
| 4819 |
-
~enable_shared_from_this();
|
| 4820 |
-
```
|
| 4821 |
-
|
| 4822 |
-
*Effects:* Destroys `*this`.
|
| 4823 |
|
| 4824 |
``` cpp
|
| 4825 |
shared_ptr<T> shared_from_this();
|
| 4826 |
shared_ptr<T const> shared_from_this() const;
|
| 4827 |
```
|
| 4828 |
|
| 4829 |
-
*
|
| 4830 |
-
class of `T`. `*this` shall be a subobject of an object `t` of type `T`.
|
| 4831 |
-
There shall be at least one `shared_ptr` instance `p` that *owns* `&t`.
|
| 4832 |
-
|
| 4833 |
-
*Returns:* A `shared_ptr<T>` object `r` that *shares ownership with*
|
| 4834 |
-
`p`.
|
| 4835 |
-
|
| 4836 |
-
*Postconditions:* `r.get() == this`.
|
| 4837 |
-
|
| 4838 |
-
A possible implementation is shown below:
|
| 4839 |
|
| 4840 |
``` cpp
|
| 4841 |
-
|
| 4842 |
-
|
| 4843 |
-
weak_ptr<T> __weak_this;
|
| 4844 |
-
protected:
|
| 4845 |
-
constexpr enable_shared_from_this() : __weak_this() { }
|
| 4846 |
-
enable_shared_from_this(enable_shared_from_this const &) { }
|
| 4847 |
-
enable_shared_from_this& operator=(enable_shared_from_this const &) { return *this; }
|
| 4848 |
-
~enable_shared_from_this() { }
|
| 4849 |
-
public:
|
| 4850 |
-
shared_ptr<T> shared_from_this() { return shared_ptr<T>(__weak_this); }
|
| 4851 |
-
shared_ptr<T const> shared_from_this() const { return shared_ptr<T const>(__weak_this); }
|
| 4852 |
-
};
|
| 4853 |
```
|
| 4854 |
|
| 4855 |
-
|
| 4856 |
-
presence of an `enable_shared_from_this` base and assign the newly
|
| 4857 |
-
created `shared_ptr` to its `__weak_this` member.
|
| 4858 |
|
| 4859 |
#### `shared_ptr` atomic access <a id="util.smartptr.shared.atomic">[[util.smartptr.shared.atomic]]</a>
|
| 4860 |
|
| 4861 |
Concurrent access to a `shared_ptr` object from multiple threads does
|
| 4862 |
not introduce a data race if the access is done exclusively via the
|
|
@@ -4908,11 +8100,11 @@ template<class T>
|
|
| 4908 |
void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
|
| 4909 |
```
|
| 4910 |
|
| 4911 |
*Requires:* `p` shall not be null.
|
| 4912 |
|
| 4913 |
-
*Effects:* `atomic_store_explicit(p, r, memory_order_seq_cst)`.
|
| 4914 |
|
| 4915 |
*Throws:* Nothing.
|
| 4916 |
|
| 4917 |
``` cpp
|
| 4918 |
template<class T>
|
|
@@ -4922,11 +8114,11 @@ template<class T>
|
|
| 4922 |
*Requires:* `p` shall not be null.
|
| 4923 |
|
| 4924 |
*Requires:* `mo` shall not be `memory_order_acquire` or
|
| 4925 |
`memory_order_acq_rel`.
|
| 4926 |
|
| 4927 |
-
*Effects:* `p->swap(r)`.
|
| 4928 |
|
| 4929 |
*Throws:* Nothing.
|
| 4930 |
|
| 4931 |
``` cpp
|
| 4932 |
template<class T>
|
|
@@ -4939,43 +8131,46 @@ template<class T>
|
|
| 4939 |
|
| 4940 |
*Throws:* Nothing.
|
| 4941 |
|
| 4942 |
``` cpp
|
| 4943 |
template<class T>
|
| 4944 |
-
shared_ptr<T> atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r,
|
| 4945 |
-
memory_order mo);
|
| 4946 |
```
|
| 4947 |
|
| 4948 |
*Requires:* `p` shall not be null.
|
| 4949 |
|
| 4950 |
-
*Effects:* `p->swap(r)`.
|
| 4951 |
|
| 4952 |
*Returns:* The previous value of `*p`.
|
| 4953 |
|
| 4954 |
*Throws:* Nothing.
|
| 4955 |
|
| 4956 |
``` cpp
|
| 4957 |
template<class T>
|
| 4958 |
-
bool atomic_compare_exchange_weak(
|
| 4959 |
-
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
|
| 4960 |
```
|
| 4961 |
|
| 4962 |
*Requires:* `p` shall not be null and `v` shall not be null.
|
| 4963 |
|
| 4964 |
*Returns:*
|
| 4965 |
-
|
|
|
|
|
|
|
|
|
|
| 4966 |
|
| 4967 |
*Throws:* Nothing.
|
| 4968 |
|
| 4969 |
``` cpp
|
| 4970 |
template<class T>
|
| 4971 |
-
bool atomic_compare_exchange_strong(
|
| 4972 |
-
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
|
| 4973 |
```
|
| 4974 |
|
| 4975 |
-
*Returns:*
|
| 4976 |
-
|
|
|
|
|
|
|
|
|
|
| 4977 |
|
| 4978 |
``` cpp
|
| 4979 |
template<class T>
|
| 4980 |
bool atomic_compare_exchange_weak_explicit(
|
| 4981 |
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
|
|
@@ -4984,53 +8179,1384 @@ template<class T>
|
|
| 4984 |
bool atomic_compare_exchange_strong_explicit(
|
| 4985 |
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
|
| 4986 |
memory_order success, memory_order failure);
|
| 4987 |
```
|
| 4988 |
|
| 4989 |
-
*Requires:* `p` shall not be null and `v` shall not be null.
|
| 4990 |
-
|
| 4991 |
-
|
| 4992 |
-
`memory_order_acq_rel`, or stronger than `success`.
|
| 4993 |
|
| 4994 |
*Effects:* If `*p` is equivalent to `*v`, assigns `w` to `*p` and has
|
| 4995 |
synchronization semantics corresponding to the value of `success`,
|
| 4996 |
otherwise assigns `*p` to `*v` and has synchronization semantics
|
| 4997 |
corresponding to the value of `failure`.
|
| 4998 |
|
| 4999 |
*Returns:* `true` if `*p` was equivalent to `*v`, `false` otherwise.
|
| 5000 |
|
| 5001 |
*Throws:* Nothing.
|
| 5002 |
|
| 5003 |
-
*Remarks:*
|
| 5004 |
-
same pointer value and share ownership.
|
| 5005 |
-
|
| 5006 |
-
*Remarks:* the weak forms may fail spuriously.
|
| 5007 |
-
See [[atomics.types.operations]].
|
| 5008 |
|
| 5009 |
#### Smart pointer hash support <a id="util.smartptr.hash">[[util.smartptr.hash]]</a>
|
| 5010 |
|
| 5011 |
``` cpp
|
| 5012 |
template <class T, class D> struct hash<unique_ptr<T, D>>;
|
| 5013 |
```
|
| 5014 |
|
| 5015 |
-
|
| 5016 |
-
|
| 5017 |
-
`
|
| 5018 |
-
|
| 5019 |
-
|
| 5020 |
-
|
| 5021 |
-
well-formed and well-defined, and shall meet the requirements of class
|
| 5022 |
-
template `hash` ([[unord.hash]]).
|
| 5023 |
|
| 5024 |
``` cpp
|
| 5025 |
template <class T> struct hash<shared_ptr<T>>;
|
| 5026 |
```
|
| 5027 |
|
| 5028 |
-
|
| 5029 |
-
|
| 5030 |
-
`
|
| 5031 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5032 |
|
| 5033 |
## Function objects <a id="function.objects">[[function.objects]]</a>
|
| 5034 |
|
| 5035 |
A *function object type* is an object type ([[basic.types]]) that can
|
| 5036 |
be the type of the *postfix-expression* in a function call (
|
|
@@ -5040,28 +9566,31 @@ to pass a pointer to a function to an algorithmic template (Clause
|
|
| 5040 |
[[algorithms]]), the interface is specified to accept a function object.
|
| 5041 |
This not only makes algorithmic templates work with pointers to
|
| 5042 |
functions, but also enables them to work with arbitrary function
|
| 5043 |
objects.
|
| 5044 |
|
|
|
|
|
|
|
| 5045 |
``` cpp
|
| 5046 |
namespace std {
|
| 5047 |
-
// [
|
| 5048 |
-
template <class
|
| 5049 |
-
|
|
|
|
| 5050 |
|
| 5051 |
-
// [refwrap], reference_wrapper
|
| 5052 |
template <class T> class reference_wrapper;
|
| 5053 |
|
| 5054 |
template <class T> reference_wrapper<T> ref(T&) noexcept;
|
| 5055 |
template <class T> reference_wrapper<const T> cref(const T&) noexcept;
|
| 5056 |
template <class T> void ref(const T&&) = delete;
|
| 5057 |
template <class T> void cref(const T&&) = delete;
|
| 5058 |
|
| 5059 |
template <class T> reference_wrapper<T> ref(reference_wrapper<T>) noexcept;
|
| 5060 |
template <class T> reference_wrapper<const T> cref(reference_wrapper<T>) noexcept;
|
| 5061 |
|
| 5062 |
-
// [arithmetic.operations], arithmetic operations
|
| 5063 |
template <class T = void> struct plus;
|
| 5064 |
template <class T = void> struct minus;
|
| 5065 |
template <class T = void> struct multiplies;
|
| 5066 |
template <class T = void> struct divides;
|
| 5067 |
template <class T = void> struct modulus;
|
|
@@ -5071,11 +9600,11 @@ namespace std {
|
|
| 5071 |
template <> struct multiplies<void>;
|
| 5072 |
template <> struct divides<void>;
|
| 5073 |
template <> struct modulus<void>;
|
| 5074 |
template <> struct negate<void>;
|
| 5075 |
|
| 5076 |
-
// [comparisons], comparisons
|
| 5077 |
template <class T = void> struct equal_to;
|
| 5078 |
template <class T = void> struct not_equal_to;
|
| 5079 |
template <class T = void> struct greater;
|
| 5080 |
template <class T = void> struct less;
|
| 5081 |
template <class T = void> struct greater_equal;
|
|
@@ -5085,168 +9614,119 @@ namespace std {
|
|
| 5085 |
template <> struct greater<void>;
|
| 5086 |
template <> struct less<void>;
|
| 5087 |
template <> struct greater_equal<void>;
|
| 5088 |
template <> struct less_equal<void>;
|
| 5089 |
|
| 5090 |
-
// [logical.operations], logical operations
|
| 5091 |
template <class T = void> struct logical_and;
|
| 5092 |
template <class T = void> struct logical_or;
|
| 5093 |
template <class T = void> struct logical_not;
|
| 5094 |
template <> struct logical_and<void>;
|
| 5095 |
template <> struct logical_or<void>;
|
| 5096 |
template <> struct logical_not<void>;
|
| 5097 |
|
| 5098 |
-
// [bitwise.operations], bitwise operations
|
| 5099 |
template <class T = void> struct bit_and;
|
| 5100 |
template <class T = void> struct bit_or;
|
| 5101 |
template <class T = void> struct bit_xor;
|
| 5102 |
template <class T = void> struct bit_not;
|
| 5103 |
template <> struct bit_and<void>;
|
| 5104 |
template <> struct bit_or<void>;
|
| 5105 |
template <> struct bit_xor<void>;
|
| 5106 |
template <> struct bit_not<void>;
|
| 5107 |
|
| 5108 |
-
// [
|
| 5109 |
-
template <class
|
| 5110 |
-
|
| 5111 |
-
constexpr unary_negate<Predicate> not1(const Predicate&);
|
| 5112 |
-
template <class Predicate> class binary_negate;
|
| 5113 |
-
template <class Predicate>
|
| 5114 |
-
constexpr binary_negate<Predicate> not2(const Predicate&);
|
| 5115 |
|
| 5116 |
-
// [func.bind], bind
|
| 5117 |
template<class T> struct is_bind_expression;
|
| 5118 |
template<class T> struct is_placeholder;
|
| 5119 |
|
| 5120 |
template<class F, class... BoundArgs>
|
| 5121 |
unspecified bind(F&&, BoundArgs&&...);
|
| 5122 |
template<class R, class F, class... BoundArgs>
|
| 5123 |
unspecified bind(F&&, BoundArgs&&...);
|
| 5124 |
|
| 5125 |
namespace placeholders {
|
| 5126 |
// M is the implementation-defined number of placeholders
|
| 5127 |
-
|
| 5128 |
-
|
| 5129 |
.
|
| 5130 |
.
|
| 5131 |
.
|
| 5132 |
-
|
| 5133 |
}
|
| 5134 |
|
| 5135 |
-
// [
|
| 5136 |
-
template
|
| 5137 |
-
|
| 5138 |
-
binder1st<Fn> bind1st(const Fn&, const T&);
|
| 5139 |
-
template <class Fn> class binder2nd;
|
| 5140 |
-
template <class Fn, class T>
|
| 5141 |
-
binder2nd<Fn> bind2nd(const Fn&, const T&);
|
| 5142 |
|
| 5143 |
-
// [
|
| 5144 |
-
template <class Arg, class Result> class pointer_to_unary_function;
|
| 5145 |
-
template <class Arg, class Result>
|
| 5146 |
-
pointer_to_unary_function<Arg,Result> ptr_fun(Result (*)(Arg));
|
| 5147 |
-
template <class Arg1, class Arg2, class Result>
|
| 5148 |
-
class pointer_to_binary_function;
|
| 5149 |
-
template <class Arg1, class Arg2, class Result>
|
| 5150 |
-
pointer_to_binary_function<Arg1,Arg2,Result>
|
| 5151 |
-
ptr_fun(Result (*)(Arg1,Arg2));
|
| 5152 |
-
|
| 5153 |
-
// [depr.member.pointer.adaptors], adaptors (deprecated):
|
| 5154 |
-
template<class S, class T> class mem_fun_t;
|
| 5155 |
-
template<class S, class T, class A> class mem_fun1_t;
|
| 5156 |
-
template<class S, class T>
|
| 5157 |
-
mem_fun_t<S,T> mem_fun(S (T::*f)());
|
| 5158 |
-
template<class S, class T, class A>
|
| 5159 |
-
mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
|
| 5160 |
-
template<class S, class T> class mem_fun_ref_t;
|
| 5161 |
-
template<class S, class T, class A> class mem_fun1_ref_t;
|
| 5162 |
-
template<class S, class T>
|
| 5163 |
-
mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
|
| 5164 |
-
template<class S, class T, class A>
|
| 5165 |
-
mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
|
| 5166 |
-
|
| 5167 |
-
template <class S, class T> class const_mem_fun_t;
|
| 5168 |
-
template <class S, class T, class A> class const_mem_fun1_t;
|
| 5169 |
-
template <class S, class T>
|
| 5170 |
-
const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
|
| 5171 |
-
template <class S, class T, class A>
|
| 5172 |
-
const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
|
| 5173 |
-
template <class S, class T> class const_mem_fun_ref_t;
|
| 5174 |
-
template <class S, class T, class A> class const_mem_fun1_ref_t;
|
| 5175 |
-
template <class S, class T>
|
| 5176 |
-
const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
|
| 5177 |
-
template <class S, class T, class A>
|
| 5178 |
-
const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
|
| 5179 |
-
|
| 5180 |
-
// [func.memfn], member function adaptors:
|
| 5181 |
-
template<class R, class T> unspecified mem_fn(R T::*);
|
| 5182 |
-
|
| 5183 |
-
// [func.wrap] polymorphic function wrappers:
|
| 5184 |
class bad_function_call;
|
| 5185 |
|
| 5186 |
-
template<class> class function; //
|
| 5187 |
template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
|
| 5188 |
|
| 5189 |
template<class R, class... ArgTypes>
|
| 5190 |
-
void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
|
| 5191 |
|
| 5192 |
template<class R, class... ArgTypes>
|
| 5193 |
-
bool operator==(const function<R(ArgTypes...)>&, nullptr_t);
|
| 5194 |
template<class R, class... ArgTypes>
|
| 5195 |
-
bool operator==(nullptr_t, const function<R(ArgTypes...)>&);
|
| 5196 |
template<class R, class... ArgTypes>
|
| 5197 |
-
bool operator!=(const function<R(ArgTypes...)>&, nullptr_t);
|
| 5198 |
template<class R, class... ArgTypes>
|
| 5199 |
-
bool operator!=(nullptr_t, const function<R(ArgTypes...)>&);
|
| 5200 |
|
| 5201 |
-
// [
|
| 5202 |
-
template
|
|
|
|
| 5203 |
|
| 5204 |
-
|
| 5205 |
-
|
| 5206 |
-
|
| 5207 |
-
|
| 5208 |
-
template <> struct hash<unsigned char>;
|
| 5209 |
-
template <> struct hash<char16_t>;
|
| 5210 |
-
template <> struct hash<char32_t>;
|
| 5211 |
-
template <> struct hash<wchar_t>;
|
| 5212 |
-
template <> struct hash<short>;
|
| 5213 |
-
template <> struct hash<unsigned short>;
|
| 5214 |
-
template <> struct hash<int>;
|
| 5215 |
-
template <> struct hash<unsigned int>;
|
| 5216 |
-
template <> struct hash<long>;
|
| 5217 |
-
template <> struct hash<long long>;
|
| 5218 |
-
template <> struct hash<unsigned long>;
|
| 5219 |
-
template <> struct hash<unsigned long long>;
|
| 5220 |
|
| 5221 |
-
template
|
| 5222 |
-
|
| 5223 |
-
|
|
|
|
| 5224 |
|
| 5225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5226 |
}
|
| 5227 |
```
|
| 5228 |
|
|
|
|
|
|
|
| 5229 |
If a C++program wants to have a by-element addition of two vectors `a`
|
| 5230 |
and `b` containing `double` and put the result into `a`, it can do:
|
| 5231 |
|
| 5232 |
``` cpp
|
| 5233 |
transform(a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
|
| 5234 |
```
|
| 5235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5236 |
To negate every element of `a`:
|
| 5237 |
|
| 5238 |
``` cpp
|
| 5239 |
transform(a.begin(), a.end(), a.begin(), negate<double>());
|
| 5240 |
```
|
| 5241 |
|
| 5242 |
-
|
| 5243 |
-
that take one or two arguments many of the function objects in this
|
| 5244 |
-
clause correspondingly provide typedefs `argument_type` and
|
| 5245 |
-
`result_type` for function objects that take one argument and
|
| 5246 |
-
`first_argument_type`, `second_argument_type`, and `result_type` for
|
| 5247 |
-
function objects that take two arguments.
|
| 5248 |
|
| 5249 |
### Definitions <a id="func.def">[[func.def]]</a>
|
| 5250 |
|
| 5251 |
The following definitions apply to this Clause:
|
| 5252 |
|
|
@@ -5268,67 +9748,70 @@ A *target object* is the callable object held by a call wrapper.
|
|
| 5268 |
### Requirements <a id="func.require">[[func.require]]</a>
|
| 5269 |
|
| 5270 |
Define `INVOKE(f, t1, t2, ..., tN)` as follows:
|
| 5271 |
|
| 5272 |
- `(t1.*f)(t2, ..., tN)` when `f` is a pointer to a member function of a
|
| 5273 |
-
class `T` and `t1` is
|
| 5274 |
-
|
| 5275 |
-
`T`
|
|
|
|
| 5276 |
- `((*t1).*f)(t2, ..., tN)` when `f` is a pointer to a member function
|
| 5277 |
-
of a class `T` and `t1`
|
| 5278 |
-
|
| 5279 |
-
|
| 5280 |
-
|
| 5281 |
-
|
| 5282 |
-
|
| 5283 |
-
|
| 5284 |
-
|
| 5285 |
- `f(t1, t2, ..., tN)` in all other cases.
|
| 5286 |
|
| 5287 |
-
Define `INVOKE(f, t1, t2, ..., tN
|
| 5288 |
-
|
| 5289 |
-
|
| 5290 |
-
If a call wrapper ([[func.def]]) has a *weak result type* the type of
|
| 5291 |
-
its member type `result_type` is based on the type `T` of the wrapper’s
|
| 5292 |
-
target object ([[func.def]]):
|
| 5293 |
-
|
| 5294 |
-
- if `T` is a pointer to function type, `result_type` shall be a synonym
|
| 5295 |
-
for the return type of `T`;
|
| 5296 |
-
- if `T` is a pointer to member function, `result_type` shall be a
|
| 5297 |
-
synonym for the return type of `T`;
|
| 5298 |
-
- if `T` is a class type with a member type `result_type`, then
|
| 5299 |
-
`result_type` shall be a synonym for `T::result_type`;
|
| 5300 |
-
- otherwise `result_type` shall not be defined.
|
| 5301 |
|
| 5302 |
Every call wrapper ([[func.def]]) shall be `MoveConstructible`. A
|
| 5303 |
-
*
|
| 5304 |
-
|
| 5305 |
-
|
| 5306 |
-
|
| 5307 |
-
|
| 5308 |
-
|
| 5309 |
-
|
| 5310 |
-
|
| 5311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5312 |
|
| 5313 |
``` cpp
|
| 5314 |
template<class... UnBoundArgs>
|
| 5315 |
R operator()(UnBoundArgs&&... unbound_args) cv-qual;
|
| 5316 |
```
|
| 5317 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5318 |
### Class template `reference_wrapper` <a id="refwrap">[[refwrap]]</a>
|
| 5319 |
|
| 5320 |
``` cpp
|
| 5321 |
namespace std {
|
| 5322 |
template <class T> class reference_wrapper {
|
| 5323 |
public :
|
| 5324 |
// types
|
| 5325 |
-
|
| 5326 |
-
typedef see below result_type; // not always defined
|
| 5327 |
-
typedef see below argument_type; // not always defined
|
| 5328 |
-
typedef see below first_argument_type; // not always defined
|
| 5329 |
-
typedef see below second_argument_type; // not always defined
|
| 5330 |
|
| 5331 |
// construct/copy/destroy
|
| 5332 |
reference_wrapper(T&) noexcept;
|
| 5333 |
reference_wrapper(T&&) = delete; // do not bind to temporary objects
|
| 5334 |
reference_wrapper(const reference_wrapper& x) noexcept;
|
|
@@ -5340,46 +9823,24 @@ namespace std {
|
|
| 5340 |
operator T& () const noexcept;
|
| 5341 |
T& get() const noexcept;
|
| 5342 |
|
| 5343 |
// invocation
|
| 5344 |
template <class... ArgTypes>
|
| 5345 |
-
|
| 5346 |
operator() (ArgTypes&&...) const;
|
| 5347 |
};
|
|
|
|
|
|
|
|
|
|
| 5348 |
}
|
| 5349 |
```
|
| 5350 |
|
| 5351 |
`reference_wrapper<T>` is a `CopyConstructible` and `CopyAssignable`
|
| 5352 |
wrapper around a reference to an object or function of type `T`.
|
| 5353 |
|
| 5354 |
-
`reference_wrapper<T>`
|
| 5355 |
-
|
| 5356 |
-
type of `T`.
|
| 5357 |
-
|
| 5358 |
-
The template specialization `reference_wrapper<T>` shall define a nested
|
| 5359 |
-
type named `argument_type` as a synonym for `T1` only if the type `T` is
|
| 5360 |
-
any of the following:
|
| 5361 |
-
|
| 5362 |
-
- a function type or a pointer to function type taking one argument of
|
| 5363 |
-
type `T1`
|
| 5364 |
-
- a pointer to member function `R T0::f` *cv* (where *cv* represents the
|
| 5365 |
-
member function’s cv-qualifiers); the type `T1` is *cv* `T0*`
|
| 5366 |
-
- a class type with a member type `argument_type`; the type `T1` is
|
| 5367 |
-
`T::argument_type`.
|
| 5368 |
-
|
| 5369 |
-
The template instantiation `reference_wrapper<T>` shall define two
|
| 5370 |
-
nested types named `first_argument_type` and `second_argument_type` as
|
| 5371 |
-
synonyms for `T1` and `T2`, respectively, only if the type `T` is any of
|
| 5372 |
-
the following:
|
| 5373 |
-
|
| 5374 |
-
- a function type or a pointer to function type taking two arguments of
|
| 5375 |
-
types `T1` and `T2`
|
| 5376 |
-
- a pointer to member function `R T0::f(T2)` *cv* (where *cv* represents
|
| 5377 |
-
the member function’s cv-qualifiers); the type `T1` is *cv* `T0*`
|
| 5378 |
-
- a class type with member types `first_argument_type` and
|
| 5379 |
-
`second_argument_type`; the type `T1` is `T::first_argument_type` and
|
| 5380 |
-
the type `T2` is `T::second_argument_type`.
|
| 5381 |
|
| 5382 |
#### `reference_wrapper` construct/copy/destroy <a id="refwrap.const">[[refwrap.const]]</a>
|
| 5383 |
|
| 5384 |
``` cpp
|
| 5385 |
reference_wrapper(T& t) noexcept;
|
|
@@ -5415,539 +9876,735 @@ operator T& () const noexcept;
|
|
| 5415 |
T& get() const noexcept;
|
| 5416 |
```
|
| 5417 |
|
| 5418 |
*Returns:* The stored reference.
|
| 5419 |
|
| 5420 |
-
#### reference_wrapper invocation <a id="refwrap.invoke">[[refwrap.invoke]]</a>
|
| 5421 |
|
| 5422 |
``` cpp
|
| 5423 |
template <class... ArgTypes>
|
| 5424 |
-
|
| 5425 |
operator()(ArgTypes&&... args) const;
|
| 5426 |
```
|
| 5427 |
|
| 5428 |
-
*Returns:*
|
| 5429 |
-
|
| 5430 |
|
| 5431 |
-
`
|
| 5432 |
-
required to provide an actual `reference_wrapper::operator()`.
|
| 5433 |
-
Implementations are permitted to support `reference_wrapper` function
|
| 5434 |
-
invocation through multiple overloaded operators or through other means.
|
| 5435 |
-
|
| 5436 |
-
#### reference_wrapper helper functions <a id="refwrap.helpers">[[refwrap.helpers]]</a>
|
| 5437 |
|
| 5438 |
``` cpp
|
| 5439 |
template <class T> reference_wrapper<T> ref(T& t) noexcept;
|
| 5440 |
```
|
| 5441 |
|
| 5442 |
-
*Returns:* `reference_wrapper<T>(t)`
|
| 5443 |
|
| 5444 |
``` cpp
|
| 5445 |
template <class T> reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;
|
| 5446 |
```
|
| 5447 |
|
| 5448 |
-
*Returns:* `ref(t.get())`
|
| 5449 |
|
| 5450 |
``` cpp
|
| 5451 |
template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
|
| 5452 |
```
|
| 5453 |
|
| 5454 |
-
*Returns:* `reference_wrapper <const T>(t)`
|
| 5455 |
|
| 5456 |
``` cpp
|
| 5457 |
template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
|
| 5458 |
```
|
| 5459 |
|
| 5460 |
-
*Returns:* `cref(t.get())
|
| 5461 |
|
| 5462 |
### Arithmetic operations <a id="arithmetic.operations">[[arithmetic.operations]]</a>
|
| 5463 |
|
| 5464 |
The library provides basic function object classes for all of the
|
| 5465 |
arithmetic operators in the language ([[expr.mul]], [[expr.add]]).
|
| 5466 |
|
|
|
|
|
|
|
| 5467 |
``` cpp
|
| 5468 |
template <class T = void> struct plus {
|
| 5469 |
constexpr T operator()(const T& x, const T& y) const;
|
| 5470 |
-
typedef T first_argument_type;
|
| 5471 |
-
typedef T second_argument_type;
|
| 5472 |
-
typedef T result_type;
|
| 5473 |
};
|
| 5474 |
```
|
| 5475 |
|
| 5476 |
-
`operator()` returns `x + y`.
|
| 5477 |
-
|
| 5478 |
-
``` cpp
|
| 5479 |
-
template <class T = void> struct minus {
|
| 5480 |
-
constexpr T operator()(const T& x, const T& y) const;
|
| 5481 |
-
typedef T first_argument_type;
|
| 5482 |
-
typedef T second_argument_type;
|
| 5483 |
-
typedef T result_type;
|
| 5484 |
-
};
|
| 5485 |
-
```
|
| 5486 |
-
|
| 5487 |
-
`operator()` returns `x - y`.
|
| 5488 |
-
|
| 5489 |
-
``` cpp
|
| 5490 |
-
template <class T = void> struct multiplies {
|
| 5491 |
-
constexpr T operator()(const T& x, const T& y) const;
|
| 5492 |
-
typedef T first_argument_type;
|
| 5493 |
-
typedef T second_argument_type;
|
| 5494 |
-
typedef T result_type;
|
| 5495 |
-
};
|
| 5496 |
-
```
|
| 5497 |
-
|
| 5498 |
-
`operator()` returns `x * y`.
|
| 5499 |
-
|
| 5500 |
``` cpp
|
| 5501 |
-
template <class T = void> struct divides {
|
| 5502 |
constexpr T operator()(const T& x, const T& y) const;
|
| 5503 |
-
typedef T first_argument_type;
|
| 5504 |
-
typedef T second_argument_type;
|
| 5505 |
-
typedef T result_type;
|
| 5506 |
-
};
|
| 5507 |
-
```
|
| 5508 |
-
|
| 5509 |
-
`operator()` returns `x / y`.
|
| 5510 |
-
|
| 5511 |
-
``` cpp
|
| 5512 |
-
template <class T = void> struct modulus {
|
| 5513 |
-
constexpr T operator()(const T& x, const T& y) const;
|
| 5514 |
-
typedef T first_argument_type;
|
| 5515 |
-
typedef T second_argument_type;
|
| 5516 |
-
typedef T result_type;
|
| 5517 |
-
};
|
| 5518 |
-
```
|
| 5519 |
-
|
| 5520 |
-
`operator()` returns `x % y`.
|
| 5521 |
-
|
| 5522 |
-
``` cpp
|
| 5523 |
-
template <class T = void> struct negate {
|
| 5524 |
-
constexpr T operator()(const T& x) const;
|
| 5525 |
-
typedef T argument_type;
|
| 5526 |
-
typedef T result_type;
|
| 5527 |
-
};
|
| 5528 |
```
|
| 5529 |
|
| 5530 |
-
`
|
| 5531 |
|
| 5532 |
``` cpp
|
| 5533 |
template <> struct plus<void> {
|
| 5534 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5535 |
-> decltype(std::forward<T>(t) + std::forward<U>(u));
|
| 5536 |
|
| 5537 |
-
|
| 5538 |
};
|
| 5539 |
```
|
| 5540 |
|
| 5541 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5542 |
|
| 5543 |
``` cpp
|
| 5544 |
template <> struct minus<void> {
|
| 5545 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5546 |
-> decltype(std::forward<T>(t) - std::forward<U>(u));
|
| 5547 |
|
| 5548 |
-
|
| 5549 |
};
|
| 5550 |
```
|
| 5551 |
|
| 5552 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5553 |
|
| 5554 |
``` cpp
|
| 5555 |
template <> struct multiplies<void> {
|
| 5556 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5557 |
-> decltype(std::forward<T>(t) * std::forward<U>(u));
|
| 5558 |
|
| 5559 |
-
|
| 5560 |
};
|
| 5561 |
```
|
| 5562 |
|
| 5563 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5564 |
|
| 5565 |
``` cpp
|
| 5566 |
template <> struct divides<void> {
|
| 5567 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5568 |
-> decltype(std::forward<T>(t) / std::forward<U>(u));
|
| 5569 |
|
| 5570 |
-
|
| 5571 |
};
|
| 5572 |
```
|
| 5573 |
|
| 5574 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5575 |
|
| 5576 |
``` cpp
|
| 5577 |
template <> struct modulus<void> {
|
| 5578 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5579 |
-> decltype(std::forward<T>(t) % std::forward<U>(u));
|
| 5580 |
|
| 5581 |
-
|
| 5582 |
};
|
| 5583 |
```
|
| 5584 |
|
| 5585 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5586 |
|
| 5587 |
``` cpp
|
| 5588 |
template <> struct negate<void> {
|
| 5589 |
template <class T> constexpr auto operator()(T&& t) const
|
| 5590 |
-> decltype(-std::forward<T>(t));
|
| 5591 |
|
| 5592 |
-
|
| 5593 |
};
|
| 5594 |
```
|
| 5595 |
|
| 5596 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5597 |
|
| 5598 |
### Comparisons <a id="comparisons">[[comparisons]]</a>
|
| 5599 |
|
| 5600 |
The library provides basic function object classes for all of the
|
| 5601 |
comparison operators in the language ([[expr.rel]], [[expr.eq]]).
|
| 5602 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5603 |
``` cpp
|
| 5604 |
template <class T = void> struct equal_to {
|
| 5605 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 5606 |
-
typedef T first_argument_type;
|
| 5607 |
-
typedef T second_argument_type;
|
| 5608 |
-
typedef bool result_type;
|
| 5609 |
};
|
| 5610 |
```
|
| 5611 |
|
| 5612 |
-
`operator()` returns `x == y`.
|
| 5613 |
-
|
| 5614 |
-
``` cpp
|
| 5615 |
-
template <class T = void> struct not_equal_to {
|
| 5616 |
-
constexpr bool operator()(const T& x, const T& y) const;
|
| 5617 |
-
typedef T first_argument_type;
|
| 5618 |
-
typedef T second_argument_type;
|
| 5619 |
-
typedef bool result_type;
|
| 5620 |
-
};
|
| 5621 |
-
```
|
| 5622 |
-
|
| 5623 |
-
`operator()` returns `x != y`.
|
| 5624 |
-
|
| 5625 |
-
``` cpp
|
| 5626 |
-
template <class T = void> struct greater {
|
| 5627 |
-
constexpr bool operator()(const T& x, const T& y) const;
|
| 5628 |
-
typedef T first_argument_type;
|
| 5629 |
-
typedef T second_argument_type;
|
| 5630 |
-
typedef bool result_type;
|
| 5631 |
-
};
|
| 5632 |
-
```
|
| 5633 |
-
|
| 5634 |
-
`operator()` returns `x > y`.
|
| 5635 |
-
|
| 5636 |
``` cpp
|
| 5637 |
-
template <class T = void> struct less {
|
| 5638 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 5639 |
-
typedef T first_argument_type;
|
| 5640 |
-
typedef T second_argument_type;
|
| 5641 |
-
typedef bool result_type;
|
| 5642 |
-
};
|
| 5643 |
-
```
|
| 5644 |
-
|
| 5645 |
-
`operator()` returns `x < y`.
|
| 5646 |
-
|
| 5647 |
-
``` cpp
|
| 5648 |
-
template <class T = void> struct greater_equal {
|
| 5649 |
-
constexpr bool operator()(const T& x, const T& y) const;
|
| 5650 |
-
typedef T first_argument_type;
|
| 5651 |
-
typedef T second_argument_type;
|
| 5652 |
-
typedef bool result_type;
|
| 5653 |
-
};
|
| 5654 |
-
```
|
| 5655 |
-
|
| 5656 |
-
`operator()` returns `x >= y`.
|
| 5657 |
-
|
| 5658 |
-
``` cpp
|
| 5659 |
-
template <class T = void> struct less_equal {
|
| 5660 |
-
constexpr bool operator()(const T& x, const T& y) const;
|
| 5661 |
-
typedef T first_argument_type;
|
| 5662 |
-
typedef T second_argument_type;
|
| 5663 |
-
typedef bool result_type;
|
| 5664 |
-
};
|
| 5665 |
```
|
| 5666 |
|
| 5667 |
-
|
| 5668 |
|
| 5669 |
``` cpp
|
| 5670 |
template <> struct equal_to<void> {
|
| 5671 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5672 |
-> decltype(std::forward<T>(t) == std::forward<U>(u));
|
| 5673 |
|
| 5674 |
-
|
| 5675 |
};
|
| 5676 |
```
|
| 5677 |
|
| 5678 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5679 |
|
| 5680 |
``` cpp
|
| 5681 |
template <> struct not_equal_to<void> {
|
| 5682 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5683 |
-> decltype(std::forward<T>(t) != std::forward<U>(u));
|
| 5684 |
|
| 5685 |
-
|
| 5686 |
};
|
| 5687 |
```
|
| 5688 |
|
| 5689 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5690 |
|
| 5691 |
``` cpp
|
| 5692 |
template <> struct greater<void> {
|
| 5693 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5694 |
-> decltype(std::forward<T>(t) > std::forward<U>(u));
|
| 5695 |
|
| 5696 |
-
|
| 5697 |
};
|
| 5698 |
```
|
| 5699 |
|
| 5700 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5701 |
|
| 5702 |
``` cpp
|
| 5703 |
template <> struct less<void> {
|
| 5704 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5705 |
-> decltype(std::forward<T>(t) < std::forward<U>(u));
|
| 5706 |
|
| 5707 |
-
|
| 5708 |
};
|
| 5709 |
```
|
| 5710 |
|
| 5711 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5712 |
|
| 5713 |
``` cpp
|
| 5714 |
template <> struct greater_equal<void> {
|
| 5715 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5716 |
-> decltype(std::forward<T>(t) >= std::forward<U>(u));
|
| 5717 |
|
| 5718 |
-
|
| 5719 |
};
|
| 5720 |
```
|
| 5721 |
|
| 5722 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5723 |
|
| 5724 |
``` cpp
|
| 5725 |
template <> struct less_equal<void> {
|
| 5726 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5727 |
-> decltype(std::forward<T>(t) <= std::forward<U>(u));
|
| 5728 |
|
| 5729 |
-
|
| 5730 |
};
|
| 5731 |
```
|
| 5732 |
|
| 5733 |
-
`
|
|
|
|
|
|
|
|
|
|
| 5734 |
|
| 5735 |
-
|
| 5736 |
-
specializations for any pointer type yield a total order, even if the
|
| 5737 |
-
built-in operators `<`, `>`, `<=`, `>=` do not.
|
| 5738 |
|
| 5739 |
### Logical operations <a id="logical.operations">[[logical.operations]]</a>
|
| 5740 |
|
| 5741 |
The library provides basic function object classes for all of the
|
| 5742 |
logical operators in the language ([[expr.log.and]], [[expr.log.or]],
|
| 5743 |
[[expr.unary.op]]).
|
| 5744 |
|
|
|
|
|
|
|
| 5745 |
``` cpp
|
| 5746 |
template <class T = void> struct logical_and {
|
| 5747 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 5748 |
-
typedef T first_argument_type;
|
| 5749 |
-
typedef T second_argument_type;
|
| 5750 |
-
typedef bool result_type;
|
| 5751 |
};
|
| 5752 |
```
|
| 5753 |
|
| 5754 |
-
`operator()` returns `x && y`.
|
| 5755 |
-
|
| 5756 |
``` cpp
|
| 5757 |
-
template <class T = void> struct logical_or {
|
| 5758 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 5759 |
-
typedef T first_argument_type;
|
| 5760 |
-
typedef T second_argument_type;
|
| 5761 |
-
typedef bool result_type;
|
| 5762 |
-
};
|
| 5763 |
```
|
| 5764 |
|
| 5765 |
-
|
| 5766 |
-
|
| 5767 |
-
``` cpp
|
| 5768 |
-
template <class T = void> struct logical_not {
|
| 5769 |
-
constexpr bool operator()(const T& x) const;
|
| 5770 |
-
typedef T argument_type;
|
| 5771 |
-
typedef bool result_type;
|
| 5772 |
-
};
|
| 5773 |
-
```
|
| 5774 |
-
|
| 5775 |
-
`operator()` returns `!x`.
|
| 5776 |
|
| 5777 |
``` cpp
|
| 5778 |
template <> struct logical_and<void> {
|
| 5779 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5780 |
-> decltype(std::forward<T>(t) && std::forward<U>(u));
|
| 5781 |
|
| 5782 |
-
|
| 5783 |
};
|
| 5784 |
```
|
| 5785 |
|
| 5786 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5787 |
|
| 5788 |
``` cpp
|
| 5789 |
template <> struct logical_or<void> {
|
| 5790 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5791 |
-> decltype(std::forward<T>(t) || std::forward<U>(u));
|
| 5792 |
|
| 5793 |
-
|
| 5794 |
};
|
| 5795 |
```
|
| 5796 |
|
| 5797 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5798 |
|
| 5799 |
``` cpp
|
| 5800 |
template <> struct logical_not<void> {
|
| 5801 |
template <class T> constexpr auto operator()(T&& t) const
|
| 5802 |
-> decltype(!std::forward<T>(t));
|
| 5803 |
|
| 5804 |
-
|
| 5805 |
};
|
| 5806 |
```
|
| 5807 |
|
| 5808 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5809 |
|
| 5810 |
### Bitwise operations <a id="bitwise.operations">[[bitwise.operations]]</a>
|
| 5811 |
|
| 5812 |
The library provides basic function object classes for all of the
|
| 5813 |
bitwise operators in the language ([[expr.bit.and]], [[expr.or]],
|
| 5814 |
[[expr.xor]], [[expr.unary.op]]).
|
| 5815 |
|
|
|
|
|
|
|
| 5816 |
``` cpp
|
| 5817 |
template <class T = void> struct bit_and {
|
| 5818 |
constexpr T operator()(const T& x, const T& y) const;
|
| 5819 |
-
typedef T first_argument_type;
|
| 5820 |
-
typedef T second_argument_type;
|
| 5821 |
-
typedef T result_type;
|
| 5822 |
};
|
| 5823 |
```
|
| 5824 |
|
| 5825 |
-
`operator()` returns `x & y`.
|
| 5826 |
-
|
| 5827 |
-
``` cpp
|
| 5828 |
-
template <class T = void> struct bit_or {
|
| 5829 |
-
constexpr T operator()(const T& x, const T& y) const;
|
| 5830 |
-
typedef T first_argument_type;
|
| 5831 |
-
typedef T second_argument_type;
|
| 5832 |
-
typedef T result_type;
|
| 5833 |
-
};
|
| 5834 |
-
```
|
| 5835 |
-
|
| 5836 |
-
`operator()` returns `x | y`.
|
| 5837 |
-
|
| 5838 |
``` cpp
|
| 5839 |
-
template <class T = void> struct bit_xor {
|
| 5840 |
constexpr T operator()(const T& x, const T& y) const;
|
| 5841 |
-
typedef T first_argument_type;
|
| 5842 |
-
typedef T second_argument_type;
|
| 5843 |
-
typedef T result_type;
|
| 5844 |
-
};
|
| 5845 |
-
```
|
| 5846 |
-
|
| 5847 |
-
`operator()` returns `x ^ y`.
|
| 5848 |
-
|
| 5849 |
-
``` cpp
|
| 5850 |
-
template <class T = void> struct bit_not {
|
| 5851 |
-
constexpr T operator()(const T& x) const;
|
| 5852 |
-
typedef T argument_type;
|
| 5853 |
-
typedef T result_type;
|
| 5854 |
-
};
|
| 5855 |
```
|
| 5856 |
|
| 5857 |
-
`
|
| 5858 |
|
| 5859 |
``` cpp
|
| 5860 |
template <> struct bit_and<void> {
|
| 5861 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5862 |
-> decltype(std::forward<T>(t) & std::forward<U>(u));
|
| 5863 |
|
| 5864 |
-
|
| 5865 |
};
|
| 5866 |
```
|
| 5867 |
|
| 5868 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5869 |
|
| 5870 |
``` cpp
|
| 5871 |
template <> struct bit_or<void> {
|
| 5872 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5873 |
-> decltype(std::forward<T>(t) | std::forward<U>(u));
|
| 5874 |
|
| 5875 |
-
|
| 5876 |
};
|
| 5877 |
```
|
| 5878 |
|
| 5879 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5880 |
|
| 5881 |
``` cpp
|
| 5882 |
template <> struct bit_xor<void> {
|
| 5883 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 5884 |
-> decltype(std::forward<T>(t) ^ std::forward<U>(u));
|
| 5885 |
|
| 5886 |
-
|
| 5887 |
};
|
| 5888 |
```
|
| 5889 |
|
| 5890 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5891 |
|
| 5892 |
``` cpp
|
| 5893 |
template <> struct bit_not<void> {
|
| 5894 |
template <class T> constexpr auto operator()(T&& t) const
|
| 5895 |
-> decltype(~std::forward<T>(t));
|
| 5896 |
|
| 5897 |
-
|
| 5898 |
};
|
| 5899 |
```
|
| 5900 |
|
| 5901 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5902 |
|
| 5903 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5904 |
|
| 5905 |
-
|
| 5906 |
-
|
|
|
|
| 5907 |
|
| 5908 |
``` cpp
|
| 5909 |
-
|
| 5910 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5911 |
public:
|
| 5912 |
-
|
| 5913 |
-
|
| 5914 |
-
|
| 5915 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5916 |
};
|
| 5917 |
```
|
| 5918 |
|
| 5919 |
-
`operator()` returns `!pred(x)`.
|
| 5920 |
-
|
| 5921 |
``` cpp
|
| 5922 |
-
|
| 5923 |
-
constexpr unary_negate<Predicate> not1(const Predicate& pred);
|
| 5924 |
```
|
| 5925 |
|
| 5926 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5927 |
|
| 5928 |
``` cpp
|
| 5929 |
-
template
|
| 5930 |
-
|
| 5931 |
-
|
| 5932 |
-
|
| 5933 |
-
|
| 5934 |
-
|
| 5935 |
-
typedef typename Predicate::first_argument_type first_argument_type;
|
| 5936 |
-
typedef typename Predicate::second_argument_type second_argument_type;
|
| 5937 |
-
typedef bool result_type;
|
| 5938 |
-
};
|
| 5939 |
```
|
| 5940 |
|
| 5941 |
-
|
| 5942 |
|
| 5943 |
``` cpp
|
| 5944 |
-
|
| 5945 |
-
constexpr binary_negate<Predicate> not2(const Predicate& pred);
|
| 5946 |
```
|
| 5947 |
|
| 5948 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5949 |
|
| 5950 |
### Function object binders <a id="func.bind">[[func.bind]]</a>
|
| 5951 |
|
| 5952 |
This subclause describes a uniform mechanism for binding arguments of
|
| 5953 |
callable objects.
|
|
@@ -5958,179 +10615,187 @@ callable objects.
|
|
| 5958 |
namespace std {
|
| 5959 |
template<class T> struct is_bind_expression; // see below
|
| 5960 |
}
|
| 5961 |
```
|
| 5962 |
|
| 5963 |
-
`is_bind_expression` can be used to detect function
|
| 5964 |
-
`bind`.
|
|
|
|
| 5965 |
|
| 5966 |
Instantiations of the `is_bind_expression` template shall meet the
|
| 5967 |
-
UnaryTypeTrait requirements ([[meta.rqmts]]). The implementation
|
| 5968 |
-
provide a definition that has a
|
| 5969 |
-
is a type returned from `bind`, otherwise it shall have a
|
| 5970 |
-
|
| 5971 |
-
|
| 5972 |
-
|
| 5973 |
-
|
| 5974 |
|
| 5975 |
#### Class template `is_placeholder` <a id="func.bind.isplace">[[func.bind.isplace]]</a>
|
| 5976 |
|
| 5977 |
``` cpp
|
| 5978 |
namespace std {
|
| 5979 |
template<class T> struct is_placeholder; // see below
|
| 5980 |
}
|
| 5981 |
```
|
| 5982 |
|
| 5983 |
-
`is_placeholder` can be used to detect the standard
|
| 5984 |
-
`_2`, and so on.
|
|
|
|
| 5985 |
|
| 5986 |
Instantiations of the `is_placeholder` template shall meet the
|
| 5987 |
-
UnaryTypeTrait requirements ([[meta.rqmts]]). The implementation
|
| 5988 |
-
provide a definition that has the
|
| 5989 |
`integral_constant<int, J>` if `T` is the type of
|
| 5990 |
-
`std::placeholders::_J`, otherwise it shall have a
|
| 5991 |
-
`integral_constant<int, 0>`. A program may specialize this template
|
| 5992 |
-
a user-defined type `T` to have a
|
| 5993 |
`integral_constant<int, N>` with `N > 0` to indicate that `T` should be
|
| 5994 |
treated as a placeholder type.
|
| 5995 |
|
| 5996 |
#### Function template `bind` <a id="func.bind.bind">[[func.bind.bind]]</a>
|
| 5997 |
|
| 5998 |
-
In the text that follows
|
| 5999 |
-
meanings:
|
| 6000 |
|
| 6001 |
- `FD` is the type `decay_t<F>`,
|
| 6002 |
- `fd` is an lvalue of type `FD` constructed from `std::forward<F>(f)`,
|
| 6003 |
-
- `
|
| 6004 |
-
- `
|
| 6005 |
-
- `
|
| 6006 |
-
- `
|
| 6007 |
-
`std::forward<
|
| 6008 |
-
- `
|
| 6009 |
the forwarding call wrapper, and
|
| 6010 |
-
- `
|
| 6011 |
|
| 6012 |
``` cpp
|
| 6013 |
template<class F, class... BoundArgs>
|
| 6014 |
unspecified bind(F&& f, BoundArgs&&... bound_args);
|
| 6015 |
```
|
| 6016 |
|
| 6017 |
-
*Requires:* `
|
| 6018 |
-
|
| 6019 |
-
*
|
| 6020 |
-
expression for some values
|
| 6021 |
-
`
|
|
|
|
| 6022 |
|
| 6023 |
-
*Returns:* A forwarding call wrapper `g`
|
| 6024 |
-
|
| 6025 |
-
|
| 6026 |
-
|
| 6027 |
-
|
| 6028 |
-
|
| 6029 |
-
|
| 6030 |
-
|
| 6031 |
-
|
|
|
|
|
|
|
|
|
|
| 6032 |
|
| 6033 |
*Throws:* Nothing unless the construction of `fd` or of one of the
|
| 6034 |
-
values `
|
| 6035 |
|
| 6036 |
*Remarks:* The return type shall satisfy the requirements of
|
| 6037 |
-
`MoveConstructible`. If all of `FD` and `
|
| 6038 |
of `CopyConstructible`, then the return type shall satisfy the
|
| 6039 |
-
requirements of `CopyConstructible`.
|
| 6040 |
-
|
|
|
|
|
|
|
| 6041 |
|
| 6042 |
``` cpp
|
| 6043 |
template<class R, class F, class... BoundArgs>
|
| 6044 |
unspecified bind(F&& f, BoundArgs&&... bound_args);
|
| 6045 |
```
|
| 6046 |
|
| 6047 |
-
*Requires:* `
|
| 6048 |
-
|
| 6049 |
-
*
|
| 6050 |
-
values
|
|
|
|
|
|
|
| 6051 |
|
| 6052 |
-
*Returns:* A forwarding call wrapper `g`
|
| 6053 |
-
`
|
| 6054 |
-
|
| 6055 |
-
|
| 6056 |
-
|
| 6057 |
-
|
| 6058 |
-
|
| 6059 |
-
the
|
| 6060 |
-
|
|
|
|
|
|
|
|
|
|
| 6061 |
|
| 6062 |
*Throws:* Nothing unless the construction of `fd` or of one of the
|
| 6063 |
-
values `
|
| 6064 |
|
| 6065 |
*Remarks:* The return type shall satisfy the requirements of
|
| 6066 |
-
`MoveConstructible`. If all of `FD` and `
|
| 6067 |
of `CopyConstructible`, then the return type shall satisfy the
|
| 6068 |
-
requirements of `CopyConstructible`.
|
| 6069 |
-
`TiD` are `MoveConstructible`.
|
| 6070 |
|
| 6071 |
-
|
| 6072 |
-
|
| 6073 |
-
from the call to `bind` and the *cv*-qualifiers *cv* of the call wrapper
|
| 6074 |
-
`g` as follows:
|
| 6075 |
|
| 6076 |
-
|
| 6077 |
-
|
| 6078 |
-
|
| 6079 |
-
|
| 6080 |
-
|
| 6081 |
-
- if
|
| 6082 |
-
|
| 6083 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6084 |
|
| 6085 |
#### Placeholders <a id="func.bind.place">[[func.bind.place]]</a>
|
| 6086 |
|
| 6087 |
``` cpp
|
| 6088 |
-
namespace std {
|
| 6089 |
-
namespace placeholders {
|
| 6090 |
// M is the implementation-defined number of placeholders
|
| 6091 |
-
|
| 6092 |
-
|
| 6093 |
.
|
| 6094 |
.
|
| 6095 |
.
|
| 6096 |
-
|
| 6097 |
-
}
|
| 6098 |
}
|
| 6099 |
```
|
| 6100 |
|
| 6101 |
All placeholder types shall be `DefaultConstructible` and
|
| 6102 |
`CopyConstructible`, and their default constructors and copy/move
|
| 6103 |
constructors shall not throw exceptions. It is *implementation-defined*
|
| 6104 |
whether placeholder types are `CopyAssignable`. `CopyAssignable`
|
| 6105 |
placeholders’ copy assignment operators shall not throw exceptions.
|
| 6106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6107 |
### Function template `mem_fn` <a id="func.memfn">[[func.memfn]]</a>
|
| 6108 |
|
| 6109 |
``` cpp
|
| 6110 |
-
template<class R, class T> unspecified mem_fn(R T::* pm);
|
| 6111 |
```
|
| 6112 |
|
| 6113 |
*Returns:* A simple call wrapper ([[func.def]]) `fn` such that the
|
| 6114 |
-
expression `fn(t, a2, ..., aN)` is equivalent to
|
| 6115 |
-
|
| 6116 |
-
nested type `result_type` that is a synonym for the return type of `pm`
|
| 6117 |
-
when `pm` is a pointer to member function.
|
| 6118 |
-
|
| 6119 |
-
The simple call wrapper shall define two nested types named
|
| 6120 |
-
`argument_type` and `result_type` as synonyms for `cv T*` and `Ret`,
|
| 6121 |
-
respectively, when `pm` is a pointer to member function with
|
| 6122 |
-
cv-qualifier *cv* and taking no arguments, where *Ret* is `pm`’s return
|
| 6123 |
-
type.
|
| 6124 |
-
|
| 6125 |
-
The simple call wrapper shall define three nested types named
|
| 6126 |
-
`first_argument_type`, `second_argument_type`, and `result_type` as
|
| 6127 |
-
synonyms for `cv T*`, `T1`, and `Ret`, respectively, when `pm` is a
|
| 6128 |
-
pointer to member function with cv-qualifier *cv* and taking one
|
| 6129 |
-
argument of type `T1`, where *Ret* is `pm`’s return type.
|
| 6130 |
-
|
| 6131 |
-
*Throws:* Nothing.
|
| 6132 |
|
| 6133 |
### Polymorphic function wrappers <a id="func.wrap">[[func.wrap]]</a>
|
| 6134 |
|
| 6135 |
This subclause describes a polymorphic wrapper class that encapsulates
|
| 6136 |
arbitrary callable objects.
|
|
@@ -6141,84 +10806,75 @@ An exception of type `bad_function_call` is thrown by
|
|
| 6141 |
`function::operator()` ([[func.wrap.func.inv]]) when the function
|
| 6142 |
wrapper object has no target.
|
| 6143 |
|
| 6144 |
``` cpp
|
| 6145 |
namespace std {
|
| 6146 |
-
class bad_function_call : public
|
| 6147 |
public:
|
| 6148 |
-
// [func.wrap.badcall.const], constructor
|
| 6149 |
bad_function_call() noexcept;
|
| 6150 |
};
|
| 6151 |
-
}
|
| 6152 |
```
|
| 6153 |
|
| 6154 |
##### `bad_function_call` constructor <a id="func.wrap.badcall.const">[[func.wrap.badcall.const]]</a>
|
| 6155 |
|
| 6156 |
``` cpp
|
| 6157 |
bad_function_call() noexcept;
|
| 6158 |
```
|
| 6159 |
|
| 6160 |
-
*Effects:*
|
|
|
|
|
|
|
| 6161 |
|
| 6162 |
#### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
|
| 6163 |
|
| 6164 |
``` cpp
|
| 6165 |
namespace std {
|
| 6166 |
-
template<class> class function; //
|
| 6167 |
|
| 6168 |
template<class R, class... ArgTypes>
|
| 6169 |
class function<R(ArgTypes...)> {
|
| 6170 |
public:
|
| 6171 |
-
|
| 6172 |
-
typedef T1 argument_type; // only if sizeof...(ArgTypes) == 1 and
|
| 6173 |
-
// the type in ArgTypes is T1
|
| 6174 |
-
typedef T1 first_argument_type; // only if sizeof...(ArgTypes) == 2 and
|
| 6175 |
-
// ArgTypes contains T1 and T2
|
| 6176 |
-
typedef T2 second_argument_type; // only if sizeof...(ArgTypes) == 2 and
|
| 6177 |
-
// ArgTypes contains T1 and T2
|
| 6178 |
|
| 6179 |
-
// [func.wrap.func.con], construct/copy/destroy
|
| 6180 |
function() noexcept;
|
| 6181 |
function(nullptr_t) noexcept;
|
| 6182 |
function(const function&);
|
| 6183 |
function(function&&);
|
| 6184 |
template<class F> function(F);
|
| 6185 |
-
template<class A> function(allocator_arg_t, const A&) noexcept;
|
| 6186 |
-
template<class A> function(allocator_arg_t, const A&,
|
| 6187 |
-
nullptr_t) noexcept;
|
| 6188 |
-
template<class A> function(allocator_arg_t, const A&,
|
| 6189 |
-
const function&);
|
| 6190 |
-
template<class A> function(allocator_arg_t, const A&,
|
| 6191 |
-
function&&);
|
| 6192 |
-
template<class F, class A> function(allocator_arg_t, const A&, F);
|
| 6193 |
|
| 6194 |
function& operator=(const function&);
|
| 6195 |
function& operator=(function&&);
|
| 6196 |
-
function& operator=(nullptr_t);
|
| 6197 |
template<class F> function& operator=(F&&);
|
| 6198 |
template<class F> function& operator=(reference_wrapper<F>) noexcept;
|
| 6199 |
|
| 6200 |
~function();
|
| 6201 |
|
| 6202 |
-
// [func.wrap.func.mod], function modifiers
|
| 6203 |
void swap(function&) noexcept;
|
| 6204 |
-
template<class F, class A> void assign(F&&, const A&);
|
| 6205 |
|
| 6206 |
-
// [func.wrap.func.cap], function capacity
|
| 6207 |
explicit operator bool() const noexcept;
|
| 6208 |
|
| 6209 |
-
// [func.wrap.func.inv], function invocation
|
| 6210 |
R operator()(ArgTypes...) const;
|
| 6211 |
|
| 6212 |
-
// [func.wrap.func.targ], function target access
|
| 6213 |
-
const
|
| 6214 |
template<class T> T* target() noexcept;
|
| 6215 |
template<class T> const T* target() const noexcept;
|
| 6216 |
-
|
| 6217 |
};
|
| 6218 |
|
| 6219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6220 |
template <class R, class... ArgTypes>
|
| 6221 |
bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
|
| 6222 |
|
| 6223 |
template <class R, class... ArgTypes>
|
| 6224 |
bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
|
|
@@ -6227,154 +10883,176 @@ namespace std {
|
|
| 6227 |
bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
|
| 6228 |
|
| 6229 |
template <class R, class... ArgTypes>
|
| 6230 |
bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
|
| 6231 |
|
| 6232 |
-
// [func.wrap.func.alg], specialized algorithms
|
| 6233 |
template <class R, class... ArgTypes>
|
| 6234 |
-
void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
|
| 6235 |
-
|
| 6236 |
-
template<class R, class... ArgTypes, class Alloc>
|
| 6237 |
-
struct uses_allocator<function<R(ArgTypes...)>, Alloc>
|
| 6238 |
-
: true_type { };
|
| 6239 |
}
|
| 6240 |
```
|
| 6241 |
|
| 6242 |
The `function` class template provides polymorphic wrappers that
|
| 6243 |
generalize the notion of a function pointer. Wrappers can store, copy,
|
| 6244 |
and call arbitrary callable objects ([[func.def]]), given a call
|
| 6245 |
signature ([[func.def]]), allowing functions to be first-class objects.
|
| 6246 |
|
| 6247 |
-
A callable
|
| 6248 |
-
`ArgTypes` and return type `R` if the expression
|
| 6249 |
-
`INVOKE(
|
| 6250 |
-
operand (Clause [[expr]]), is well formed (
|
|
|
|
| 6251 |
|
| 6252 |
The `function` class template is a call wrapper ([[func.def]]) whose
|
| 6253 |
call signature ([[func.def]]) is `R(ArgTypes...)`.
|
| 6254 |
|
|
|
|
|
|
|
|
|
|
| 6255 |
##### `function` construct/copy/destroy <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
|
| 6256 |
|
| 6257 |
-
When any `function` constructor that takes a first argument of type
|
| 6258 |
-
`allocator_arg_t` is invoked, the second argument shall have a type that
|
| 6259 |
-
conforms to the requirements for Allocator (Table
|
| 6260 |
-
[[allocator.requirements]]). A copy of the allocator argument is used to
|
| 6261 |
-
allocate memory, if necessary, for the internal data structures of the
|
| 6262 |
-
constructed `function` object.
|
| 6263 |
-
|
| 6264 |
``` cpp
|
| 6265 |
function() noexcept;
|
| 6266 |
-
template <class A> function(allocator_arg_t, const A& a) noexcept;
|
| 6267 |
```
|
| 6268 |
|
| 6269 |
*Postconditions:* `!*this`.
|
| 6270 |
|
| 6271 |
``` cpp
|
| 6272 |
function(nullptr_t) noexcept;
|
| 6273 |
-
template <class A> function(allocator_arg_t, const A& a, nullptr_t) noexcept;
|
| 6274 |
```
|
| 6275 |
|
| 6276 |
*Postconditions:* `!*this`.
|
| 6277 |
|
| 6278 |
``` cpp
|
| 6279 |
function(const function& f);
|
| 6280 |
-
template <class A> function(allocator_arg_t, const A& a, const function& f);
|
| 6281 |
```
|
| 6282 |
|
| 6283 |
*Postconditions:* `!*this` if `!f`; otherwise, `*this` targets a copy of
|
| 6284 |
`f.target()`.
|
| 6285 |
|
| 6286 |
-
*Throws:* shall not throw exceptions if `f`’s target is a
|
| 6287 |
-
|
| 6288 |
-
|
| 6289 |
-
|
| 6290 |
-
|
| 6291 |
-
|
| 6292 |
-
|
|
|
|
|
|
|
| 6293 |
|
| 6294 |
``` cpp
|
| 6295 |
function(function&& f);
|
| 6296 |
-
template <class A> function(allocator_arg_t, const A& a, function&& f);
|
| 6297 |
```
|
| 6298 |
|
| 6299 |
-
*
|
| 6300 |
-
|
| 6301 |
-
state with an unspecified value.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6302 |
|
| 6303 |
``` cpp
|
| 6304 |
template<class F> function(F f);
|
| 6305 |
-
template <class F, class A> function(allocator_arg_t, const A& a, F f);
|
| 6306 |
```
|
| 6307 |
|
| 6308 |
*Requires:* `F` shall be `CopyConstructible`.
|
| 6309 |
|
| 6310 |
-
*Remarks:*
|
| 6311 |
-
resolution unless `
|
| 6312 |
-
types `ArgTypes...` and return type `R`.
|
| 6313 |
|
| 6314 |
*Postconditions:* `!*this` if any of the following hold:
|
| 6315 |
|
| 6316 |
- `f` is a null function pointer value.
|
| 6317 |
- `f` is a null member pointer value.
|
| 6318 |
- `F` is an instance of the `function` class template, and `!f`.
|
| 6319 |
|
| 6320 |
Otherwise, `*this` targets a copy of `f` initialized with
|
| 6321 |
-
`std::move(f)`.
|
|
|
|
|
|
|
| 6322 |
dynamically allocated memory for small callable objects, for example,
|
| 6323 |
-
where `f`
|
| 6324 |
-
|
| 6325 |
|
| 6326 |
*Throws:* shall not throw exceptions when `f` is a function pointer or a
|
| 6327 |
`reference_wrapper<T>` for some `T`. Otherwise, may throw `bad_alloc` or
|
| 6328 |
any exception thrown by `F`’s copy or move constructor.
|
| 6329 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6330 |
``` cpp
|
| 6331 |
function& operator=(const function& f);
|
| 6332 |
```
|
| 6333 |
|
| 6334 |
-
*Effects:* `function(f).swap(*this);`
|
| 6335 |
|
| 6336 |
-
*Returns:* `*this`
|
| 6337 |
|
| 6338 |
``` cpp
|
| 6339 |
function& operator=(function&& f);
|
| 6340 |
```
|
| 6341 |
|
| 6342 |
*Effects:* Replaces the target of `*this` with the target of `f`.
|
| 6343 |
|
| 6344 |
-
*Returns:* `*this`
|
| 6345 |
|
| 6346 |
``` cpp
|
| 6347 |
-
function& operator=(nullptr_t);
|
| 6348 |
```
|
| 6349 |
|
| 6350 |
*Effects:* If `*this != nullptr`, destroys the target of `this`.
|
| 6351 |
|
| 6352 |
*Postconditions:* `!(*this)`.
|
| 6353 |
|
| 6354 |
-
*Returns:* `*this`
|
| 6355 |
|
| 6356 |
``` cpp
|
| 6357 |
template<class F> function& operator=(F&& f);
|
| 6358 |
```
|
| 6359 |
|
| 6360 |
-
*Effects:* `function(std::forward<F>(f)).swap(*this);`
|
| 6361 |
|
| 6362 |
-
*Returns:* `*this`
|
| 6363 |
|
| 6364 |
*Remarks:* This assignment operator shall not participate in overload
|
| 6365 |
-
resolution unless `
|
| 6366 |
-
|
| 6367 |
-
return type `R`.
|
| 6368 |
|
| 6369 |
``` cpp
|
| 6370 |
template<class F> function& operator=(reference_wrapper<F> f) noexcept;
|
| 6371 |
```
|
| 6372 |
|
| 6373 |
-
*Effects:* `function(f).swap(*this);`
|
| 6374 |
|
| 6375 |
-
*Returns:* `*this`
|
| 6376 |
|
| 6377 |
``` cpp
|
| 6378 |
~function();
|
| 6379 |
```
|
| 6380 |
|
|
@@ -6386,17 +11064,10 @@ template<class F> function& operator=(reference_wrapper<F> f) noexcept;
|
|
| 6386 |
void swap(function& other) noexcept;
|
| 6387 |
```
|
| 6388 |
|
| 6389 |
*Effects:* interchanges the targets of `*this` and `other`.
|
| 6390 |
|
| 6391 |
-
``` cpp
|
| 6392 |
-
template<class F, class A>
|
| 6393 |
-
void assign(F&& f, const A& a);
|
| 6394 |
-
```
|
| 6395 |
-
|
| 6396 |
-
*Effects:* `function(allocator_arg, a, std::forward<F>(f)).swap(*this)`
|
| 6397 |
-
|
| 6398 |
##### `function` capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
|
| 6399 |
|
| 6400 |
``` cpp
|
| 6401 |
explicit operator bool() const noexcept;
|
| 6402 |
```
|
|
@@ -6404,44 +11075,38 @@ explicit operator bool() const noexcept;
|
|
| 6404 |
*Returns:* `true` if `*this` has a target, otherwise `false`.
|
| 6405 |
|
| 6406 |
##### `function` invocation <a id="func.wrap.func.inv">[[func.wrap.func.inv]]</a>
|
| 6407 |
|
| 6408 |
``` cpp
|
| 6409 |
-
R operator()(ArgTypes... args) const
|
| 6410 |
```
|
| 6411 |
|
| 6412 |
-
*
|
| 6413 |
-
|
| 6414 |
-
|
| 6415 |
-
|
| 6416 |
-
*Returns:* Nothing if `R` is `void`, otherwise the return value of
|
| 6417 |
-
*`INVOKE`*`(f, std::forward<ArgTypes>(args)..., R)`.
|
| 6418 |
|
| 6419 |
*Throws:* `bad_function_call` if `!*this`; otherwise, any exception
|
| 6420 |
thrown by the wrapped callable object.
|
| 6421 |
|
| 6422 |
-
##### function target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
|
| 6423 |
|
| 6424 |
``` cpp
|
| 6425 |
-
const
|
| 6426 |
```
|
| 6427 |
|
| 6428 |
*Returns:* If `*this` has a target of type `T`, `typeid(T)`; otherwise,
|
| 6429 |
`typeid(void)`.
|
| 6430 |
|
| 6431 |
``` cpp
|
| 6432 |
template<class T> T* target() noexcept;
|
| 6433 |
template<class T> const T* target() const noexcept;
|
| 6434 |
```
|
| 6435 |
|
| 6436 |
-
*Requires:* `T` shall be a type that is Callable ([[func.wrap.func]])
|
| 6437 |
-
for parameter types `ArgTypes` and return type `R`.
|
| 6438 |
-
|
| 6439 |
*Returns:* If `target_type() == typeid(T)` a pointer to the stored
|
| 6440 |
function target; otherwise a null pointer.
|
| 6441 |
|
| 6442 |
-
##### null pointer comparison
|
| 6443 |
|
| 6444 |
``` cpp
|
| 6445 |
template <class R, class... ArgTypes>
|
| 6446 |
bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
|
| 6447 |
template <class R, class... ArgTypes>
|
|
@@ -6461,63 +11126,290 @@ template <class R, class... ArgTypes>
|
|
| 6461 |
|
| 6462 |
##### specialized algorithms <a id="func.wrap.func.alg">[[func.wrap.func.alg]]</a>
|
| 6463 |
|
| 6464 |
``` cpp
|
| 6465 |
template<class R, class... ArgTypes>
|
| 6466 |
-
void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2);
|
| 6467 |
```
|
| 6468 |
|
| 6469 |
-
*Effects:* `f1.swap(f2);`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6470 |
|
| 6471 |
### Class template `hash` <a id="unord.hash">[[unord.hash]]</a>
|
| 6472 |
|
| 6473 |
The unordered associative containers defined in [[unord]] use
|
| 6474 |
-
specializations of the class template `hash`
|
| 6475 |
-
|
| 6476 |
-
|
| 6477 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6478 |
|
| 6479 |
- satisfy the `Hash` requirements ([[hash.requirements]]), with `Key`
|
| 6480 |
as the function call argument type, the `DefaultConstructible`
|
| 6481 |
-
requirements (Table [[defaultconstructible]]), the
|
| 6482 |
-
requirements (Table [[copyassignable]]),
|
| 6483 |
- be swappable ([[swappable.requirements]]) for lvalues,
|
| 6484 |
-
-
|
| 6485 |
-
|
| 6486 |
-
|
| 6487 |
-
is also true, where `h` is an object of type `hash<Key>` and `k1` and
|
| 6488 |
-
`k2` are objects of type `Key`;
|
| 6489 |
- satisfy the requirement that the expression `h(k)`, where `h` is an
|
| 6490 |
object of type `hash<Key>` and `k` is an object of type `Key`, shall
|
| 6491 |
not throw an exception unless `hash<Key>` is a user-defined
|
| 6492 |
specialization that depends on at least one user-defined type.
|
| 6493 |
|
| 6494 |
-
``` cpp
|
| 6495 |
-
template <> struct hash<bool>;
|
| 6496 |
-
template <> struct hash<char>;
|
| 6497 |
-
template <> struct hash<signed char>;
|
| 6498 |
-
template <> struct hash<unsigned char>;
|
| 6499 |
-
template <> struct hash<char16_t>;
|
| 6500 |
-
template <> struct hash<char32_t>;
|
| 6501 |
-
template <> struct hash<wchar_t>;
|
| 6502 |
-
template <> struct hash<short>;
|
| 6503 |
-
template <> struct hash<unsigned short>;
|
| 6504 |
-
template <> struct hash<int>;
|
| 6505 |
-
template <> struct hash<unsigned int>;
|
| 6506 |
-
template <> struct hash<long>;
|
| 6507 |
-
template <> struct hash<unsigned long>;
|
| 6508 |
-
template <> struct hash<long long>;
|
| 6509 |
-
template <> struct hash<unsigned long long>;
|
| 6510 |
-
template <> struct hash<float>;
|
| 6511 |
-
template <> struct hash<double>;
|
| 6512 |
-
template <> struct hash<long double>;
|
| 6513 |
-
template <class T> struct hash<T*>;
|
| 6514 |
-
```
|
| 6515 |
-
|
| 6516 |
-
The template specializations shall meet the requirements of class
|
| 6517 |
-
template `hash` ([[unord.hash]]).
|
| 6518 |
-
|
| 6519 |
## Metaprogramming and type traits <a id="meta">[[meta]]</a>
|
| 6520 |
|
| 6521 |
This subclause describes components used by C++programs, particularly in
|
| 6522 |
templates, to support the widest possible range of types, optimise
|
| 6523 |
template code usage, detect type related user errors, and perform type
|
|
@@ -6528,35 +11420,38 @@ taxonomy of all possible C++types, and state where in that taxonomy a
|
|
| 6528 |
given type belongs. The type property inspection traits allow important
|
| 6529 |
characteristics of types or of combinations of types to be inspected.
|
| 6530 |
The type transformations allow certain properties of types to be
|
| 6531 |
manipulated.
|
| 6532 |
|
|
|
|
|
|
|
|
|
|
| 6533 |
### Requirements <a id="meta.rqmts">[[meta.rqmts]]</a>
|
| 6534 |
|
| 6535 |
A *UnaryTypeTrait* describes a property of a type. It shall be a class
|
| 6536 |
template that takes one template type argument and, optionally,
|
| 6537 |
additional arguments that help define the property being described. It
|
| 6538 |
shall be `DefaultConstructible`, `CopyConstructible`, and publicly and
|
| 6539 |
-
unambiguously derived, directly or indirectly, from its
|
| 6540 |
-
*
|
| 6541 |
`integral_constant` ([[meta.help]]), with the arguments to the template
|
| 6542 |
`integral_constant` determined by the requirements for the particular
|
| 6543 |
-
property being described. The member names of the
|
| 6544 |
shall not be hidden and shall be unambiguously available in the
|
| 6545 |
-
UnaryTypeTrait.
|
| 6546 |
|
| 6547 |
A *BinaryTypeTrait* describes a relationship between two types. It shall
|
| 6548 |
be a class template that takes two template type arguments and,
|
| 6549 |
optionally, additional arguments that help define the relationship being
|
| 6550 |
described. It shall be `DefaultConstructible`, `CopyConstructible`, and
|
| 6551 |
publicly and unambiguously derived, directly or indirectly, from its
|
| 6552 |
-
*
|
| 6553 |
`integral_constant` ([[meta.help]]), with the arguments to the template
|
| 6554 |
`integral_constant` determined by the requirements for the particular
|
| 6555 |
-
relationship being described. The member names of the
|
| 6556 |
-
shall not be hidden and shall be unambiguously available
|
| 6557 |
-
BinaryTypeTrait.
|
| 6558 |
|
| 6559 |
A *TransformationTrait* modifies a property of a type. It shall be a
|
| 6560 |
class template that takes one template type argument and, optionally,
|
| 6561 |
additional arguments that help define the modification. It shall define
|
| 6562 |
a publicly accessible nested type named `type`, which shall be a synonym
|
|
@@ -6564,16 +11459,19 @@ for the modified type.
|
|
| 6564 |
|
| 6565 |
### Header `<type_traits>` synopsis <a id="meta.type.synop">[[meta.type.synop]]</a>
|
| 6566 |
|
| 6567 |
``` cpp
|
| 6568 |
namespace std {
|
| 6569 |
-
// [meta.help], helper class
|
| 6570 |
template <class T, T v> struct integral_constant;
|
| 6571 |
-
typedef integral_constant<bool, true> true_type;
|
| 6572 |
-
typedef integral_constant<bool, false> false_type;
|
| 6573 |
|
| 6574 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6575 |
template <class T> struct is_void;
|
| 6576 |
template <class T> struct is_null_pointer;
|
| 6577 |
template <class T> struct is_integral;
|
| 6578 |
template <class T> struct is_floating_point;
|
| 6579 |
template <class T> struct is_array;
|
|
@@ -6585,31 +11483,31 @@ namespace std {
|
|
| 6585 |
template <class T> struct is_enum;
|
| 6586 |
template <class T> struct is_union;
|
| 6587 |
template <class T> struct is_class;
|
| 6588 |
template <class T> struct is_function;
|
| 6589 |
|
| 6590 |
-
// [meta.unary.comp], composite type categories
|
| 6591 |
template <class T> struct is_reference;
|
| 6592 |
template <class T> struct is_arithmetic;
|
| 6593 |
template <class T> struct is_fundamental;
|
| 6594 |
template <class T> struct is_object;
|
| 6595 |
template <class T> struct is_scalar;
|
| 6596 |
template <class T> struct is_compound;
|
| 6597 |
template <class T> struct is_member_pointer;
|
| 6598 |
|
| 6599 |
-
// [meta.unary.prop], type properties
|
| 6600 |
template <class T> struct is_const;
|
| 6601 |
template <class T> struct is_volatile;
|
| 6602 |
template <class T> struct is_trivial;
|
| 6603 |
template <class T> struct is_trivially_copyable;
|
| 6604 |
template <class T> struct is_standard_layout;
|
| 6605 |
template <class T> struct is_pod;
|
| 6606 |
-
template <class T> struct is_literal_type;
|
| 6607 |
template <class T> struct is_empty;
|
| 6608 |
template <class T> struct is_polymorphic;
|
| 6609 |
template <class T> struct is_abstract;
|
| 6610 |
template <class T> struct is_final;
|
|
|
|
| 6611 |
|
| 6612 |
template <class T> struct is_signed;
|
| 6613 |
template <class T> struct is_unsigned;
|
| 6614 |
|
| 6615 |
template <class T, class... Args> struct is_constructible;
|
|
@@ -6619,10 +11517,13 @@ namespace std {
|
|
| 6619 |
|
| 6620 |
template <class T, class U> struct is_assignable;
|
| 6621 |
template <class T> struct is_copy_assignable;
|
| 6622 |
template <class T> struct is_move_assignable;
|
| 6623 |
|
|
|
|
|
|
|
|
|
|
| 6624 |
template <class T> struct is_destructible;
|
| 6625 |
|
| 6626 |
template <class T, class... Args> struct is_trivially_constructible;
|
| 6627 |
template <class T> struct is_trivially_default_constructible;
|
| 6628 |
template <class T> struct is_trivially_copy_constructible;
|
|
@@ -6640,24 +11541,36 @@ namespace std {
|
|
| 6640 |
|
| 6641 |
template <class T, class U> struct is_nothrow_assignable;
|
| 6642 |
template <class T> struct is_nothrow_copy_assignable;
|
| 6643 |
template <class T> struct is_nothrow_move_assignable;
|
| 6644 |
|
|
|
|
|
|
|
|
|
|
| 6645 |
template <class T> struct is_nothrow_destructible;
|
|
|
|
| 6646 |
template <class T> struct has_virtual_destructor;
|
| 6647 |
|
| 6648 |
-
|
|
|
|
|
|
|
| 6649 |
template <class T> struct alignment_of;
|
| 6650 |
template <class T> struct rank;
|
| 6651 |
template <class T, unsigned I = 0> struct extent;
|
| 6652 |
|
| 6653 |
-
// [meta.rel], type relations
|
| 6654 |
template <class T, class U> struct is_same;
|
| 6655 |
template <class Base, class Derived> struct is_base_of;
|
| 6656 |
template <class From, class To> struct is_convertible;
|
| 6657 |
|
| 6658 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6659 |
template <class T> struct remove_const;
|
| 6660 |
template <class T> struct remove_volatile;
|
| 6661 |
template <class T> struct remove_cv;
|
| 6662 |
template <class T> struct add_const;
|
| 6663 |
template <class T> struct add_volatile;
|
|
@@ -6674,11 +11587,11 @@ namespace std {
|
|
| 6674 |
template <class T>
|
| 6675 |
using add_volatile_t = typename add_volatile<T>::type;
|
| 6676 |
template <class T>
|
| 6677 |
using add_cv_t = typename add_cv<T>::type;
|
| 6678 |
|
| 6679 |
-
// [meta.trans.ref], reference modifications
|
| 6680 |
template <class T> struct remove_reference;
|
| 6681 |
template <class T> struct add_lvalue_reference;
|
| 6682 |
template <class T> struct add_rvalue_reference;
|
| 6683 |
|
| 6684 |
template <class T>
|
|
@@ -6686,54 +11599,53 @@ namespace std {
|
|
| 6686 |
template <class T>
|
| 6687 |
using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;
|
| 6688 |
template <class T>
|
| 6689 |
using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;
|
| 6690 |
|
| 6691 |
-
// [meta.trans.sign], sign modifications
|
| 6692 |
template <class T> struct make_signed;
|
| 6693 |
template <class T> struct make_unsigned;
|
| 6694 |
|
| 6695 |
template <class T>
|
| 6696 |
using make_signed_t = typename make_signed<T>::type;
|
| 6697 |
template <class T>
|
| 6698 |
using make_unsigned_t = typename make_unsigned<T>::type;
|
| 6699 |
|
| 6700 |
-
// [meta.trans.arr], array modifications
|
| 6701 |
template <class T> struct remove_extent;
|
| 6702 |
template <class T> struct remove_all_extents;
|
| 6703 |
|
| 6704 |
template <class T>
|
| 6705 |
using remove_extent_t = typename remove_extent<T>::type;
|
| 6706 |
template <class T>
|
| 6707 |
using remove_all_extents_t = typename remove_all_extents<T>::type;
|
| 6708 |
|
| 6709 |
-
// [meta.trans.ptr], pointer modifications
|
| 6710 |
template <class T> struct remove_pointer;
|
| 6711 |
template <class T> struct add_pointer;
|
| 6712 |
|
| 6713 |
template <class T>
|
| 6714 |
using remove_pointer_t = typename remove_pointer<T>::type;
|
| 6715 |
template <class T>
|
| 6716 |
using add_pointer_t = typename add_pointer<T>::type;
|
| 6717 |
|
| 6718 |
-
// [meta.trans.other], other transformations
|
| 6719 |
-
template <
|
| 6720 |
-
|
| 6721 |
struct aligned_storage;
|
| 6722 |
-
template <
|
| 6723 |
template <class T> struct decay;
|
| 6724 |
template <bool, class T = void> struct enable_if;
|
| 6725 |
template <bool, class T, class F> struct conditional;
|
| 6726 |
template <class... T> struct common_type;
|
| 6727 |
template <class T> struct underlying_type;
|
| 6728 |
-
template <class
|
| 6729 |
-
template <class F, class... ArgTypes> class result_of<F(ArgTypes...)>;
|
| 6730 |
|
| 6731 |
-
template <
|
| 6732 |
-
|
| 6733 |
using aligned_storage_t = typename aligned_storage<Len, Align>::type;
|
| 6734 |
-
template <
|
| 6735 |
using aligned_union_t = typename aligned_union<Len, Types...>::type;
|
| 6736 |
template <class T>
|
| 6737 |
using decay_t = typename decay<T>::type;
|
| 6738 |
template <bool b, class T = void>
|
| 6739 |
using enable_if_t = typename enable_if<b, T>::type;
|
|
@@ -6741,316 +11653,688 @@ namespace std {
|
|
| 6741 |
using conditional_t = typename conditional<b, T, F>::type;
|
| 6742 |
template <class... T>
|
| 6743 |
using common_type_t = typename common_type<T...>::type;
|
| 6744 |
template <class T>
|
| 6745 |
using underlying_type_t = typename underlying_type<T>::type;
|
| 6746 |
-
template <class
|
| 6747 |
-
using
|
| 6748 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6749 |
```
|
| 6750 |
|
| 6751 |
-
The behavior of a program that adds specializations for any of the
|
| 6752 |
templates defined in this subclause is undefined unless otherwise
|
| 6753 |
specified.
|
| 6754 |
|
|
|
|
|
|
|
|
|
|
| 6755 |
### Helper classes <a id="meta.help">[[meta.help]]</a>
|
| 6756 |
|
| 6757 |
``` cpp
|
| 6758 |
namespace std {
|
| 6759 |
template <class T, T v>
|
| 6760 |
struct integral_constant {
|
| 6761 |
static constexpr T value = v;
|
| 6762 |
-
|
| 6763 |
-
|
| 6764 |
constexpr operator value_type() const noexcept { return value; }
|
| 6765 |
constexpr value_type operator()() const noexcept { return value; }
|
| 6766 |
};
|
| 6767 |
-
typedef integral_constant<bool, true> true_type;
|
| 6768 |
-
typedef integral_constant<bool, false> false_type;
|
| 6769 |
}
|
| 6770 |
```
|
| 6771 |
|
| 6772 |
-
The class template `integral_constant`
|
| 6773 |
-
`true_type` and `false_type` are used
|
| 6774 |
-
interface for various type traits.
|
| 6775 |
|
| 6776 |
### Unary type traits <a id="meta.unary">[[meta.unary]]</a>
|
| 6777 |
|
| 6778 |
-
This
|
| 6779 |
properties of a type at compile time.
|
| 6780 |
|
| 6781 |
-
Each of these templates shall be a UnaryTypeTrait ([[meta.rqmts]])
|
| 6782 |
-
a
|
| 6783 |
-
true, otherwise `false_type`.
|
| 6784 |
|
| 6785 |
#### Primary type categories <a id="meta.unary.cat">[[meta.unary.cat]]</a>
|
| 6786 |
|
| 6787 |
The primary type categories correspond to the descriptions given in
|
| 6788 |
section [[basic.types]] of the C++standard.
|
| 6789 |
|
| 6790 |
For any given type `T`, the result of applying one of these templates to
|
| 6791 |
-
`T` and to
|
| 6792 |
|
| 6793 |
-
For any given type `T`, exactly one of the primary type
|
| 6794 |
-
`value` member that evaluates to `true`.
|
| 6795 |
|
| 6796 |
#### Composite type traits <a id="meta.unary.comp">[[meta.unary.comp]]</a>
|
| 6797 |
|
| 6798 |
These templates provide convenient compositions of the primary type
|
| 6799 |
categories, corresponding to the descriptions given in section
|
| 6800 |
[[basic.types]].
|
| 6801 |
|
| 6802 |
For any given type `T`, the result of applying one of these templates to
|
| 6803 |
-
`T`
|
| 6804 |
|
| 6805 |
#### Type properties <a id="meta.unary.prop">[[meta.unary.prop]]</a>
|
| 6806 |
|
| 6807 |
These templates provide access to some of the more important properties
|
| 6808 |
of types.
|
| 6809 |
|
| 6810 |
It is unspecified whether the library defines any full or partial
|
| 6811 |
specializations of any of these templates.
|
| 6812 |
|
| 6813 |
-
For all of the class templates `X` declared in this
|
| 6814 |
instantiating that template with a template-argument that is a class
|
| 6815 |
template specialization may result in the implicit instantiation of the
|
| 6816 |
template argument if and only if the semantics of `X` require that the
|
| 6817 |
argument must be a complete type.
|
| 6818 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6819 |
``` cpp
|
| 6820 |
-
|
| 6821 |
-
|
| 6822 |
-
|
| 6823 |
-
|
| 6824 |
-
|
| 6825 |
```
|
| 6826 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6827 |
``` cpp
|
| 6828 |
remove_const_t<const volatile int> // volatile int
|
| 6829 |
remove_const_t<const int* const> // const int*
|
| 6830 |
remove_const_t<const int&> // const int&
|
| 6831 |
remove_const_t<const int[3]> // int[3]
|
| 6832 |
```
|
| 6833 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6834 |
``` cpp
|
| 6835 |
// Given:
|
| 6836 |
struct P final { };
|
| 6837 |
union U1 { };
|
| 6838 |
union U2 final { };
|
| 6839 |
|
| 6840 |
// the following assertions hold:
|
| 6841 |
-
static_assert(!
|
| 6842 |
-
static_assert(
|
| 6843 |
-
static_assert(!
|
| 6844 |
-
static_assert(
|
| 6845 |
```
|
| 6846 |
|
| 6847 |
-
|
| 6848 |
|
| 6849 |
-
|
| 6850 |
-
template <class T>
|
| 6851 |
-
add_rvalue_reference_t<T> create() noexcept;
|
| 6852 |
-
```
|
| 6853 |
-
|
| 6854 |
-
the predicate condition for a template specialization
|
| 6855 |
`is_constructible<T, Args...>` shall be satisfied if and only if the
|
| 6856 |
following variable definition would be well-formed for some invented
|
| 6857 |
variable `t`:
|
| 6858 |
|
| 6859 |
``` cpp
|
| 6860 |
-
T t(
|
| 6861 |
```
|
| 6862 |
|
| 6863 |
-
These tokens are never interpreted as a function
|
| 6864 |
-
|
| 6865 |
-
|
| 6866 |
-
|
| 6867 |
-
|
| 6868 |
-
|
| 6869 |
-
|
| 6870 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6871 |
|
| 6872 |
### Type property queries <a id="meta.unary.prop.query">[[meta.unary.prop.query]]</a>
|
| 6873 |
|
| 6874 |
-
This
|
| 6875 |
of types at compile time.
|
| 6876 |
|
| 6877 |
Each of these templates shall be a `UnaryTypeTrait` ([[meta.rqmts]])
|
| 6878 |
-
with a
|
|
|
|
|
|
|
| 6879 |
|
| 6880 |
``` cpp
|
| 6881 |
// the following assertions hold:
|
| 6882 |
-
assert(
|
| 6883 |
-
assert(
|
| 6884 |
-
assert(
|
| 6885 |
```
|
| 6886 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6887 |
``` cpp
|
| 6888 |
// the following assertions hold:
|
| 6889 |
-
assert(
|
| 6890 |
-
assert(
|
| 6891 |
-
assert(
|
| 6892 |
-
assert(
|
| 6893 |
-
assert((
|
| 6894 |
-
assert((
|
| 6895 |
-
assert((
|
| 6896 |
-
assert((
|
| 6897 |
```
|
| 6898 |
|
|
|
|
|
|
|
| 6899 |
### Relationships between types <a id="meta.rel">[[meta.rel]]</a>
|
| 6900 |
|
| 6901 |
-
This
|
| 6902 |
relationships between types at compile time.
|
| 6903 |
|
| 6904 |
-
Each of these templates shall be a BinaryTypeTrait ([[meta.rqmts]])
|
| 6905 |
-
with a
|
| 6906 |
is true, otherwise `false_type`.
|
| 6907 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6908 |
``` cpp
|
| 6909 |
struct B {};
|
| 6910 |
struct B1 : B {};
|
| 6911 |
struct B2 : B {};
|
| 6912 |
struct D : private B1, private B2 {};
|
| 6913 |
|
| 6914 |
-
|
| 6915 |
-
|
| 6916 |
-
|
| 6917 |
-
|
| 6918 |
-
|
| 6919 |
-
|
| 6920 |
-
|
| 6921 |
-
|
| 6922 |
```
|
| 6923 |
|
| 6924 |
-
|
| 6925 |
|
| 6926 |
-
|
| 6927 |
-
template <class T>
|
| 6928 |
-
add_rvalue_reference_t<T> create() noexcept;
|
| 6929 |
-
```
|
| 6930 |
-
|
| 6931 |
-
the predicate condition for a template specialization
|
| 6932 |
`is_convertible<From, To>` shall be satisfied if and only if the return
|
| 6933 |
expression in the following code would be well-formed, including any
|
| 6934 |
implicit conversions to the return type of the function:
|
| 6935 |
|
| 6936 |
``` cpp
|
| 6937 |
To test() {
|
| 6938 |
-
return
|
| 6939 |
}
|
| 6940 |
```
|
| 6941 |
|
| 6942 |
-
This requirement gives well defined results for reference
|
| 6943 |
-
types, array types, and function types.
|
| 6944 |
-
|
| 6945 |
-
|
| 6946 |
-
|
| 6947 |
-
|
| 6948 |
-
|
| 6949 |
-
|
| 6950 |
-
|
| 6951 |
-
|
|
|
|
|
|
|
|
|
|
| 6952 |
|
| 6953 |
### Transformations between types <a id="meta.trans">[[meta.trans]]</a>
|
| 6954 |
|
| 6955 |
-
This
|
| 6956 |
-
|
| 6957 |
|
| 6958 |
Each of the templates in this subclause shall be a
|
| 6959 |
-
|
| 6960 |
|
| 6961 |
#### Const-volatile modifications <a id="meta.trans.cv">[[meta.trans.cv]]</a>
|
| 6962 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6963 |
#### Reference modifications <a id="meta.trans.ref">[[meta.trans.ref]]</a>
|
| 6964 |
|
|
|
|
|
|
|
|
|
|
| 6965 |
#### Sign modifications <a id="meta.trans.sign">[[meta.trans.sign]]</a>
|
| 6966 |
|
| 6967 |
#### Array modifications <a id="meta.trans.arr">[[meta.trans.arr]]</a>
|
| 6968 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6969 |
``` cpp
|
| 6970 |
// the following assertions hold:
|
| 6971 |
-
assert((
|
| 6972 |
-
assert((
|
| 6973 |
-
assert((
|
| 6974 |
-
assert((
|
| 6975 |
```
|
| 6976 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6977 |
``` cpp
|
| 6978 |
// the following assertions hold:
|
| 6979 |
-
assert((
|
| 6980 |
-
assert((
|
| 6981 |
-
assert((
|
| 6982 |
-
assert((
|
| 6983 |
```
|
| 6984 |
|
|
|
|
|
|
|
| 6985 |
#### Pointer modifications <a id="meta.trans.ptr">[[meta.trans.ptr]]</a>
|
| 6986 |
|
| 6987 |
#### Other transformations <a id="meta.trans.other">[[meta.trans.other]]</a>
|
| 6988 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6989 |
A typical implementation would define `aligned_storage` as:
|
| 6990 |
|
| 6991 |
``` cpp
|
| 6992 |
-
template <
|
| 6993 |
struct aligned_storage {
|
| 6994 |
typedef struct {
|
| 6995 |
alignas(Alignment) unsigned char __data[Len];
|
| 6996 |
} type;
|
| 6997 |
};
|
| 6998 |
```
|
| 6999 |
|
|
|
|
|
|
|
| 7000 |
It is *implementation-defined* whether any extended alignment is
|
| 7001 |
supported ([[basic.align]]).
|
| 7002 |
|
| 7003 |
-
|
|
|
|
|
|
|
| 7004 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7005 |
``` cpp
|
| 7006 |
-
|
| 7007 |
-
|
| 7008 |
-
template <class T>
|
| 7009 |
-
struct common_type<T> {
|
| 7010 |
-
typedef decay_t<T> type;
|
| 7011 |
-
};
|
| 7012 |
-
|
| 7013 |
-
template <class T, class U>
|
| 7014 |
-
struct common_type<T, U> {
|
| 7015 |
-
typedef decay_t<decltype(true ? declval<T>() : declval<U>())> type;
|
| 7016 |
-
};
|
| 7017 |
-
|
| 7018 |
-
template <class T, class U, class... V>
|
| 7019 |
-
struct common_type<T, U, V...> {
|
| 7020 |
-
typedef common_type_t<common_type_t<T, U>, V...> type;
|
| 7021 |
-
};
|
| 7022 |
```
|
| 7023 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7024 |
Given these definitions:
|
| 7025 |
|
| 7026 |
``` cpp
|
| 7027 |
-
|
| 7028 |
-
|
| 7029 |
|
| 7030 |
struct S {
|
| 7031 |
operator PF2() const;
|
| 7032 |
double operator()(char, int&);
|
| 7033 |
void fn(long) const;
|
| 7034 |
char data;
|
| 7035 |
};
|
| 7036 |
|
| 7037 |
-
|
| 7038 |
-
|
| 7039 |
```
|
| 7040 |
|
| 7041 |
the following assertions will hold:
|
| 7042 |
|
| 7043 |
``` cpp
|
| 7044 |
-
static_assert(
|
| 7045 |
-
static_assert(
|
| 7046 |
-
static_assert(
|
| 7047 |
-
static_assert(
|
| 7048 |
-
static_assert(
|
| 7049 |
-
static_assert(
|
| 7050 |
```
|
| 7051 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7052 |
## Compile-time rational arithmetic <a id="ratio">[[ratio]]</a>
|
| 7053 |
|
| 7054 |
### In general <a id="ratio.general">[[ratio.general]]</a>
|
| 7055 |
|
| 7056 |
This subclause describes the ratio library. It provides a class template
|
|
@@ -7082,31 +12366,44 @@ namespace std {
|
|
| 7082 |
template <class R1, class R2> struct ratio_less;
|
| 7083 |
template <class R1, class R2> struct ratio_less_equal;
|
| 7084 |
template <class R1, class R2> struct ratio_greater;
|
| 7085 |
template <class R1, class R2> struct ratio_greater_equal;
|
| 7086 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7087 |
// [ratio.si], convenience SI typedefs
|
| 7088 |
-
|
| 7089 |
-
|
| 7090 |
-
|
| 7091 |
-
|
| 7092 |
-
|
| 7093 |
-
|
| 7094 |
-
|
| 7095 |
-
|
| 7096 |
-
|
| 7097 |
-
|
| 7098 |
-
|
| 7099 |
-
|
| 7100 |
-
|
| 7101 |
-
|
| 7102 |
-
|
| 7103 |
-
|
| 7104 |
-
|
| 7105 |
-
|
| 7106 |
-
|
| 7107 |
-
|
| 7108 |
}
|
| 7109 |
```
|
| 7110 |
|
| 7111 |
### Class template `ratio` <a id="ratio.ratio">[[ratio.ratio]]</a>
|
| 7112 |
|
|
@@ -7115,21 +12412,23 @@ namespace std {
|
|
| 7115 |
template <intmax_t N, intmax_t D = 1>
|
| 7116 |
class ratio {
|
| 7117 |
public:
|
| 7118 |
static constexpr intmax_t num;
|
| 7119 |
static constexpr intmax_t den;
|
| 7120 |
-
|
| 7121 |
};
|
| 7122 |
}
|
| 7123 |
```
|
| 7124 |
|
| 7125 |
If the template argument `D` is zero or the absolute values of either of
|
| 7126 |
the template arguments `N` and `D` is not representable by type
|
| 7127 |
-
`intmax_t`, the program is ill-formed.
|
| 7128 |
-
|
| 7129 |
-
|
| 7130 |
-
|
|
|
|
|
|
|
| 7131 |
|
| 7132 |
The static data members `num` and `den` shall have the following values,
|
| 7133 |
where `gcd` represents the greatest common divisor of the absolute
|
| 7134 |
values of `N` and `D`:
|
| 7135 |
|
|
@@ -7162,10 +12461,12 @@ yields correct values of `U` and `V`.
|
|
| 7162 |
| | `R2::num * R1::den` | |
|
| 7163 |
| `ratio_multiply<R1, R2>` | `R1::num * R2::num` | `R1::den * R2::den` |
|
| 7164 |
| `ratio_divide<R1, R2>` | `R1::num * R2::den` | `R1::den * R2::num` |
|
| 7165 |
|
| 7166 |
|
|
|
|
|
|
|
| 7167 |
``` cpp
|
| 7168 |
static_assert(ratio_add<ratio<1, 3>, ratio<1, 6>>::num == 1, "1/3+1/6 == 1/2");
|
| 7169 |
static_assert(ratio_add<ratio<1, 3>, ratio<1, 6>>::den == 2, "1/3+1/6 == 1/2");
|
| 7170 |
static_assert(ratio_multiply<ratio<1, 3>, ratio<3, 2>>::num == 1, "1/3*3/2 == 1/2");
|
| 7171 |
static_assert(ratio_multiply<ratio<1, 3>, ratio<3, 2>>::den == 2, "1/3*3/2 == 1/2");
|
|
@@ -7179,102 +12480,102 @@ static_assert(ratio_multiply<ratio<1,INT_MAX>, ratio<INT_MAX,2>>::num == 1,
|
|
| 7179 |
"1/MAX * MAX/2 == 1/2");
|
| 7180 |
static_assert(ratio_multiply<ratio<1, INT_MAX>, ratio<INT_MAX, 2>>::den == 2,
|
| 7181 |
"1/MAX * MAX/2 == 1/2");
|
| 7182 |
```
|
| 7183 |
|
|
|
|
|
|
|
| 7184 |
### Comparison of `ratio`s <a id="ratio.comparison">[[ratio.comparison]]</a>
|
| 7185 |
|
| 7186 |
``` cpp
|
| 7187 |
-
template <class R1, class R2>
|
| 7188 |
-
:
|
| 7189 |
```
|
| 7190 |
|
| 7191 |
-
If `R1::num == R2::num` and `R1::den == R2::den`, `ratio_equal<R1, R2>`
|
| 7192 |
-
shall be derived from
|
| 7193 |
-
`integral_constant<bool, true>`; otherwise it shall be derived from
|
| 7194 |
-
`integral_constant<bool, false>`.
|
| 7195 |
-
|
| 7196 |
``` cpp
|
| 7197 |
-
template <class R1, class R2>
|
| 7198 |
-
:
|
| 7199 |
```
|
| 7200 |
|
| 7201 |
``` cpp
|
| 7202 |
-
template <class R1, class R2>
|
| 7203 |
-
:
|
| 7204 |
```
|
| 7205 |
|
| 7206 |
-
If `R1::num
|
| 7207 |
-
be derived from `
|
| 7208 |
-
derived from `
|
| 7209 |
-
other algorithms to compute this relationship to
|
| 7210 |
-
overflow occurs, the program is ill-formed.
|
| 7211 |
|
| 7212 |
``` cpp
|
| 7213 |
-
template <class R1, class R2>
|
| 7214 |
-
:
|
| 7215 |
```
|
| 7216 |
|
| 7217 |
``` cpp
|
| 7218 |
-
template <class R1, class R2>
|
| 7219 |
-
:
|
| 7220 |
```
|
| 7221 |
|
| 7222 |
``` cpp
|
| 7223 |
-
template <class R1, class R2>
|
| 7224 |
-
:
|
| 7225 |
```
|
| 7226 |
|
| 7227 |
### SI types for `ratio` <a id="ratio.si">[[ratio.si]]</a>
|
| 7228 |
|
| 7229 |
-
For each of the
|
| 7230 |
-
of the constants used in its specification are representable by
|
| 7231 |
`intmax_t`, the typedef shall be defined; if either of the constants is
|
| 7232 |
not representable by `intmax_t`, the typedef shall not be defined.
|
| 7233 |
|
| 7234 |
## Time utilities <a id="time">[[time]]</a>
|
| 7235 |
|
| 7236 |
### In general <a id="time.general">[[time.general]]</a>
|
| 7237 |
|
| 7238 |
This subclause describes the chrono library ([[time.syn]]) and various
|
| 7239 |
-
C functions ([[
|
| 7240 |
utilities.
|
| 7241 |
|
| 7242 |
### Header `<chrono>` synopsis <a id="time.syn">[[time.syn]]</a>
|
| 7243 |
|
| 7244 |
``` cpp
|
| 7245 |
namespace std {
|
| 7246 |
namespace chrono {
|
| 7247 |
-
|
| 7248 |
// [time.duration], class template duration
|
| 7249 |
template <class Rep, class Period = ratio<1>> class duration;
|
| 7250 |
|
| 7251 |
// [time.point], class template time_point
|
| 7252 |
template <class Clock, class Duration = typename Clock::duration> class time_point;
|
|
|
|
| 7253 |
|
| 7254 |
-
|
| 7255 |
-
|
| 7256 |
-
// [time.traits.specializations] common_type specializations
|
| 7257 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7258 |
-
|
|
|
|
| 7259 |
|
| 7260 |
template <class Clock, class Duration1, class Duration2>
|
| 7261 |
-
|
|
|
|
| 7262 |
|
| 7263 |
namespace chrono {
|
| 7264 |
-
|
| 7265 |
// [time.traits], customization traits
|
| 7266 |
template <class Rep> struct treat_as_floating_point;
|
| 7267 |
template <class Rep> struct duration_values;
|
|
|
|
|
|
|
| 7268 |
|
| 7269 |
// [time.duration.nonmember], duration arithmetic
|
| 7270 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7271 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 7272 |
-
|
|
|
|
| 7273 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7274 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 7275 |
-
|
|
|
|
| 7276 |
template <class Rep1, class Period, class Rep2>
|
| 7277 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 7278 |
constexpr operator*(const duration<Rep1, Period>& d, const Rep2& s);
|
| 7279 |
template <class Rep1, class Rep2, class Period>
|
| 7280 |
duration<common_type_t<Rep1, Rep2>, Period>
|
|
@@ -7282,17 +12583,19 @@ template <class Rep1, class Rep2, class Period>
|
|
| 7282 |
template <class Rep1, class Period, class Rep2>
|
| 7283 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 7284 |
constexpr operator/(const duration<Rep1, Period>& d, const Rep2& s);
|
| 7285 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7286 |
common_type_t<Rep1, Rep2>
|
| 7287 |
-
|
|
|
|
| 7288 |
template <class Rep1, class Period, class Rep2>
|
| 7289 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 7290 |
constexpr operator%(const duration<Rep1, Period>& d, const Rep2& s);
|
| 7291 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7292 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 7293 |
-
|
|
|
|
| 7294 |
|
| 7295 |
// [time.duration.comparisons], duration comparisons
|
| 7296 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7297 |
constexpr bool operator==(const duration<Rep1, Period1>& lhs,
|
| 7298 |
const duration<Rep2, Period2>& rhs);
|
|
@@ -7313,34 +12616,44 @@ template <class Rep1, class Period1, class Rep2, class Period2>
|
|
| 7313 |
const duration<Rep2, Period2>& rhs);
|
| 7314 |
|
| 7315 |
// [time.duration.cast], duration_cast
|
| 7316 |
template <class ToDuration, class Rep, class Period>
|
| 7317 |
constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7318 |
|
| 7319 |
// convenience typedefs
|
| 7320 |
-
|
| 7321 |
-
|
| 7322 |
-
|
| 7323 |
-
|
| 7324 |
-
|
| 7325 |
-
|
| 7326 |
|
| 7327 |
// [time.point.nonmember], time_point arithmetic
|
| 7328 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 7329 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 7330 |
-
|
|
|
|
| 7331 |
template <class Rep1, class Period1, class Clock, class Duration2>
|
| 7332 |
constexpr time_point<Clock, common_type_t<duration<Rep1, Period1>, Duration2>>
|
| 7333 |
-
|
|
|
|
| 7334 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 7335 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 7336 |
-
|
|
|
|
| 7337 |
template <class Clock, class Duration1, class Duration2>
|
| 7338 |
constexpr common_type_t<Duration1, Duration2>
|
| 7339 |
-
|
|
|
|
| 7340 |
|
| 7341 |
-
// [time.point.comparisons] time_point comparisons
|
| 7342 |
template <class Clock, class Duration1, class Duration2>
|
| 7343 |
constexpr bool operator==(const time_point<Clock, Duration1>& lhs,
|
| 7344 |
const time_point<Clock, Duration2>& rhs);
|
| 7345 |
template <class Clock, class Duration1, class Duration2>
|
| 7346 |
constexpr bool operator!=(const time_point<Clock, Duration1>& lhs,
|
|
@@ -7360,22 +12673,33 @@ template <class Clock, class Duration1, class Duration2>
|
|
| 7360 |
|
| 7361 |
// [time.point.cast], time_point_cast
|
| 7362 |
template <class ToDuration, class Clock, class Duration>
|
| 7363 |
constexpr time_point<Clock, ToDuration>
|
| 7364 |
time_point_cast(const time_point<Clock, Duration>& t);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7365 |
|
| 7366 |
// [time.clock], clocks
|
| 7367 |
class system_clock;
|
| 7368 |
class steady_clock;
|
| 7369 |
class high_resolution_clock;
|
| 7370 |
-
|
| 7371 |
-
} // namespace chrono
|
| 7372 |
|
| 7373 |
inline namespace literals {
|
| 7374 |
inline namespace chrono_literals {
|
| 7375 |
-
|
| 7376 |
-
// ~[time.duration.literals], suffixes for duration literals
|
| 7377 |
constexpr chrono::hours operator""h(unsigned long long);
|
| 7378 |
constexpr chrono::duration<unspecified, ratio<3600,1>> operator""h(long double);
|
| 7379 |
constexpr chrono::minutes operator""min(unsigned long long);
|
| 7380 |
constexpr chrono::duration<unspecified, ratio<60,1>> operator""min(long double);
|
| 7381 |
constexpr chrono::seconds operator""s(unsigned long long);
|
|
@@ -7384,21 +12708,17 @@ constexpr chrono::milliseconds operator "" ms(unsigned
|
|
| 7384 |
constexpr chrono::duration<unspecified, milli> operator""ms(long double);
|
| 7385 |
constexpr chrono::microseconds operator""us(unsigned long long);
|
| 7386 |
constexpr chrono::duration<unspecified, micro> operator""us(long double);
|
| 7387 |
constexpr chrono::nanoseconds operator""ns(unsigned long long);
|
| 7388 |
constexpr chrono::duration<unspecified, nano> operator""ns(long double);
|
| 7389 |
-
|
| 7390 |
-
|
| 7391 |
-
} // namespace literals
|
| 7392 |
|
| 7393 |
namespace chrono {
|
| 7394 |
-
|
| 7395 |
using namespace literals::chrono_literals;
|
| 7396 |
-
|
| 7397 |
-
}
|
| 7398 |
-
|
| 7399 |
-
} // namespace std
|
| 7400 |
```
|
| 7401 |
|
| 7402 |
### Clock requirements <a id="time.clock.req">[[time.clock.req]]</a>
|
| 7403 |
|
| 7404 |
A clock is a bundle consisting of a `duration`, a `time_point`, and a
|
|
@@ -7407,29 +12727,32 @@ clock’s `time_point` is referred to as the clock’s *epoch*. A clock
|
|
| 7407 |
shall meet the requirements in Table [[tab:time.clock]].
|
| 7408 |
|
| 7409 |
In Table [[tab:time.clock]] `C1` and `C2` denote clock types. `t1` and
|
| 7410 |
`t2` are values returned by `C1::now()` where the call returning `t1`
|
| 7411 |
happens before ([[intro.multithread]]) the call returning `t2` and both
|
| 7412 |
-
of these calls occur before `C1::time_point::max()`.
|
| 7413 |
-
not wrap around between `t1` and `t2`.
|
| 7414 |
|
| 7415 |
-
|
| 7416 |
-
|
| 7417 |
-
|
|
|
|
|
|
|
|
|
|
| 7418 |
|
| 7419 |
A type `TC` meets the `TrivialClock` requirements if:
|
| 7420 |
|
| 7421 |
- `TC` satisfies the `Clock` requirements ([[time.clock.req]]),
|
| 7422 |
- the types `TC::rep`, `TC::duration`, and `TC::time_point` satisfy the
|
| 7423 |
-
requirements of `EqualityComparable` (Table
|
| 7424 |
-
|
| 7425 |
-
|
| 7426 |
-
|
| 7427 |
-
|
|
|
|
| 7428 |
and the requirements of numeric types ([[numeric.requirements]]).
|
| 7429 |
-
|
| 7430 |
-
throw exceptions.
|
| 7431 |
- lvalues of the types `TC::rep`, `TC::duration`, and `TC::time_point`
|
| 7432 |
are swappable ([[swappable.requirements]]),
|
| 7433 |
- the function `TC::now()` does not throw exceptions, and
|
| 7434 |
- the type `TC::time_point::clock` meets the `TrivialClock`
|
| 7435 |
requirements, recursively.
|
|
@@ -7443,19 +12766,21 @@ template <class Rep> struct treat_as_floating_point
|
|
| 7443 |
: is_floating_point<Rep> { };
|
| 7444 |
```
|
| 7445 |
|
| 7446 |
The `duration` template uses the `treat_as_floating_point` trait to help
|
| 7447 |
determine if a `duration` object can be converted to another `duration`
|
| 7448 |
-
with a different tick `period`. If `
|
| 7449 |
-
|
| 7450 |
Otherwise, the implicit convertibility depends on the tick `period`s of
|
| 7451 |
-
the `duration`s.
|
| 7452 |
-
|
| 7453 |
-
|
| 7454 |
-
|
| 7455 |
-
|
| 7456 |
-
|
|
|
|
|
|
|
| 7457 |
|
| 7458 |
#### `duration_values` <a id="time.traits.duration_values">[[time.traits.duration_values]]</a>
|
| 7459 |
|
| 7460 |
``` cpp
|
| 7461 |
template <class Rep>
|
|
@@ -7476,57 +12801,62 @@ that case, the author of that class type should specialize
|
|
| 7476 |
|
| 7477 |
``` cpp
|
| 7478 |
static constexpr Rep zero();
|
| 7479 |
```
|
| 7480 |
|
| 7481 |
-
*Returns:* `Rep(0)`.
|
| 7482 |
-
`Rep()` may have some other meaning, such as an uninitialized value.
|
| 7483 |
|
| 7484 |
-
|
|
|
|
|
|
|
|
|
|
| 7485 |
|
| 7486 |
``` cpp
|
| 7487 |
static constexpr Rep min();
|
| 7488 |
```
|
| 7489 |
|
| 7490 |
*Returns:* `numeric_limits<Rep>::lowest()`.
|
| 7491 |
|
| 7492 |
-
The value returned shall compare less than or equal to
|
|
|
|
| 7493 |
|
| 7494 |
``` cpp
|
| 7495 |
static constexpr Rep max();
|
| 7496 |
```
|
| 7497 |
|
| 7498 |
*Returns:* `numeric_limits<Rep>::max()`.
|
| 7499 |
|
| 7500 |
-
The value returned shall compare greater than `zero()`.
|
| 7501 |
|
| 7502 |
#### Specializations of `common_type` <a id="time.traits.specializations">[[time.traits.specializations]]</a>
|
| 7503 |
|
| 7504 |
``` cpp
|
| 7505 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7506 |
struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>> {
|
| 7507 |
-
|
| 7508 |
};
|
| 7509 |
```
|
| 7510 |
|
| 7511 |
The `period` of the `duration` indicated by this specialization of
|
| 7512 |
`common_type` shall be the greatest common divisor of `Period1` and
|
| 7513 |
-
`Period2`.
|
|
|
|
|
|
|
| 7514 |
common divisor of `Period1::num` and `Period2::num` and the least common
|
| 7515 |
-
multiple of `Period1::den` and `Period2::den`.
|
| 7516 |
|
| 7517 |
-
The `typedef` name `type` is a synonym for the `duration`
|
| 7518 |
-
largest tick `period` possible where both `duration` arguments
|
| 7519 |
-
convert to it without requiring a division operation. The
|
| 7520 |
-
of this type is intended to be able to hold any value
|
| 7521 |
-
this conversion with no truncation error, although
|
| 7522 |
-
durations may have round-off errors.
|
| 7523 |
|
| 7524 |
``` cpp
|
| 7525 |
template <class Clock, class Duration1, class Duration2>
|
| 7526 |
struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>> {
|
| 7527 |
-
|
| 7528 |
};
|
| 7529 |
```
|
| 7530 |
|
| 7531 |
The common type of two `time_point` types is a `time_point` with the
|
| 7532 |
same clock as the two types and the common type of their two
|
|
@@ -7542,119 +12872,129 @@ as a rational constant using the template `ratio`.
|
|
| 7542 |
|
| 7543 |
``` cpp
|
| 7544 |
template <class Rep, class Period = ratio<1>>
|
| 7545 |
class duration {
|
| 7546 |
public:
|
| 7547 |
-
|
| 7548 |
-
|
| 7549 |
private:
|
| 7550 |
rep rep_; // exposition only
|
| 7551 |
public:
|
| 7552 |
-
// [time.duration.cons], construct/copy/destroy
|
| 7553 |
constexpr duration() = default;
|
| 7554 |
template <class Rep2>
|
| 7555 |
constexpr explicit duration(const Rep2& r);
|
| 7556 |
template <class Rep2, class Period2>
|
| 7557 |
constexpr duration(const duration<Rep2, Period2>& d);
|
| 7558 |
~duration() = default;
|
| 7559 |
duration(const duration&) = default;
|
| 7560 |
duration& operator=(const duration&) = default;
|
| 7561 |
|
| 7562 |
-
// [time.duration.observer], observer
|
| 7563 |
constexpr rep count() const;
|
| 7564 |
|
| 7565 |
-
// [time.duration.arithmetic], arithmetic
|
| 7566 |
-
constexpr duration
|
| 7567 |
-
constexpr duration
|
| 7568 |
-
duration& operator++();
|
| 7569 |
-
duration operator++(int);
|
| 7570 |
-
duration& operator--();
|
| 7571 |
-
duration operator--(int);
|
| 7572 |
|
| 7573 |
-
duration& operator+=(const duration& d);
|
| 7574 |
-
duration& operator-=(const duration& d);
|
| 7575 |
|
| 7576 |
-
duration& operator*=(const rep& rhs);
|
| 7577 |
-
duration& operator/=(const rep& rhs);
|
| 7578 |
-
duration& operator%=(const rep& rhs);
|
| 7579 |
-
duration& operator%=(const duration& rhs);
|
| 7580 |
|
| 7581 |
-
// [time.duration.special], special values
|
| 7582 |
static constexpr duration zero();
|
| 7583 |
static constexpr duration min();
|
| 7584 |
static constexpr duration max();
|
| 7585 |
};
|
| 7586 |
```
|
| 7587 |
|
| 7588 |
-
|
| 7589 |
-
|
|
|
|
| 7590 |
|
| 7591 |
-
|
| 7592 |
-
|
| 7593 |
|
| 7594 |
-
|
| 7595 |
-
|
| 7596 |
|
| 7597 |
-
|
|
|
|
|
|
|
|
|
|
| 7598 |
|
| 7599 |
-
*
|
| 7600 |
-
those thrown by the indicated operations on their representations.
|
| 7601 |
-
|
| 7602 |
-
*Remarks:* The defaulted copy constructor of duration shall be a
|
| 7603 |
-
`constexpr` function if and only if the required initialization of the
|
| 7604 |
-
member `rep_` for copy and move, respectively, would satisfy the
|
| 7605 |
-
requirements for a `constexpr` function.
|
| 7606 |
|
| 7607 |
``` cpp
|
| 7608 |
duration<long, ratio<60>> d0; // holds a count of minutes using a long
|
| 7609 |
duration<long long, milli> d1; // holds a count of milliseconds using a long long
|
| 7610 |
duration<double, ratio<1, 30>> d2; // holds a count with a tick period of $\frac{1}{30}$ of a second
|
| 7611 |
// (30 Hz) using a double
|
| 7612 |
```
|
| 7613 |
|
|
|
|
|
|
|
| 7614 |
#### `duration` constructors <a id="time.duration.cons">[[time.duration.cons]]</a>
|
| 7615 |
|
| 7616 |
``` cpp
|
| 7617 |
template <class Rep2>
|
| 7618 |
constexpr explicit duration(const Rep2& r);
|
| 7619 |
```
|
| 7620 |
|
| 7621 |
*Remarks:* This constructor shall not participate in overload resolution
|
| 7622 |
unless `Rep2` is implicitly convertible to `rep` and
|
| 7623 |
|
| 7624 |
-
- `
|
| 7625 |
-
- `
|
|
|
|
|
|
|
| 7626 |
|
| 7627 |
``` cpp
|
| 7628 |
duration<int, milli> d(3); // OK
|
| 7629 |
duration<int, milli> d(3.5); // error
|
| 7630 |
```
|
| 7631 |
|
|
|
|
|
|
|
| 7632 |
*Effects:* Constructs an object of type `duration`.
|
| 7633 |
|
| 7634 |
-
`count() == static_cast<rep>(r)`.
|
| 7635 |
|
| 7636 |
``` cpp
|
| 7637 |
template <class Rep2, class Period2>
|
| 7638 |
constexpr duration(const duration<Rep2, Period2>& d);
|
| 7639 |
```
|
| 7640 |
|
| 7641 |
*Remarks:* This constructor shall not participate in overload resolution
|
| 7642 |
unless no overflow is induced in the conversion and
|
| 7643 |
-
`
|
| 7644 |
`ratio_divide<Period2, period>::den` is `1` and
|
| 7645 |
-
`
|
| 7646 |
-
|
| 7647 |
-
|
| 7648 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7649 |
|
| 7650 |
``` cpp
|
| 7651 |
duration<int, milli> ms(3);
|
| 7652 |
duration<int, micro> us = ms; // OK
|
| 7653 |
duration<int, milli> ms2 = us; // error
|
| 7654 |
```
|
| 7655 |
|
|
|
|
|
|
|
| 7656 |
*Effects:* Constructs an object of type `duration`, constructing `rep_`
|
| 7657 |
from
|
| 7658 |
`duration_cast<duration>(d).count()`.
|
| 7659 |
|
| 7660 |
#### `duration` observer <a id="time.duration.observer">[[time.duration.observer]]</a>
|
|
@@ -7666,94 +13006,94 @@ constexpr rep count() const;
|
|
| 7666 |
*Returns:* `rep_`.
|
| 7667 |
|
| 7668 |
#### `duration` arithmetic <a id="time.duration.arithmetic">[[time.duration.arithmetic]]</a>
|
| 7669 |
|
| 7670 |
``` cpp
|
| 7671 |
-
constexpr duration operator+() const;
|
| 7672 |
```
|
| 7673 |
|
| 7674 |
-
*Returns:* `*this`.
|
| 7675 |
|
| 7676 |
``` cpp
|
| 7677 |
-
constexpr duration operator-() const;
|
| 7678 |
```
|
| 7679 |
|
| 7680 |
-
*Returns:* `duration(-rep_)
|
| 7681 |
|
| 7682 |
``` cpp
|
| 7683 |
-
duration& operator++();
|
| 7684 |
```
|
| 7685 |
|
| 7686 |
-
*Effects:* `++rep_`.
|
| 7687 |
|
| 7688 |
*Returns:* `*this`.
|
| 7689 |
|
| 7690 |
``` cpp
|
| 7691 |
-
duration operator++(int);
|
| 7692 |
```
|
| 7693 |
|
| 7694 |
-
*Returns:* `duration(rep_++)
|
| 7695 |
|
| 7696 |
``` cpp
|
| 7697 |
-
duration& operator--();
|
| 7698 |
```
|
| 7699 |
|
| 7700 |
-
*Effects:* `
|
| 7701 |
|
| 7702 |
*Returns:* `*this`.
|
| 7703 |
|
| 7704 |
``` cpp
|
| 7705 |
-
duration operator--(int);
|
| 7706 |
```
|
| 7707 |
|
| 7708 |
-
*Returns:* `duration(rep_--)
|
| 7709 |
|
| 7710 |
``` cpp
|
| 7711 |
-
duration& operator+=(const duration& d);
|
| 7712 |
```
|
| 7713 |
|
| 7714 |
-
*Effects:* `rep_ += d.count()`
|
| 7715 |
|
| 7716 |
*Returns:* `*this`.
|
| 7717 |
|
| 7718 |
``` cpp
|
| 7719 |
-
duration& operator-=(const duration& d);
|
| 7720 |
```
|
| 7721 |
|
| 7722 |
-
*Effects:* `rep_ -= d.count()`
|
| 7723 |
|
| 7724 |
*Returns:* `*this`.
|
| 7725 |
|
| 7726 |
``` cpp
|
| 7727 |
-
duration& operator*=(const rep& rhs);
|
| 7728 |
```
|
| 7729 |
|
| 7730 |
-
*Effects:* `rep_ *= rhs`
|
| 7731 |
|
| 7732 |
*Returns:* `*this`.
|
| 7733 |
|
| 7734 |
``` cpp
|
| 7735 |
-
duration& operator/=(const rep& rhs);
|
| 7736 |
```
|
| 7737 |
|
| 7738 |
-
*Effects:* `rep_ /= rhs`
|
| 7739 |
|
| 7740 |
*Returns:* `*this`.
|
| 7741 |
|
| 7742 |
``` cpp
|
| 7743 |
-
duration& operator%=(const rep& rhs);
|
| 7744 |
```
|
| 7745 |
|
| 7746 |
-
*Effects:* `rep_ %= rhs`
|
| 7747 |
|
| 7748 |
*Returns:* `*this`.
|
| 7749 |
|
| 7750 |
``` cpp
|
| 7751 |
-
duration& operator%=(const duration& rhs);
|
| 7752 |
```
|
| 7753 |
|
| 7754 |
-
*Effects:* `rep_ %= rhs.count()`
|
| 7755 |
|
| 7756 |
*Returns:* `*this`.
|
| 7757 |
|
| 7758 |
#### `duration` special values <a id="time.duration.special">[[time.duration.special]]</a>
|
| 7759 |
|
|
@@ -7784,30 +13124,30 @@ type of the function. `CR(A,B)` represents `common_type_t<A, B>`.
|
|
| 7784 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7785 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 7786 |
operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 7787 |
```
|
| 7788 |
|
| 7789 |
-
*Returns:* CD(CD(lhs).count() + CD(rhs).count()).
|
| 7790 |
|
| 7791 |
``` cpp
|
| 7792 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7793 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 7794 |
operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 7795 |
```
|
| 7796 |
|
| 7797 |
-
*Returns:* CD(CD(lhs).count() - CD(rhs).count()).
|
| 7798 |
|
| 7799 |
``` cpp
|
| 7800 |
template <class Rep1, class Period, class Rep2>
|
| 7801 |
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 7802 |
operator*(const duration<Rep1, Period>& d, const Rep2& s);
|
| 7803 |
```
|
| 7804 |
|
| 7805 |
*Remarks:* This operator shall not participate in overload resolution
|
| 7806 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)`.
|
| 7807 |
|
| 7808 |
-
*Returns:* CD(CD(d).count()
|
| 7809 |
|
| 7810 |
``` cpp
|
| 7811 |
template <class Rep1, class Rep2, class Period>
|
| 7812 |
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 7813 |
operator*(const Rep1& s, const duration<Rep2, Period>& d);
|
|
@@ -7824,13 +13164,13 @@ template <class Rep1, class Period, class Rep2>
|
|
| 7824 |
operator/(const duration<Rep1, Period>& d, const Rep2& s);
|
| 7825 |
```
|
| 7826 |
|
| 7827 |
*Remarks:* This operator shall not participate in overload resolution
|
| 7828 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
|
| 7829 |
-
is not
|
| 7830 |
|
| 7831 |
-
*Returns:* CD(CD(d).count() / s).
|
| 7832 |
|
| 7833 |
``` cpp
|
| 7834 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7835 |
constexpr common_type_t<Rep1, Rep2>
|
| 7836 |
operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
@@ -7844,66 +13184,72 @@ template <class Rep1, class Period, class Rep2>
|
|
| 7844 |
operator%(const duration<Rep1, Period>& d, const Rep2& s);
|
| 7845 |
```
|
| 7846 |
|
| 7847 |
*Remarks:* This operator shall not participate in overload resolution
|
| 7848 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
|
| 7849 |
-
is not
|
| 7850 |
|
| 7851 |
-
*Returns:* CD(CD(d).count() % s).
|
| 7852 |
|
| 7853 |
``` cpp
|
| 7854 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7855 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 7856 |
operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 7857 |
```
|
| 7858 |
|
| 7859 |
-
*Returns:* CD(CD(lhs).count() % CD(rhs).count()).
|
| 7860 |
|
| 7861 |
#### `duration` comparisons <a id="time.duration.comparisons">[[time.duration.comparisons]]</a>
|
| 7862 |
|
| 7863 |
In the function descriptions that follow, `CT` represents
|
| 7864 |
`common_type_t<A, B>`, where `A` and `B` are the types of the two
|
| 7865 |
arguments to the function.
|
| 7866 |
|
| 7867 |
``` cpp
|
| 7868 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7869 |
-
constexpr bool operator==(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 7870 |
```
|
| 7871 |
|
| 7872 |
-
*Returns:* `CT(lhs).count() == CT(rhs).count()`.
|
| 7873 |
|
| 7874 |
``` cpp
|
| 7875 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7876 |
-
constexpr bool operator!=(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 7877 |
```
|
| 7878 |
|
| 7879 |
*Returns:* `!(lhs == rhs)`.
|
| 7880 |
|
| 7881 |
``` cpp
|
| 7882 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7883 |
-
constexpr bool operator<(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 7884 |
```
|
| 7885 |
|
| 7886 |
-
*Returns:* `CT(lhs).count() < CT(rhs).count()`.
|
| 7887 |
|
| 7888 |
``` cpp
|
| 7889 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7890 |
-
constexpr bool operator<=(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 7891 |
```
|
| 7892 |
|
| 7893 |
*Returns:* `!(rhs < lhs)`.
|
| 7894 |
|
| 7895 |
``` cpp
|
| 7896 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7897 |
-
constexpr bool operator>(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 7898 |
```
|
| 7899 |
|
| 7900 |
*Returns:* `rhs < lhs`.
|
| 7901 |
|
| 7902 |
``` cpp
|
| 7903 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 7904 |
-
constexpr bool operator>=(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 7905 |
```
|
| 7906 |
|
| 7907 |
*Returns:* `!(lhs < rhs)`.
|
| 7908 |
|
| 7909 |
#### `duration_cast` <a id="time.duration.cast">[[time.duration.cast]]</a>
|
|
@@ -7912,15 +13258,15 @@ template <class Rep1, class Period1, class Rep2, class Period2>
|
|
| 7912 |
template <class ToDuration, class Rep, class Period>
|
| 7913 |
constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
|
| 7914 |
```
|
| 7915 |
|
| 7916 |
*Remarks:* This function shall not participate in overload resolution
|
| 7917 |
-
unless `ToDuration` is
|
| 7918 |
|
| 7919 |
*Returns:* Let `CF` be
|
| 7920 |
`ratio_divide<Period, typename ToDuration::period>`, and `CR` be
|
| 7921 |
-
`common_type<` `typename ToDuration::rep, Rep, intmax_t>::type
|
| 7922 |
|
| 7923 |
- If `CF::num == 1` and `CF::den == 1`, returns
|
| 7924 |
``` cpp
|
| 7925 |
ToDuration(static_cast<typename ToDuration::rep>(d.count()))
|
| 7926 |
```
|
|
@@ -7938,42 +13284,81 @@ unless `ToDuration` is an instantiation of `duration`.
|
|
| 7938 |
``` cpp
|
| 7939 |
ToDuration(static_cast<typename ToDuration::rep>(
|
| 7940 |
static_cast<CR>(d.count()) * static_cast<CR>(CF::num) / static_cast<CR>(CF::den)))
|
| 7941 |
```
|
| 7942 |
|
| 7943 |
-
*
|
| 7944 |
conversions are done with `static_cast`. It avoids multiplications and
|
| 7945 |
divisions when it is known at compile time that one or more arguments
|
| 7946 |
is 1. Intermediate computations are carried out in the widest
|
| 7947 |
representation and only converted to the destination representation at
|
| 7948 |
-
the final step.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7949 |
|
| 7950 |
#### Suffixes for duration literals <a id="time.duration.literals">[[time.duration.literals]]</a>
|
| 7951 |
|
| 7952 |
This section describes literal suffixes for constructing duration
|
| 7953 |
literals. The suffixes `h`, `min`, `s`, `ms`, `us`, `ns` denote duration
|
| 7954 |
values of the corresponding types `hours`, `minutes`, `seconds`,
|
| 7955 |
`milliseconds`, `microseconds`, and `nanoseconds` respectively if they
|
| 7956 |
are applied to integral literals.
|
| 7957 |
|
| 7958 |
-
If any of these suffixes are applied to a floating
|
| 7959 |
-
result is a `chrono::duration` literal with an unspecified
|
| 7960 |
-
point representation.
|
| 7961 |
|
| 7962 |
If any of these suffixes are applied to an integer literal and the
|
| 7963 |
resulting `chrono::duration` value cannot be represented in the result
|
| 7964 |
type because of overflow, the program is ill-formed.
|
| 7965 |
|
|
|
|
|
|
|
| 7966 |
The following code shows some duration literals.
|
| 7967 |
|
| 7968 |
``` cpp
|
| 7969 |
using namespace std::chrono_literals;
|
| 7970 |
auto constexpr aday=24h;
|
| 7971 |
auto constexpr lesson=45min;
|
| 7972 |
auto constexpr halfanhour=0.5h;
|
| 7973 |
```
|
| 7974 |
|
|
|
|
|
|
|
| 7975 |
``` cpp
|
| 7976 |
constexpr chrono::hours operator""h(unsigned long long hours);
|
| 7977 |
constexpr chrono::duration<unspecified, ratio<3600, 1>> operator""h(long double hours);
|
| 7978 |
```
|
| 7979 |
|
|
@@ -7985,19 +13370,19 @@ constexpr chrono::duration<unspecified, ratio<60,1>> operator "" min(long double
|
|
| 7985 |
```
|
| 7986 |
|
| 7987 |
*Returns:* A `duration` literal representing `minutes` minutes.
|
| 7988 |
|
| 7989 |
``` cpp
|
| 7990 |
-
constexpr chrono::seconds
|
| 7991 |
constexpr chrono::duration<unspecified> operator""s(long double sec);
|
| 7992 |
```
|
| 7993 |
|
| 7994 |
*Returns:* A `duration` literal representing `sec` seconds.
|
| 7995 |
|
| 7996 |
-
The same suffix `s` is used for `basic_string` but there is
|
| 7997 |
-
since duration suffixes apply to numbers and string literal
|
| 7998 |
-
apply to character array literals.
|
| 7999 |
|
| 8000 |
``` cpp
|
| 8001 |
constexpr chrono::milliseconds operator""ms(unsigned long long msec);
|
| 8002 |
constexpr chrono::duration<unspecified, milli> operator""ms(long double msec);
|
| 8003 |
```
|
|
@@ -8016,44 +13401,56 @@ constexpr chrono::nanoseconds operator "" ns(unsigned long long
|
|
| 8016 |
constexpr chrono::duration<unspecified, nano> operator""ns(long double nsec);
|
| 8017 |
```
|
| 8018 |
|
| 8019 |
*Returns:* A `duration` literal representing `nsec` nanoseconds.
|
| 8020 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8021 |
### Class template `time_point` <a id="time.point">[[time.point]]</a>
|
| 8022 |
|
| 8023 |
``` cpp
|
| 8024 |
template <class Clock, class Duration = typename Clock::duration>
|
| 8025 |
class time_point {
|
| 8026 |
public:
|
| 8027 |
-
|
| 8028 |
-
|
| 8029 |
-
|
| 8030 |
-
|
| 8031 |
private:
|
| 8032 |
duration d_; // exposition only
|
| 8033 |
|
| 8034 |
public:
|
| 8035 |
-
// [time.point.cons], construct
|
| 8036 |
constexpr time_point(); // has value epoch
|
| 8037 |
constexpr explicit time_point(const duration& d); // same as time_point() + d
|
| 8038 |
template <class Duration2>
|
| 8039 |
constexpr time_point(const time_point<clock, Duration2>& t);
|
| 8040 |
|
| 8041 |
-
// [time.point.observer], observer
|
| 8042 |
constexpr duration time_since_epoch() const;
|
| 8043 |
|
| 8044 |
-
// [time.point.arithmetic], arithmetic
|
| 8045 |
-
time_point& operator+=(const duration& d);
|
| 8046 |
-
time_point& operator-=(const duration& d);
|
| 8047 |
|
| 8048 |
-
// [time.point.special], special values
|
| 8049 |
static constexpr time_point min();
|
| 8050 |
static constexpr time_point max();
|
| 8051 |
};
|
| 8052 |
```
|
| 8053 |
|
| 8054 |
-
`Clock` shall meet the Clock requirements ([[time.clock]]).
|
| 8055 |
|
| 8056 |
If `Duration` is not an instance of `duration`, the program is
|
| 8057 |
ill-formed.
|
| 8058 |
|
| 8059 |
#### `time_point` constructors <a id="time.point.cons">[[time.point.cons]]</a>
|
|
@@ -8093,22 +13490,22 @@ constexpr duration time_since_epoch() const;
|
|
| 8093 |
*Returns:* `d_`.
|
| 8094 |
|
| 8095 |
#### `time_point` arithmetic <a id="time.point.arithmetic">[[time.point.arithmetic]]</a>
|
| 8096 |
|
| 8097 |
``` cpp
|
| 8098 |
-
time_point& operator+=(const duration& d);
|
| 8099 |
```
|
| 8100 |
|
| 8101 |
-
*Effects:* `d_ += d`
|
| 8102 |
|
| 8103 |
*Returns:* `*this`.
|
| 8104 |
|
| 8105 |
``` cpp
|
| 8106 |
-
time_point& operator-=(const duration& d);
|
| 8107 |
```
|
| 8108 |
|
| 8109 |
-
*Effects:* `d_ -= d`
|
| 8110 |
|
| 8111 |
*Returns:* `*this`.
|
| 8112 |
|
| 8113 |
#### `time_point` special values <a id="time.point.special">[[time.point.special]]</a>
|
| 8114 |
|
|
@@ -8130,12 +13527,12 @@ static constexpr time_point max();
|
|
| 8130 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 8131 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 8132 |
operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 8133 |
```
|
| 8134 |
|
| 8135 |
-
*Returns:* `CT(lhs.time_since_epoch() + rhs)`, where `CT` is the
|
| 8136 |
-
the return value.
|
| 8137 |
|
| 8138 |
``` cpp
|
| 8139 |
template <class Rep1, class Period1, class Clock, class Duration2>
|
| 8140 |
constexpr time_point<Clock, common_type_t<duration<Rep1, Period1>, Duration2>>
|
| 8141 |
operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
@@ -8147,11 +13544,12 @@ template <class Rep1, class Period1, class Clock, class Duration2>
|
|
| 8147 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 8148 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 8149 |
operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 8150 |
```
|
| 8151 |
|
| 8152 |
-
*Returns:* `lhs
|
|
|
|
| 8153 |
|
| 8154 |
``` cpp
|
| 8155 |
template <class Clock, class Duration1, class Duration2>
|
| 8156 |
constexpr common_type_t<Duration1, Duration2>
|
| 8157 |
operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
@@ -8161,46 +13559,52 @@ template <class Clock, class Duration1, class Duration2>
|
|
| 8161 |
|
| 8162 |
#### `time_point` comparisons <a id="time.point.comparisons">[[time.point.comparisons]]</a>
|
| 8163 |
|
| 8164 |
``` cpp
|
| 8165 |
template <class Clock, class Duration1, class Duration2>
|
| 8166 |
-
constexpr bool operator==(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 8167 |
```
|
| 8168 |
|
| 8169 |
*Returns:* `lhs.time_since_epoch() == rhs.time_since_epoch()`.
|
| 8170 |
|
| 8171 |
``` cpp
|
| 8172 |
template <class Clock, class Duration1, class Duration2>
|
| 8173 |
-
constexpr bool operator!=(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 8174 |
```
|
| 8175 |
|
| 8176 |
*Returns:* `!(lhs == rhs)`.
|
| 8177 |
|
| 8178 |
``` cpp
|
| 8179 |
template <class Clock, class Duration1, class Duration2>
|
| 8180 |
-
constexpr bool operator<(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 8181 |
```
|
| 8182 |
|
| 8183 |
*Returns:* `lhs.time_since_epoch() < rhs.time_since_epoch()`.
|
| 8184 |
|
| 8185 |
``` cpp
|
| 8186 |
template <class Clock, class Duration1, class Duration2>
|
| 8187 |
-
constexpr bool operator<=(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 8188 |
```
|
| 8189 |
|
| 8190 |
*Returns:* `!(rhs < lhs)`.
|
| 8191 |
|
| 8192 |
``` cpp
|
| 8193 |
template <class Clock, class Duration1, class Duration2>
|
| 8194 |
-
constexpr bool operator>(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 8195 |
```
|
| 8196 |
|
| 8197 |
*Returns:* `rhs < lhs`.
|
| 8198 |
|
| 8199 |
``` cpp
|
| 8200 |
template <class Clock, class Duration1, class Duration2>
|
| 8201 |
-
constexpr bool operator>=(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 8202 |
```
|
| 8203 |
|
| 8204 |
*Returns:* `!(lhs < rhs)`.
|
| 8205 |
|
| 8206 |
#### `time_point_cast` <a id="time.point.cast">[[time.point.cast]]</a>
|
|
@@ -8210,14 +13614,54 @@ template <class ToDuration, class Clock, class Duration>
|
|
| 8210 |
constexpr time_point<Clock, ToDuration>
|
| 8211 |
time_point_cast(const time_point<Clock, Duration>& t);
|
| 8212 |
```
|
| 8213 |
|
| 8214 |
*Remarks:* This function shall not participate in overload resolution
|
| 8215 |
-
unless `ToDuration` is
|
| 8216 |
|
| 8217 |
*Returns:*
|
| 8218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8219 |
|
| 8220 |
### Clocks <a id="time.clock">[[time.clock]]</a>
|
| 8221 |
|
| 8222 |
The types defined in this subclause shall satisfy the `TrivialClock`
|
| 8223 |
requirements ([[time.clock.req]]).
|
|
@@ -8228,14 +13672,14 @@ Objects of class `system_clock` represent wall clock time from the
|
|
| 8228 |
system-wide realtime clock.
|
| 8229 |
|
| 8230 |
``` cpp
|
| 8231 |
class system_clock {
|
| 8232 |
public:
|
| 8233 |
-
|
| 8234 |
-
|
| 8235 |
-
|
| 8236 |
-
|
| 8237 |
static constexpr bool is_steady = unspecified;
|
| 8238 |
|
| 8239 |
static time_point now() noexcept;
|
| 8240 |
|
| 8241 |
// Map to C API
|
|
@@ -8243,33 +13687,35 @@ public:
|
|
| 8243 |
static time_point from_time_t(time_t t) noexcept;
|
| 8244 |
};
|
| 8245 |
```
|
| 8246 |
|
| 8247 |
``` cpp
|
| 8248 |
-
|
| 8249 |
```
|
| 8250 |
|
| 8251 |
*Requires:*
|
| 8252 |
`system_clock::duration::min() < system_clock::duration::zero()` shall
|
| 8253 |
-
be `true`.
|
|
|
|
|
|
|
| 8254 |
|
| 8255 |
``` cpp
|
| 8256 |
static time_t to_time_t(const time_point& t) noexcept;
|
| 8257 |
```
|
| 8258 |
|
| 8259 |
*Returns:* A `time_t` object that represents the same point in time as
|
| 8260 |
`t` when both values are restricted to the coarser of the precisions of
|
| 8261 |
-
`time_t` and `time_point`. It is implementation
|
| 8262 |
are rounded or truncated to the required precision.
|
| 8263 |
|
| 8264 |
``` cpp
|
| 8265 |
static time_point from_time_t(time_t t) noexcept;
|
| 8266 |
```
|
| 8267 |
|
| 8268 |
*Returns:* A `time_point` object that represents the same point in time
|
| 8269 |
as `t` when both values are restricted to the coarser of the precisions
|
| 8270 |
-
of `time_t` and `time_point`. It is implementation
|
| 8271 |
values are rounded or truncated to the required precision.
|
| 8272 |
|
| 8273 |
#### Class `steady_clock` <a id="time.clock.steady">[[time.clock.steady]]</a>
|
| 8274 |
|
| 8275 |
Objects of class `steady_clock` represent clocks for which values of
|
|
@@ -8278,14 +13724,14 @@ values of `time_point` advance at a steady rate relative to real time.
|
|
| 8278 |
That is, the clock may not be adjusted.
|
| 8279 |
|
| 8280 |
``` cpp
|
| 8281 |
class steady_clock {
|
| 8282 |
public:
|
| 8283 |
-
|
| 8284 |
-
|
| 8285 |
-
|
| 8286 |
-
|
| 8287 |
static constexpr bool is_steady = true;
|
| 8288 |
|
| 8289 |
static time_point now() noexcept;
|
| 8290 |
};
|
| 8291 |
```
|
|
@@ -8297,452 +13743,55 @@ shortest tick period. `high_resolution_clock` may be a synonym for
|
|
| 8297 |
`system_clock` or `steady_clock`.
|
| 8298 |
|
| 8299 |
``` cpp
|
| 8300 |
class high_resolution_clock {
|
| 8301 |
public:
|
| 8302 |
-
|
| 8303 |
-
|
| 8304 |
-
|
| 8305 |
-
|
| 8306 |
static constexpr bool is_steady = unspecified;
|
| 8307 |
|
| 8308 |
static time_point now() noexcept;
|
| 8309 |
};
|
| 8310 |
```
|
| 8311 |
|
| 8312 |
-
###
|
| 8313 |
-
|
| 8314 |
-
Table [[tab:util.hdr.ctime]] describes the header `<ctime>`.
|
| 8315 |
-
|
| 8316 |
-
The contents are the same as the Standard C library header
|
| 8317 |
-
`<time.h>.`[^3] The functions `asctime`, `ctime`, `gmtime`, and
|
| 8318 |
-
`localtime` are not required to avoid data races (
|
| 8319 |
-
[[res.on.data.races]]).
|
| 8320 |
-
|
| 8321 |
-
ISO C Clause 7.12, Amendment 1 Clause 4.6.4.
|
| 8322 |
-
|
| 8323 |
-
## Class template `scoped_allocator_adaptor` <a id="allocator.adaptor">[[allocator.adaptor]]</a>
|
| 8324 |
-
|
| 8325 |
-
### Header `<scoped_allocator>` synopsis <a id="allocator.adaptor.syn">[[allocator.adaptor.syn]]</a>
|
| 8326 |
|
| 8327 |
``` cpp
|
| 8328 |
-
|
| 8329 |
-
|
| 8330 |
-
|
| 8331 |
-
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 8332 |
-
bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 8333 |
-
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 8334 |
-
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 8335 |
-
bool operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 8336 |
-
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 8337 |
-
```
|
| 8338 |
-
|
| 8339 |
-
The class template `scoped_allocator_adaptor` is an allocator template
|
| 8340 |
-
that specifies the memory resource (the outer allocator) to be used by a
|
| 8341 |
-
container (as any other allocator does) and also specifies an inner
|
| 8342 |
-
allocator resource to be passed to the constructor of every element
|
| 8343 |
-
within the container. This adaptor is instantiated with one outer and
|
| 8344 |
-
zero or more inner allocator types. If instantiated with only one
|
| 8345 |
-
allocator type, the inner allocator becomes the
|
| 8346 |
-
`scoped_allocator_adaptor` itself, thus using the same allocator
|
| 8347 |
-
resource for the container and every element within the container and,
|
| 8348 |
-
if the elements themselves are containers, each of their elements
|
| 8349 |
-
recursively. If instantiated with more than one allocator, the first
|
| 8350 |
-
allocator is the outer allocator for use by the container, the second
|
| 8351 |
-
allocator is passed to the constructors of the container’s elements,
|
| 8352 |
-
and, if the elements themselves are containers, the third allocator is
|
| 8353 |
-
passed to the elements’ elements, and so on. If containers are nested to
|
| 8354 |
-
a depth greater than the number of allocators, the last allocator is
|
| 8355 |
-
used repeatedly, as in the single-allocator case, for any remaining
|
| 8356 |
-
recursions. The `scoped_allocator_adaptor` is derived from the outer
|
| 8357 |
-
allocator type so it can be substituted for the outer allocator type in
|
| 8358 |
-
most expressions.
|
| 8359 |
|
| 8360 |
-
``` cpp
|
| 8361 |
namespace std {
|
| 8362 |
-
|
| 8363 |
-
|
| 8364 |
-
|
| 8365 |
-
|
| 8366 |
-
|
| 8367 |
-
|
| 8368 |
-
|
| 8369 |
-
|
| 8370 |
-
|
| 8371 |
-
|
| 8372 |
-
|
| 8373 |
-
|
| 8374 |
-
|
| 8375 |
-
|
| 8376 |
-
|
| 8377 |
-
|
| 8378 |
-
|
| 8379 |
-
typedef see below propagate_on_container_copy_assignment;
|
| 8380 |
-
typedef see below propagate_on_container_move_assignment;
|
| 8381 |
-
typedef see below propagate_on_container_swap;
|
| 8382 |
-
|
| 8383 |
-
template <class Tp>
|
| 8384 |
-
struct rebind {
|
| 8385 |
-
typedef scoped_allocator_adaptor<
|
| 8386 |
-
OuterTraits::template rebind_alloc<Tp>, InnerAllocs...> other;
|
| 8387 |
-
};
|
| 8388 |
-
|
| 8389 |
-
scoped_allocator_adaptor();
|
| 8390 |
-
template <class OuterA2>
|
| 8391 |
-
scoped_allocator_adaptor(OuterA2&& outerAlloc,
|
| 8392 |
-
const InnerAllocs&... innerAllocs) noexcept;
|
| 8393 |
-
|
| 8394 |
-
scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
|
| 8395 |
-
scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept;
|
| 8396 |
-
|
| 8397 |
-
template <class OuterA2>
|
| 8398 |
-
scoped_allocator_adaptor(
|
| 8399 |
-
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept;
|
| 8400 |
-
template <class OuterA2>
|
| 8401 |
-
scoped_allocator_adaptor(
|
| 8402 |
-
scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
|
| 8403 |
-
|
| 8404 |
-
~scoped_allocator_adaptor();
|
| 8405 |
-
|
| 8406 |
-
inner_allocator_type& inner_allocator() noexcept;
|
| 8407 |
-
const inner_allocator_type& inner_allocator() const noexcept;
|
| 8408 |
-
outer_allocator_type& outer_allocator() noexcept;
|
| 8409 |
-
const outer_allocator_type& outer_allocator() const noexcept;
|
| 8410 |
-
|
| 8411 |
-
pointer allocate(size_type n);
|
| 8412 |
-
pointer allocate(size_type n, const_void_pointer hint);
|
| 8413 |
-
void deallocate(pointer p, size_type n);
|
| 8414 |
-
size_type max_size() const;
|
| 8415 |
-
|
| 8416 |
-
template <class T, class... Args>
|
| 8417 |
-
void construct(T* p, Args&&... args);
|
| 8418 |
-
template <class T1, class T2, class... Args1, class... Args2>
|
| 8419 |
-
void construct(pair<T1, T2>* p, piecewise_construct_t,
|
| 8420 |
-
tuple<Args1...> x, tuple<Args2...> y);
|
| 8421 |
-
template <class T1, class T2>
|
| 8422 |
-
void construct(pair<T1, T2>* p);
|
| 8423 |
-
template <class T1, class T2, class U, class V>
|
| 8424 |
-
void construct(pair<T1, T2>* p, U&& x, V&& y);
|
| 8425 |
-
template <class T1, class T2, class U, class V>
|
| 8426 |
-
void construct(pair<T1, T2>* p, const pair<U, V>& x);
|
| 8427 |
-
template <class T1, class T2, class U, class V>
|
| 8428 |
-
void construct(pair<T1, T2>* p, pair<U, V>&& x);
|
| 8429 |
-
|
| 8430 |
-
template <class T>
|
| 8431 |
-
void destroy(T* p);
|
| 8432 |
-
|
| 8433 |
-
scoped_allocator_adaptor select_on_container_copy_construction() const;
|
| 8434 |
-
};
|
| 8435 |
-
|
| 8436 |
-
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 8437 |
-
bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 8438 |
-
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 8439 |
-
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 8440 |
-
bool operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 8441 |
-
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 8442 |
}
|
| 8443 |
```
|
| 8444 |
|
| 8445 |
-
|
|
|
|
| 8446 |
|
| 8447 |
-
```
|
| 8448 |
-
|
| 8449 |
-
```
|
| 8450 |
|
| 8451 |
-
|
| 8452 |
-
`sizeof...(InnerAllocs)` is zero; otherwise,
|
| 8453 |
-
`scoped_allocator_adaptor<InnerAllocs...>`.
|
| 8454 |
-
|
| 8455 |
-
``` cpp
|
| 8456 |
-
typedef see below propagate_on_container_copy_assignment;
|
| 8457 |
-
```
|
| 8458 |
-
|
| 8459 |
-
*Type:* `true_type` if
|
| 8460 |
-
`allocator_traits<A>::propagate_on_container_copy_assignment::value` is
|
| 8461 |
-
`true` for any `A` in the set of `OuterAlloc` and `InnerAllocs...`;
|
| 8462 |
-
otherwise, `false_type`.
|
| 8463 |
-
|
| 8464 |
-
``` cpp
|
| 8465 |
-
typedef see below propagate_on_container_move_assignment;
|
| 8466 |
-
```
|
| 8467 |
-
|
| 8468 |
-
*Type:* `true_type` if
|
| 8469 |
-
`allocator_traits<A>::propagate_on_container_move_assignment::value` is
|
| 8470 |
-
`true` for any `A` in the set of `OuterAlloc` and `InnerAllocs...`;
|
| 8471 |
-
otherwise, `false_type`.
|
| 8472 |
-
|
| 8473 |
-
``` cpp
|
| 8474 |
-
typedef see below propagate_on_container_swap;
|
| 8475 |
-
```
|
| 8476 |
-
|
| 8477 |
-
*Type:* `true_type` if
|
| 8478 |
-
`allocator_traits<A>::propagate_on_container_swap::value` is `true` for
|
| 8479 |
-
any `A` in the set of `OuterAlloc` and `InnerAllocs...`; otherwise,
|
| 8480 |
-
`false_type`.
|
| 8481 |
-
|
| 8482 |
-
### Scoped allocator adaptor constructors <a id="allocator.adaptor.cnstr">[[allocator.adaptor.cnstr]]</a>
|
| 8483 |
-
|
| 8484 |
-
``` cpp
|
| 8485 |
-
scoped_allocator_adaptor();
|
| 8486 |
-
```
|
| 8487 |
-
|
| 8488 |
-
*Effects:* value-initializes the `OuterAlloc` base class and the `inner`
|
| 8489 |
-
allocator object.
|
| 8490 |
-
|
| 8491 |
-
``` cpp
|
| 8492 |
-
template <class OuterA2>
|
| 8493 |
-
scoped_allocator_adaptor(OuterA2&& outerAlloc,
|
| 8494 |
-
const InnerAllocs&... innerAllocs) noexcept;
|
| 8495 |
-
```
|
| 8496 |
-
|
| 8497 |
-
*Requires:* `OuterAlloc` shall be constructible from `OuterA2`.
|
| 8498 |
-
|
| 8499 |
-
*Effects:* initializes the `OuterAlloc` base class with
|
| 8500 |
-
`std::forward<OuterA2>(outerAlloc)` and `inner` with `innerAllocs...`
|
| 8501 |
-
(hence recursively initializing each allocator within the adaptor with
|
| 8502 |
-
the corresponding allocator from the argument list).
|
| 8503 |
-
|
| 8504 |
-
``` cpp
|
| 8505 |
-
scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
|
| 8506 |
-
```
|
| 8507 |
-
|
| 8508 |
-
*Effects:* initializes each allocator within the adaptor with the
|
| 8509 |
-
corresponding allocator from `other`.
|
| 8510 |
-
|
| 8511 |
-
``` cpp
|
| 8512 |
-
scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept;
|
| 8513 |
-
```
|
| 8514 |
-
|
| 8515 |
-
*Effects:* move constructs each allocator within the adaptor with the
|
| 8516 |
-
corresponding allocator from `other`.
|
| 8517 |
-
|
| 8518 |
-
``` cpp
|
| 8519 |
-
template <class OuterA2>
|
| 8520 |
-
scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2,
|
| 8521 |
-
InnerAllocs...>& other) noexcept;
|
| 8522 |
-
```
|
| 8523 |
-
|
| 8524 |
-
*Requires:* `OuterAlloc` shall be constructible from `OuterA2`.
|
| 8525 |
-
|
| 8526 |
-
*Effects:* initializes each allocator within the adaptor with the
|
| 8527 |
-
corresponding allocator from `other`.
|
| 8528 |
-
|
| 8529 |
-
``` cpp
|
| 8530 |
-
template <class OuterA2>
|
| 8531 |
-
scoped_allocator_adaptor(scoped_allocator_adaptor<OuterA2,
|
| 8532 |
-
InnerAllocs...>&& other) noexcept;
|
| 8533 |
-
```
|
| 8534 |
-
|
| 8535 |
-
*Requires:* `OuterAlloc` shall be constructible from `OuterA2`.
|
| 8536 |
-
|
| 8537 |
-
*Effects:* initializes each allocator within the adaptor with the
|
| 8538 |
-
corresponding allocator rvalue from `other`.
|
| 8539 |
-
|
| 8540 |
-
### Scoped allocator adaptor members <a id="allocator.adaptor.members">[[allocator.adaptor.members]]</a>
|
| 8541 |
-
|
| 8542 |
-
In the `construct` member functions, *OUTERMOST(x)* is `x` if `x` does
|
| 8543 |
-
not have an `outer_allocator()` member function and
|
| 8544 |
-
*OUTERMOST(x.outer_allocator())* otherwise; *OUTERMOST_ALLOC_TRAITS(x)*
|
| 8545 |
-
is
|
| 8546 |
-
`allocator_traits<decltype(OUTERMOST(x))>`. *OUTERMOST*(x) and
|
| 8547 |
-
*OUTERMOST_ALLOC_TRAITS*(x) are recursive operations. It is incumbent
|
| 8548 |
-
upon the definition of `outer_allocator()` to ensure that the recursion
|
| 8549 |
-
terminates. It will terminate for all instantiations of
|
| 8550 |
-
`scoped_allocator_adaptor`.
|
| 8551 |
-
|
| 8552 |
-
``` cpp
|
| 8553 |
-
inner_allocator_type& inner_allocator() noexcept;
|
| 8554 |
-
const inner_allocator_type& inner_allocator() const noexcept;
|
| 8555 |
-
```
|
| 8556 |
-
|
| 8557 |
-
*Returns:* `*this` if `sizeof...(InnerAllocs)` is zero; otherwise,
|
| 8558 |
-
`inner`.
|
| 8559 |
-
|
| 8560 |
-
``` cpp
|
| 8561 |
-
outer_allocator_type& outer_allocator() noexcept;
|
| 8562 |
-
```
|
| 8563 |
-
|
| 8564 |
-
*Returns:* `static_cast<OuterAlloc&>(*this)`.
|
| 8565 |
-
|
| 8566 |
-
``` cpp
|
| 8567 |
-
const outer_allocator_type& outer_allocator() const noexcept;
|
| 8568 |
-
```
|
| 8569 |
-
|
| 8570 |
-
*Returns:* `static_cast<const OuterAlloc&>(*this)`.
|
| 8571 |
-
|
| 8572 |
-
``` cpp
|
| 8573 |
-
pointer allocate(size_type n);
|
| 8574 |
-
```
|
| 8575 |
-
|
| 8576 |
-
*Returns:*
|
| 8577 |
-
`allocator_traits<OuterAlloc>::allocate(outer_allocator(), n)`.
|
| 8578 |
-
|
| 8579 |
-
``` cpp
|
| 8580 |
-
pointer allocate(size_type n, const_void_pointer hint);
|
| 8581 |
-
```
|
| 8582 |
-
|
| 8583 |
-
*Returns:*
|
| 8584 |
-
`allocator_traits<OuterAlloc>::allocate(outer_allocator(), n, hint)`.
|
| 8585 |
-
|
| 8586 |
-
``` cpp
|
| 8587 |
-
void deallocate(pointer p, size_type n) noexcept;
|
| 8588 |
-
```
|
| 8589 |
-
|
| 8590 |
-
*Effects:*
|
| 8591 |
-
`allocator_traits<OuterAlloc>::deallocate(outer_allocator(), p, n)`;
|
| 8592 |
-
|
| 8593 |
-
``` cpp
|
| 8594 |
-
size_type max_size() const;
|
| 8595 |
-
```
|
| 8596 |
-
|
| 8597 |
-
*Returns:* `allocator_traits<OuterAlloc>::max_size(outer_allocator())`.
|
| 8598 |
-
|
| 8599 |
-
``` cpp
|
| 8600 |
-
template <class T, class... Args>
|
| 8601 |
-
void construct(T* p, Args&&... args);
|
| 8602 |
-
```
|
| 8603 |
-
|
| 8604 |
-
*Effects:*
|
| 8605 |
-
|
| 8606 |
-
- If `uses_allocator<T, inner_allocator_type>::value` is `false` and
|
| 8607 |
-
`is_constructible<T, Args...>::value` is `true`, calls
|
| 8608 |
-
*OUTERMOST_ALLOC_TRAITS*(`*this`)`::construct(`
|
| 8609 |
-
*`OUTERMOST`*`(*this), p, std::forward<Args>(args)...)`.
|
| 8610 |
-
- Otherwise, if `uses_allocator<T, inner_allocator_type>::value` is
|
| 8611 |
-
`true` and
|
| 8612 |
-
`is_constructible<T, allocator_arg_t, inner_allocator_type, Args...>::value`
|
| 8613 |
-
is `true`, calls
|
| 8614 |
-
*OUTERMOST_ALLOC_TRAITS*(`*this`)`::construct(`*`OUTERMOST`*`(*this), p, allocator_arg,`
|
| 8615 |
-
`inner_allocator(), std::forward<Args>(args)...)`.
|
| 8616 |
-
- Otherwise, if `uses_allocator<T, inner_allocator_type>::value` is
|
| 8617 |
-
`true` and `is_constructible<T, Args..., inner_allocator_type>::value`
|
| 8618 |
-
is `true`, calls *OUTERMOST_ALLOC_TRAITS*(\*this)::
|
| 8619 |
-
`construct(`*`OUTERMOST`*`(*this), p, std::forward<Args>(args)...,`
|
| 8620 |
-
`inner_allocator())`.
|
| 8621 |
-
- Otherwise, the program is ill-formed. An error will result if
|
| 8622 |
-
`uses_allocator` evaluates to true but the specific constructor does
|
| 8623 |
-
not take an allocator. This definition prevents a silent failure to
|
| 8624 |
-
pass an inner allocator to a contained element.
|
| 8625 |
-
|
| 8626 |
-
``` cpp
|
| 8627 |
-
template <class T1, class T2, class... Args1, class... Args2>
|
| 8628 |
-
void construct(pair<T1, T2>* p,piecewise_construct_t,
|
| 8629 |
-
tuple<Args1...> x, tuple<Args2...> y);
|
| 8630 |
-
```
|
| 8631 |
-
|
| 8632 |
-
*Requires:* all of the types in `Args1` and `Args2` shall be
|
| 8633 |
-
`CopyConstructible` (Table [[copyconstructible]]).
|
| 8634 |
-
|
| 8635 |
-
*Effects:* Constructs a `tuple` object `xprime` from `x` by the
|
| 8636 |
-
following rules:
|
| 8637 |
-
|
| 8638 |
-
- If `uses_allocator<T1, inner_allocator_type>::value` is `false` and
|
| 8639 |
-
`is_constructible<T1, Args1...>::value` is `true`, then `xprime` is
|
| 8640 |
-
`x`.
|
| 8641 |
-
- Otherwise, if `uses_allocator<T1, inner_allocator_type>::value` is
|
| 8642 |
-
`true` and
|
| 8643 |
-
`is_constructible<T1, allocator_arg_t, inner_allocator_type, Args1...>::value`
|
| 8644 |
-
is `true`, then `xprime` is
|
| 8645 |
-
`tuple_cat(tuple<allocator_arg_t, inner_allocator_type&>( allocator_arg, inner_allocator()), std::move(x))`.
|
| 8646 |
-
- Otherwise, if `uses_allocator<T1, inner_allocator_type>::value` is
|
| 8647 |
-
`true` and
|
| 8648 |
-
`is_constructible<T1, Args1..., inner_allocator_type>::value` is
|
| 8649 |
-
`true`, then `xprime` is
|
| 8650 |
-
`tuple_cat(std::move(x), tuple<inner_allocator_type&>(inner_allocator()))`.
|
| 8651 |
-
- Otherwise, the program is ill-formed.
|
| 8652 |
-
|
| 8653 |
-
and constructs a `tuple` object `yprime` from `y` by the following
|
| 8654 |
-
rules:
|
| 8655 |
-
|
| 8656 |
-
- If `uses_allocator<T2, inner_allocator_type>::value` is `false` and
|
| 8657 |
-
`is_constructible<T2, Args2...>::value` is `true`, then `yprime` is
|
| 8658 |
-
`y`.
|
| 8659 |
-
- Otherwise, if `uses_allocator<T2, inner_allocator_type>::value` is
|
| 8660 |
-
`true` and
|
| 8661 |
-
`is_constructible<T2, allocator_arg_t, inner_allocator_type, Args2...>::value`
|
| 8662 |
-
is `true`, then `yprime` is
|
| 8663 |
-
`tuple_cat(tuple<allocator_arg_t, inner_allocator_type&>( allocator_arg, inner_allocator()), std::move(y))`.
|
| 8664 |
-
- Otherwise, if `uses_allocator<T2, inner_allocator_type>::value` is
|
| 8665 |
-
`true` and
|
| 8666 |
-
`is_constructible<T2, Args2..., inner_allocator_type>::value` is
|
| 8667 |
-
`true`, then `yprime` is
|
| 8668 |
-
`tuple_cat(std::move(y), tuple<inner_allocator_type&>(inner_allocator()))`.
|
| 8669 |
-
- Otherwise, the program is ill-formed.
|
| 8670 |
-
|
| 8671 |
-
then calls
|
| 8672 |
-
*`OUTERMOST_ALLOC_TRAITS`*`(*this)::construct(`*`OUTERMOST`*`(*this), p,`
|
| 8673 |
-
`piecewise_construct, std::move(xprime), std::move(yprime))`.
|
| 8674 |
-
|
| 8675 |
-
``` cpp
|
| 8676 |
-
template <class T1, class T2>
|
| 8677 |
-
void construct(pair<T1, T2>* p);
|
| 8678 |
-
```
|
| 8679 |
-
|
| 8680 |
-
*Effects:* Equivalent to
|
| 8681 |
-
`this->construct(p, piecewise_construct, tuple<>(), tuple<>())`.
|
| 8682 |
-
|
| 8683 |
-
``` cpp
|
| 8684 |
-
template <class T1, class T2, class U, class V>
|
| 8685 |
-
void construct(pair<T1, T2>* p, U&& x, V&& y);
|
| 8686 |
-
```
|
| 8687 |
-
|
| 8688 |
-
*Effects:* Equivalent to
|
| 8689 |
-
`this->construct(p, piecewise_construct, forward_as_tuple(std::forward<U>(x)), forward_as_tuple(std::forward<V>(y)))`.
|
| 8690 |
-
|
| 8691 |
-
``` cpp
|
| 8692 |
-
template <class T1, class T2, class U, class V>
|
| 8693 |
-
void construct(pair<T1, T2>* p, const pair<U, V>& x);
|
| 8694 |
-
```
|
| 8695 |
-
|
| 8696 |
-
*Effects:* Equivalent to
|
| 8697 |
-
`this->construct(p, piecewise_construct, forward_as_tuple(x.first), forward_as_tuple(x.second))`.
|
| 8698 |
-
|
| 8699 |
-
``` cpp
|
| 8700 |
-
template <class T1, class T2, class U, class V>
|
| 8701 |
-
void construct(pair<T1, T2>* p, pair<U, V>&& x);
|
| 8702 |
-
```
|
| 8703 |
-
|
| 8704 |
-
*Effects:* Equivalent to
|
| 8705 |
-
`this->construct(p, piecewise_construct, forward_as_tuple(std::forward<U>(x.first)), forward_as_tuple(std::forward<V>(x.second)))`.
|
| 8706 |
-
|
| 8707 |
-
``` cpp
|
| 8708 |
-
template <class T>
|
| 8709 |
-
void destroy(T* p);
|
| 8710 |
-
```
|
| 8711 |
-
|
| 8712 |
-
*Effects:* calls
|
| 8713 |
-
*`OUTERMOST_ALLOC_TRAITS`*`(*this)::destroy(`*`OUTERMOST`*`(*this), p)`.
|
| 8714 |
-
|
| 8715 |
-
``` cpp
|
| 8716 |
-
scoped_allocator_adaptor select_on_container_copy_construction() const;
|
| 8717 |
-
```
|
| 8718 |
-
|
| 8719 |
-
*Returns:* A new scoped_allocator_adaptor object where each allocator
|
| 8720 |
-
`A` in the adaptor is initialized from the result of calling
|
| 8721 |
-
`allocator_traits<A>::select_on_container_copy_construction()` on the
|
| 8722 |
-
corresponding allocator in `*this`.
|
| 8723 |
-
|
| 8724 |
-
### Scoped allocator operators <a id="scoped.adaptor.operators">[[scoped.adaptor.operators]]</a>
|
| 8725 |
-
|
| 8726 |
-
``` cpp
|
| 8727 |
-
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 8728 |
-
bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 8729 |
-
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 8730 |
-
```
|
| 8731 |
-
|
| 8732 |
-
*Returns:* `a.outer_allocator() == b.outer_allocator()` if
|
| 8733 |
-
`sizeof...(InnerAllocs)` is zero; otherwise,
|
| 8734 |
-
`a.outer_allocator() == b.outer_allocator()` `&&`
|
| 8735 |
-
`a.inner_allocator() == b.inner_allocator()`.
|
| 8736 |
-
|
| 8737 |
-
``` cpp
|
| 8738 |
-
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 8739 |
-
bool operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 8740 |
-
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 8741 |
-
```
|
| 8742 |
-
|
| 8743 |
-
*Returns:* `!(a == b)`.
|
| 8744 |
|
| 8745 |
## Class `type_index` <a id="type.index">[[type.index]]</a>
|
| 8746 |
|
| 8747 |
### Header `<typeindex>` synopsis <a id="type.index.synopsis">[[type.index.synopsis]]</a>
|
| 8748 |
|
|
@@ -8786,131 +13835,299 @@ can be used as an index type in associative containers (
|
|
| 8786 |
|
| 8787 |
``` cpp
|
| 8788 |
type_index(const type_info& rhs) noexcept;
|
| 8789 |
```
|
| 8790 |
|
| 8791 |
-
*Effects:*
|
| 8792 |
`target = &rhs`.
|
| 8793 |
|
| 8794 |
``` cpp
|
| 8795 |
bool operator==(const type_index& rhs) const noexcept;
|
| 8796 |
```
|
| 8797 |
|
| 8798 |
-
*Returns:* `*target == *rhs.target`
|
| 8799 |
|
| 8800 |
``` cpp
|
| 8801 |
bool operator!=(const type_index& rhs) const noexcept;
|
| 8802 |
```
|
| 8803 |
|
| 8804 |
-
*Returns:* `*target != *rhs.target`
|
| 8805 |
|
| 8806 |
``` cpp
|
| 8807 |
bool operator<(const type_index& rhs) const noexcept;
|
| 8808 |
```
|
| 8809 |
|
| 8810 |
-
*Returns:* `target->before(*rhs.target)`
|
| 8811 |
|
| 8812 |
``` cpp
|
| 8813 |
bool operator<=(const type_index& rhs) const noexcept;
|
| 8814 |
```
|
| 8815 |
|
| 8816 |
-
*Returns:* `!rhs.target->before(*target)`
|
| 8817 |
|
| 8818 |
``` cpp
|
| 8819 |
bool operator>(const type_index& rhs) const noexcept;
|
| 8820 |
```
|
| 8821 |
|
| 8822 |
-
*Returns:* `rhs.target->before(*target)`
|
| 8823 |
|
| 8824 |
``` cpp
|
| 8825 |
bool operator>=(const type_index& rhs) const noexcept;
|
| 8826 |
```
|
| 8827 |
|
| 8828 |
-
*Returns:* `!target->before(*rhs.target)`
|
| 8829 |
|
| 8830 |
``` cpp
|
| 8831 |
size_t hash_code() const noexcept;
|
| 8832 |
```
|
| 8833 |
|
| 8834 |
-
*Returns:* `target->hash_code()`
|
| 8835 |
|
| 8836 |
``` cpp
|
| 8837 |
const char* name() const noexcept;
|
| 8838 |
```
|
| 8839 |
|
| 8840 |
-
*Returns:* `target->name()`
|
| 8841 |
|
| 8842 |
### Hash support <a id="type.index.hash">[[type.index.hash]]</a>
|
| 8843 |
|
| 8844 |
``` cpp
|
| 8845 |
template <> struct hash<type_index>;
|
| 8846 |
```
|
| 8847 |
|
| 8848 |
-
|
| 8849 |
-
|
| 8850 |
-
|
| 8851 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8852 |
|
| 8853 |
<!-- Link reference definitions -->
|
| 8854 |
[alg.sorting]: algorithms.md#alg.sorting
|
| 8855 |
[algorithms]: algorithms.md#algorithms
|
|
|
|
| 8856 |
[allocator.adaptor]: #allocator.adaptor
|
| 8857 |
[allocator.adaptor.cnstr]: #allocator.adaptor.cnstr
|
| 8858 |
[allocator.adaptor.members]: #allocator.adaptor.members
|
| 8859 |
[allocator.adaptor.syn]: #allocator.adaptor.syn
|
| 8860 |
[allocator.adaptor.types]: #allocator.adaptor.types
|
| 8861 |
[allocator.globals]: #allocator.globals
|
| 8862 |
[allocator.members]: #allocator.members
|
| 8863 |
[allocator.requirements]: library.md#allocator.requirements
|
|
|
|
| 8864 |
[allocator.tag]: #allocator.tag
|
| 8865 |
[allocator.traits]: #allocator.traits
|
| 8866 |
[allocator.traits.members]: #allocator.traits.members
|
| 8867 |
[allocator.traits.types]: #allocator.traits.types
|
| 8868 |
[allocator.uses]: #allocator.uses
|
| 8869 |
[allocator.uses.construction]: #allocator.uses.construction
|
| 8870 |
[allocator.uses.trait]: #allocator.uses.trait
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8871 |
[arithmetic.operations]: #arithmetic.operations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8872 |
[array]: containers.md#array
|
| 8873 |
[associative]: containers.md#associative
|
| 8874 |
[atomics.order]: atomics.md#atomics.order
|
| 8875 |
[atomics.types.operations]: atomics.md#atomics.types.operations
|
| 8876 |
[basic.align]: basic.md#basic.align
|
| 8877 |
[basic.compound]: basic.md#basic.compound
|
| 8878 |
[basic.def.odr]: basic.md#basic.def.odr
|
| 8879 |
[basic.fundamental]: basic.md#basic.fundamental
|
| 8880 |
[basic.life]: basic.md#basic.life
|
|
|
|
| 8881 |
[basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
|
| 8882 |
-
[basic.type.qualifier]: basic.md#basic.type.qualifier
|
| 8883 |
[basic.types]: basic.md#basic.types
|
|
|
|
|
|
|
| 8884 |
[bitset.cons]: #bitset.cons
|
| 8885 |
[bitset.hash]: #bitset.hash
|
| 8886 |
[bitset.members]: #bitset.members
|
| 8887 |
[bitset.operators]: #bitset.operators
|
|
|
|
| 8888 |
[bitwise.operations]: #bitwise.operations
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8889 |
[c.malloc]: #c.malloc
|
| 8890 |
-
[c.strings]: strings.md#c.strings
|
| 8891 |
-
[class]: class.md#class
|
| 8892 |
-
[class.abstract]: class.md#class.abstract
|
| 8893 |
-
[class.derived]: class.md#class.derived
|
| 8894 |
-
[class.dtor]: special.md#class.dtor
|
| 8895 |
-
[class.virtual]: class.md#class.virtual
|
| 8896 |
[comparisons]: #comparisons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8897 |
[conv.array]: conv.md#conv.array
|
| 8898 |
[conv.func]: conv.md#conv.func
|
| 8899 |
[conv.lval]: conv.md#conv.lval
|
| 8900 |
[conv.rank]: conv.md#conv.rank
|
| 8901 |
-
[
|
| 8902 |
-
[
|
| 8903 |
-
[
|
| 8904 |
[dcl.array]: dcl.md#dcl.array
|
| 8905 |
-
[dcl.
|
| 8906 |
[dcl.ref]: dcl.md#dcl.ref
|
| 8907 |
[declval]: #declval
|
| 8908 |
[default.allocator]: #default.allocator
|
| 8909 |
-
[
|
| 8910 |
-
[
|
| 8911 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8912 |
[expr]: expr.md#expr
|
| 8913 |
[expr.add]: expr.md#expr.add
|
| 8914 |
[expr.alignof]: expr.md#expr.alignof
|
| 8915 |
[expr.bit.and]: expr.md#expr.bit.and
|
| 8916 |
[expr.call]: expr.md#expr.call
|
|
@@ -8918,23 +14135,28 @@ result as `index.hash_code()`.
|
|
| 8918 |
[expr.log.and]: expr.md#expr.log.and
|
| 8919 |
[expr.log.or]: expr.md#expr.log.or
|
| 8920 |
[expr.mul]: expr.md#expr.mul
|
| 8921 |
[expr.or]: expr.md#expr.or
|
| 8922 |
[expr.rel]: expr.md#expr.rel
|
| 8923 |
-
[expr.unary.noexcept]: expr.md#expr.unary.noexcept
|
| 8924 |
[expr.unary.op]: expr.md#expr.unary.op
|
| 8925 |
[expr.xor]: expr.md#expr.xor
|
| 8926 |
[forward]: #forward
|
| 8927 |
[forward.iterators]: iterators.md#forward.iterators
|
| 8928 |
[func.bind]: #func.bind
|
| 8929 |
[func.bind.bind]: #func.bind.bind
|
| 8930 |
[func.bind.isbind]: #func.bind.isbind
|
| 8931 |
[func.bind.isplace]: #func.bind.isplace
|
| 8932 |
[func.bind.place]: #func.bind.place
|
| 8933 |
[func.def]: #func.def
|
|
|
|
| 8934 |
[func.memfn]: #func.memfn
|
|
|
|
| 8935 |
[func.require]: #func.require
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8936 |
[func.wrap]: #func.wrap
|
| 8937 |
[func.wrap.badcall]: #func.wrap.badcall
|
| 8938 |
[func.wrap.badcall.const]: #func.wrap.badcall.const
|
| 8939 |
[func.wrap.func]: #func.wrap.func
|
| 8940 |
[func.wrap.func.alg]: #func.wrap.func.alg
|
|
@@ -8943,27 +14165,51 @@ result as `index.hash_code()`.
|
|
| 8943 |
[func.wrap.func.inv]: #func.wrap.func.inv
|
| 8944 |
[func.wrap.func.mod]: #func.wrap.func.mod
|
| 8945 |
[func.wrap.func.nullptr]: #func.wrap.func.nullptr
|
| 8946 |
[func.wrap.func.targ]: #func.wrap.func.targ
|
| 8947 |
[function.objects]: #function.objects
|
|
|
|
| 8948 |
[hash.requirements]: library.md#hash.requirements
|
| 8949 |
[input.iterators]: iterators.md#input.iterators
|
| 8950 |
[intro.multithread]: intro.md#intro.multithread
|
| 8951 |
[intseq]: #intseq
|
| 8952 |
[intseq.general]: #intseq.general
|
| 8953 |
[intseq.intseq]: #intseq.intseq
|
| 8954 |
[intseq.make]: #intseq.make
|
| 8955 |
[invalid.argument]: diagnostics.md#invalid.argument
|
| 8956 |
[iostate.flags]: input.md#iostate.flags
|
| 8957 |
[istream.formatted]: input.md#istream.formatted
|
| 8958 |
-
[
|
| 8959 |
[logical.operations]: #logical.operations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8960 |
[memory]: #memory
|
| 8961 |
[memory.general]: #memory.general
|
| 8962 |
[memory.syn]: #memory.syn
|
| 8963 |
[meta]: #meta
|
| 8964 |
[meta.help]: #meta.help
|
|
|
|
| 8965 |
[meta.rel]: #meta.rel
|
| 8966 |
[meta.rqmts]: #meta.rqmts
|
| 8967 |
[meta.trans]: #meta.trans
|
| 8968 |
[meta.trans.arr]: #meta.trans.arr
|
| 8969 |
[meta.trans.cv]: #meta.trans.cv
|
|
@@ -8975,21 +14221,37 @@ result as `index.hash_code()`.
|
|
| 8975 |
[meta.unary]: #meta.unary
|
| 8976 |
[meta.unary.cat]: #meta.unary.cat
|
| 8977 |
[meta.unary.comp]: #meta.unary.comp
|
| 8978 |
[meta.unary.prop]: #meta.unary.prop
|
| 8979 |
[meta.unary.prop.query]: #meta.unary.prop.query
|
| 8980 |
-
[
|
| 8981 |
-
[
|
| 8982 |
-
[negators]: #negators
|
| 8983 |
[new.delete]: language.md#new.delete
|
| 8984 |
[nullablepointer.requirements]: library.md#nullablepointer.requirements
|
| 8985 |
[numeric.requirements]: numerics.md#numeric.requirements
|
| 8986 |
[operators]: #operators
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8987 |
[ostream.formatted]: input.md#ostream.formatted
|
| 8988 |
[out.of.range]: diagnostics.md#out.of.range
|
| 8989 |
-
[output.iterators]: iterators.md#output.iterators
|
| 8990 |
[over.match.call]: over.md#over.match.call
|
|
|
|
| 8991 |
[overflow.error]: diagnostics.md#overflow.error
|
| 8992 |
[pair.astuple]: #pair.astuple
|
| 8993 |
[pair.piecewise]: #pair.piecewise
|
| 8994 |
[pairs]: #pairs
|
| 8995 |
[pairs.general]: #pairs.general
|
|
@@ -9016,29 +14278,41 @@ result as `index.hash_code()`.
|
|
| 9016 |
[scoped.adaptor.operators]: #scoped.adaptor.operators
|
| 9017 |
[smartptr]: #smartptr
|
| 9018 |
[special]: special.md#special
|
| 9019 |
[specialized.addressof]: #specialized.addressof
|
| 9020 |
[specialized.algorithms]: #specialized.algorithms
|
|
|
|
| 9021 |
[stmt.dcl]: stmt.md#stmt.dcl
|
| 9022 |
-
[
|
| 9023 |
[support.dynamic]: language.md#support.dynamic
|
| 9024 |
[swappable.requirements]: library.md#swappable.requirements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9025 |
[tab:ratio.arithmetic]: #tab:ratio.arithmetic
|
| 9026 |
[tab:time.clock]: #tab:time.clock
|
| 9027 |
-
[tab:util.hdr.cstdlib]: #tab:util.hdr.cstdlib
|
| 9028 |
-
[tab:util.hdr.cstring]: #tab:util.hdr.cstring
|
| 9029 |
-
[tab:util.hdr.ctime]: #tab:util.hdr.ctime
|
| 9030 |
[tab:util.lib.summary]: #tab:util.lib.summary
|
|
|
|
| 9031 |
[template.bitset]: #template.bitset
|
| 9032 |
-
[temporary.buffer]: #temporary.buffer
|
| 9033 |
[time]: #time
|
| 9034 |
[time.clock]: #time.clock
|
| 9035 |
[time.clock.hires]: #time.clock.hires
|
| 9036 |
[time.clock.req]: #time.clock.req
|
| 9037 |
[time.clock.steady]: #time.clock.steady
|
| 9038 |
[time.clock.system]: #time.clock.system
|
| 9039 |
[time.duration]: #time.duration
|
|
|
|
| 9040 |
[time.duration.arithmetic]: #time.duration.arithmetic
|
| 9041 |
[time.duration.cast]: #time.duration.cast
|
| 9042 |
[time.duration.comparisons]: #time.duration.comparisons
|
| 9043 |
[time.duration.cons]: #time.duration.cons
|
| 9044 |
[time.duration.literals]: #time.duration.literals
|
|
@@ -9058,36 +14332,41 @@ result as `index.hash_code()`.
|
|
| 9058 |
[time.traits]: #time.traits
|
| 9059 |
[time.traits.duration_values]: #time.traits.duration_values
|
| 9060 |
[time.traits.is_fp]: #time.traits.is_fp
|
| 9061 |
[time.traits.specializations]: #time.traits.specializations
|
| 9062 |
[tuple]: #tuple
|
|
|
|
| 9063 |
[tuple.assign]: #tuple.assign
|
| 9064 |
[tuple.cnstr]: #tuple.cnstr
|
| 9065 |
[tuple.creation]: #tuple.creation
|
| 9066 |
[tuple.elem]: #tuple.elem
|
| 9067 |
[tuple.general]: #tuple.general
|
| 9068 |
[tuple.helper]: #tuple.helper
|
| 9069 |
[tuple.rel]: #tuple.rel
|
| 9070 |
[tuple.special]: #tuple.special
|
| 9071 |
[tuple.swap]: #tuple.swap
|
|
|
|
| 9072 |
[tuple.traits]: #tuple.traits
|
| 9073 |
[tuple.tuple]: #tuple.tuple
|
| 9074 |
[type.index]: #type.index
|
| 9075 |
[type.index.hash]: #type.index.hash
|
| 9076 |
[type.index.members]: #type.index.members
|
| 9077 |
[type.index.overview]: #type.index.overview
|
| 9078 |
[type.index.synopsis]: #type.index.synopsis
|
|
|
|
|
|
|
| 9079 |
[uninitialized.copy]: #uninitialized.copy
|
| 9080 |
[uninitialized.fill]: #uninitialized.fill
|
| 9081 |
-
[uninitialized.
|
| 9082 |
[unique.ptr]: #unique.ptr
|
| 9083 |
[unique.ptr.create]: #unique.ptr.create
|
| 9084 |
[unique.ptr.dltr]: #unique.ptr.dltr
|
| 9085 |
[unique.ptr.dltr.dflt]: #unique.ptr.dltr.dflt
|
| 9086 |
[unique.ptr.dltr.dflt1]: #unique.ptr.dltr.dflt1
|
| 9087 |
[unique.ptr.dltr.general]: #unique.ptr.dltr.general
|
| 9088 |
[unique.ptr.runtime]: #unique.ptr.runtime
|
|
|
|
| 9089 |
[unique.ptr.runtime.ctor]: #unique.ptr.runtime.ctor
|
| 9090 |
[unique.ptr.runtime.modifiers]: #unique.ptr.runtime.modifiers
|
| 9091 |
[unique.ptr.runtime.observers]: #unique.ptr.runtime.observers
|
| 9092 |
[unique.ptr.single]: #unique.ptr.single
|
| 9093 |
[unique.ptr.single.asgn]: #unique.ptr.single.asgn
|
|
@@ -9116,21 +14395,45 @@ result as `index.hash_code()`.
|
|
| 9116 |
[util.smartptr.shared.mod]: #util.smartptr.shared.mod
|
| 9117 |
[util.smartptr.shared.obs]: #util.smartptr.shared.obs
|
| 9118 |
[util.smartptr.shared.spec]: #util.smartptr.shared.spec
|
| 9119 |
[util.smartptr.weak]: #util.smartptr.weak
|
| 9120 |
[util.smartptr.weak.assign]: #util.smartptr.weak.assign
|
|
|
|
| 9121 |
[util.smartptr.weak.const]: #util.smartptr.weak.const
|
| 9122 |
[util.smartptr.weak.dest]: #util.smartptr.weak.dest
|
| 9123 |
[util.smartptr.weak.mod]: #util.smartptr.weak.mod
|
| 9124 |
[util.smartptr.weak.obs]: #util.smartptr.weak.obs
|
| 9125 |
[util.smartptr.weak.spec]: #util.smartptr.weak.spec
|
| 9126 |
-
[util.smartptr.weakptr]: #util.smartptr.weakptr
|
| 9127 |
[utilities]: #utilities
|
| 9128 |
[utilities.general]: #utilities.general
|
| 9129 |
[utility]: #utility
|
|
|
|
| 9130 |
[utility.exchange]: #utility.exchange
|
|
|
|
| 9131 |
[utility.swap]: #utility.swap
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9132 |
|
| 9133 |
[^1]: `pointer_safety::preferred` might be returned to indicate that a
|
| 9134 |
leak detector is running so that the program can avoid spurious leak
|
| 9135 |
reports.
|
| 9136 |
|
|
|
|
| 10 |
**Table: General utilities library summary** <a id="tab:util.lib.summary">[tab:util.lib.summary]</a>
|
| 11 |
|
| 12 |
| Subclause | | Header |
|
| 13 |
| --------------------- | -------------------------------- | -------------------- |
|
| 14 |
| [[utility]] | Utility components | `<utility>` |
|
| 15 |
+
| [[intseq]] | Compile-time integer sequences | `<utility>` |
|
| 16 |
| [[pairs]] | Pairs | `<utility>` |
|
| 17 |
| [[tuple]] | Tuples | `<tuple>` |
|
| 18 |
+
| [[optional]] | Optional objects | `<optional>` |
|
| 19 |
+
| [[variant]] | Variants | `<variant>` |
|
| 20 |
+
| [[any]] | Storage for any type | `<any>` |
|
| 21 |
+
| [[bitset]] | Fixed-size sequences of bits | `<bitset>` |
|
| 22 |
+
| [[memory]] | Memory | `<memory>` |
|
| 23 |
+
| | | `<cstdlib>` |
|
| 24 |
| [[smartptr]] | Smart pointers | `<memory>` |
|
| 25 |
+
| [[mem.res]] | Memory resources | `<memory_resource>` |
|
| 26 |
+
| [[allocator.adaptor]] | Scoped allocators | `<scoped_allocator>` |
|
| 27 |
| [[function.objects]] | Function objects | `<functional>` |
|
| 28 |
| [[meta]] | Type traits | `<type_traits>` |
|
| 29 |
| [[ratio]] | Compile-time rational arithmetic | `<ratio>` |
|
| 30 |
| [[time]] | Time utilities | `<chrono>` |
|
| 31 |
| | | `<ctime>` |
|
|
|
|
| 32 |
| [[type.index]] | Type indexes | `<typeindex>` |
|
| 33 |
+
| [[execpol]] | Execution policies | `<execution>` |
|
| 34 |
|
| 35 |
|
| 36 |
## Utility components <a id="utility">[[utility]]</a>
|
| 37 |
|
| 38 |
This subclause contains some basic function and class templates that are
|
| 39 |
used throughout the rest of the library.
|
| 40 |
|
| 41 |
+
### Header `<utility>` synopsis <a id="utility.syn">[[utility.syn]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
``` cpp
|
| 44 |
+
#include <initializer_list> // see [initializer_list.syn]
|
| 45 |
|
| 46 |
namespace std {
|
| 47 |
+
// [operators], operators
|
| 48 |
namespace rel_ops {
|
| 49 |
template<class T> bool operator!=(const T&, const T&);
|
| 50 |
template<class T> bool operator> (const T&, const T&);
|
| 51 |
template<class T> bool operator<=(const T&, const T&);
|
| 52 |
template<class T> bool operator>=(const T&, const T&);
|
| 53 |
}
|
| 54 |
|
| 55 |
+
// [utility.swap], swap
|
| 56 |
+
template <class T>
|
| 57 |
+
void swap(T& a, T& b) noexcept(see below);
|
| 58 |
+
template <class T, size_t N>
|
| 59 |
+
void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v<T>);
|
| 60 |
|
| 61 |
+
// [utility.exchange], exchange
|
| 62 |
+
template <class T, class U = T>
|
| 63 |
+
T exchange(T& obj, U&& new_val);
|
| 64 |
|
| 65 |
+
// [forward], forward/move
|
| 66 |
template <class T>
|
| 67 |
constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 68 |
template <class T>
|
| 69 |
constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
|
| 70 |
template <class T>
|
| 71 |
constexpr remove_reference_t<T>&& move(T&&) noexcept;
|
| 72 |
template <class T>
|
| 73 |
constexpr conditional_t<
|
| 74 |
+
!is_nothrow_move_constructible_v<T> && is_copy_constructible_v<T>, const T&, T&&>
|
| 75 |
+
move_if_noexcept(T& x) noexcept;
|
| 76 |
|
| 77 |
+
// [utility.as_const], as_const
|
| 78 |
+
template <class T>
|
| 79 |
+
constexpr add_const_t<T>& as_const(T& t) noexcept;
|
| 80 |
+
template <class T>
|
| 81 |
+
void as_const(const T&&) = delete;
|
| 82 |
+
|
| 83 |
+
// [declval], declval
|
| 84 |
template <class T>
|
| 85 |
add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
| 86 |
+
%
|
| 87 |
|
| 88 |
+
// [intseq], Compile-time integer sequences
|
| 89 |
+
template<class T, T...>
|
| 90 |
+
struct integer_sequence;
|
| 91 |
+
template<size_t... I>
|
| 92 |
+
using index_sequence = integer_sequence<size_t, I...>;
|
| 93 |
|
| 94 |
+
template<class T, T N>
|
| 95 |
+
using make_integer_sequence = integer_sequence<T, see below>;
|
| 96 |
+
template<size_t N>
|
| 97 |
+
using make_index_sequence = make_integer_sequence<size_t, N>;
|
| 98 |
+
|
| 99 |
+
template<class... T>
|
| 100 |
+
using index_sequence_for = make_index_sequence<sizeof...(T)>;
|
| 101 |
+
|
| 102 |
+
// [pairs], class template pair
|
| 103 |
+
template <class T1, class T2>
|
| 104 |
+
struct pair;
|
| 105 |
+
|
| 106 |
+
// [pairs.spec], pair specialized algorithms
|
| 107 |
template <class T1, class T2>
|
| 108 |
constexpr bool operator==(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 109 |
template <class T1, class T2>
|
| 110 |
constexpr bool operator< (const pair<T1, T2>&, const pair<T1, T2>&);
|
| 111 |
template <class T1, class T2>
|
|
|
|
| 114 |
constexpr bool operator> (const pair<T1, T2>&, const pair<T1, T2>&);
|
| 115 |
template <class T1, class T2>
|
| 116 |
constexpr bool operator>=(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 117 |
template <class T1, class T2>
|
| 118 |
constexpr bool operator<=(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 119 |
+
|
| 120 |
template <class T1, class T2>
|
| 121 |
void swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
|
| 122 |
+
|
| 123 |
template <class T1, class T2>
|
| 124 |
constexpr see below make_pair(T1&&, T2&&);
|
| 125 |
|
| 126 |
+
// [pair.astuple], tuple-like access to pair
|
| 127 |
template <class T> class tuple_size;
|
| 128 |
template <size_t I, class T> class tuple_element;
|
| 129 |
|
| 130 |
template <class T1, class T2> struct tuple_size<pair<T1, T2>>;
|
| 131 |
template <class T1, class T2> struct tuple_element<0, pair<T1, T2>>;
|
| 132 |
template <class T1, class T2> struct tuple_element<1, pair<T1, T2>>;
|
| 133 |
|
| 134 |
template<size_t I, class T1, class T2>
|
| 135 |
+
constexpr tuple_element_t<I, pair<T1, T2>>& get(pair<T1, T2>&) noexcept;
|
|
|
|
| 136 |
template<size_t I, class T1, class T2>
|
| 137 |
+
constexpr tuple_element_t<I, pair<T1, T2>>&& get(pair<T1, T2>&&) noexcept;
|
|
|
|
| 138 |
template<size_t I, class T1, class T2>
|
| 139 |
+
constexpr const tuple_element_t<I, pair<T1, T2>>& get(const pair<T1, T2>&) noexcept;
|
| 140 |
+
template<size_t I, class T1, class T2>
|
| 141 |
+
constexpr const tuple_element_t<I, pair<T1, T2>>&& get(const pair<T1, T2>&&) noexcept;
|
| 142 |
+
template <class T1, class T2>
|
| 143 |
+
constexpr T1& get(pair<T1, T2>& p) noexcept;
|
| 144 |
+
template <class T1, class T2>
|
| 145 |
+
constexpr const T1& get(const pair<T1, T2>& p) noexcept;
|
| 146 |
+
template <class T1, class T2>
|
| 147 |
+
constexpr T1&& get(pair<T1, T2>&& p) noexcept;
|
| 148 |
+
template <class T1, class T2>
|
| 149 |
+
constexpr const T1&& get(const pair<T1, T2>&& p) noexcept;
|
| 150 |
+
template <class T2, class T1>
|
| 151 |
+
constexpr T2& get(pair<T1, T2>& p) noexcept;
|
| 152 |
+
template <class T2, class T1>
|
| 153 |
+
constexpr const T2& get(const pair<T1, T2>& p) noexcept;
|
| 154 |
+
template <class T2, class T1>
|
| 155 |
+
constexpr T2&& get(pair<T1, T2>&& p) noexcept;
|
| 156 |
+
template <class T2, class T1>
|
| 157 |
+
constexpr const T2&& get(const pair<T1, T2>&& p) noexcept;
|
| 158 |
|
| 159 |
// [pair.piecewise], pair piecewise construction
|
| 160 |
+
struct piecewise_construct_t {
|
| 161 |
+
explicit piecewise_construct_t() = default;
|
| 162 |
+
};
|
| 163 |
+
inline constexpr piecewise_construct_t piecewise_construct{};
|
| 164 |
+
template <class... Types> class tuple; // defined in <tuple> ([tuple.syn])
|
| 165 |
|
| 166 |
+
// in-place construction
|
| 167 |
+
struct in_place_t {
|
| 168 |
+
explicit in_place_t() = default;
|
| 169 |
+
};
|
| 170 |
+
inline constexpr in_place_t in_place{};
|
| 171 |
+
template <class T>
|
| 172 |
+
struct in_place_type_t {
|
| 173 |
+
explicit in_place_type_t() = default;
|
| 174 |
+
};
|
| 175 |
+
template <class T> inline constexpr in_place_type_t<T> in_place_type{};
|
| 176 |
+
template <size_t I>
|
| 177 |
+
struct in_place_index_t {
|
| 178 |
+
explicit in_place_index_t() = default;
|
| 179 |
+
};
|
| 180 |
+
template <size_t I> inline constexpr in_place_index_t<I> in_place_index{};
|
| 181 |
|
| 182 |
+
{chars_format{chars_format{chars_format{chars_format
|
| 183 |
+
// floating-point format for primitive numerical conversion
|
| 184 |
+
enum class chars_format {
|
| 185 |
+
scientific = unspecified,
|
| 186 |
+
fixed = unspecified,
|
| 187 |
+
hex = unspecified,
|
| 188 |
+
general = fixed | scientific
|
| 189 |
+
};
|
| 190 |
|
| 191 |
+
{to_chars_result{to_chars_result}
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
+
// [utility.to.chars], primitive numerical output conversion
|
| 194 |
+
struct to_chars_result {
|
| 195 |
+
char* ptr;
|
| 196 |
+
error_code ec;
|
| 197 |
+
};
|
| 198 |
+
|
| 199 |
+
to_chars_result to_chars(char* first, char* last, see below value, int base = 10);
|
| 200 |
+
|
| 201 |
+
to_chars_result to_chars(char* first, char* last, float value);
|
| 202 |
+
to_chars_result to_chars(char* first, char* last, double value);
|
| 203 |
+
to_chars_result to_chars(char* first, char* last, long double value);
|
| 204 |
+
|
| 205 |
+
to_chars_result to_chars(char* first, char* last, float value,
|
| 206 |
+
chars_format fmt);
|
| 207 |
+
to_chars_result to_chars(char* first, char* last, double value,
|
| 208 |
+
chars_format fmt);
|
| 209 |
+
to_chars_result to_chars(char* first, char* last, long double value,
|
| 210 |
+
chars_format fmt);
|
| 211 |
+
|
| 212 |
+
to_chars_result to_chars(char* first, char* last, float value,
|
| 213 |
+
chars_format fmt, int precision);
|
| 214 |
+
to_chars_result to_chars(char* first, char* last, double value,
|
| 215 |
+
chars_format fmt, int precision);
|
| 216 |
+
to_chars_result to_chars(char* first, char* last, long double value,
|
| 217 |
+
chars_format fmt, int precision);
|
| 218 |
+
|
| 219 |
+
{from_chars_result{from_chars_result}
|
| 220 |
+
|
| 221 |
+
// [utility.from.chars], primitive numerical input conversion
|
| 222 |
+
struct from_chars_result {
|
| 223 |
+
const char* ptr;
|
| 224 |
+
error_code ec;
|
| 225 |
+
};
|
| 226 |
+
|
| 227 |
+
from_chars_result from_chars(const char* first, const char* last,
|
| 228 |
+
see below& value, int base = 10);
|
| 229 |
+
|
| 230 |
+
from_chars_result from_chars(const char* first, const char* last, float& value,
|
| 231 |
+
chars_format fmt = chars_format::general);
|
| 232 |
+
from_chars_result from_chars(const char* first, const char* last, double& value,
|
| 233 |
+
chars_format fmt = chars_format::general);
|
| 234 |
+
from_chars_result from_chars(const char* first, const char* last, long double& value,
|
| 235 |
+
chars_format fmt = chars_format::general);
|
| 236 |
}
|
| 237 |
```
|
| 238 |
|
| 239 |
+
The header `<utility>` defines several types and function templates that
|
| 240 |
+
are described in this Clause. It also defines the template `pair` and
|
| 241 |
+
various function templates that operate on `pair` objects.
|
| 242 |
+
|
| 243 |
+
The type `chars_format` is a bitmask type ([[bitmask.types]]) with
|
| 244 |
+
elements `scientific`, `fixed`, and `hex`.
|
| 245 |
+
|
| 246 |
### Operators <a id="operators">[[operators]]</a>
|
| 247 |
|
| 248 |
To avoid redundant definitions of `operator!=` out of `operator==` and
|
| 249 |
operators `>`, `<=`, and `>=` out of `operator<`, the library provides
|
| 250 |
the following:
|
|
|
|
| 252 |
``` cpp
|
| 253 |
template <class T> bool operator!=(const T& x, const T& y);
|
| 254 |
```
|
| 255 |
|
| 256 |
*Requires:* Type `T` is `EqualityComparable`
|
| 257 |
+
(Table [[tab:equalitycomparable]]).
|
| 258 |
|
| 259 |
*Returns:* `!(x == y)`.
|
| 260 |
|
| 261 |
``` cpp
|
| 262 |
template <class T> bool operator>(const T& x, const T& y);
|
| 263 |
```
|
| 264 |
|
| 265 |
*Requires:* Type `T` is `LessThanComparable`
|
| 266 |
+
(Table [[tab:lessthancomparable]]).
|
| 267 |
|
| 268 |
*Returns:* `y < x`.
|
| 269 |
|
| 270 |
``` cpp
|
| 271 |
template <class T> bool operator<=(const T& x, const T& y);
|
| 272 |
```
|
| 273 |
|
| 274 |
*Requires:* Type `T` is `LessThanComparable`
|
| 275 |
+
(Table [[tab:lessthancomparable]]).
|
| 276 |
|
| 277 |
*Returns:* `!(y < x)`.
|
| 278 |
|
| 279 |
``` cpp
|
| 280 |
template <class T> bool operator>=(const T& x, const T& y);
|
| 281 |
```
|
| 282 |
|
| 283 |
*Requires:* Type `T` is `LessThanComparable`
|
| 284 |
+
(Table [[tab:lessthancomparable]]).
|
| 285 |
|
| 286 |
*Returns:* `!(x < y)`.
|
| 287 |
|
| 288 |
In this library, whenever a declaration is provided for an `operator!=`,
|
| 289 |
`operator>`, `operator>=`, or `operator<=`, and requirements and
|
| 290 |
semantics are not explicitly provided, the requirements and semantics
|
| 291 |
are as specified in this Clause.
|
| 292 |
|
| 293 |
+
### `swap` <a id="utility.swap">[[utility.swap]]</a>
|
| 294 |
|
| 295 |
``` cpp
|
| 296 |
+
template <class T>
|
| 297 |
+
void swap(T& a, T& b) noexcept(see below);
|
| 298 |
```
|
| 299 |
|
| 300 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 301 |
+
unless `is_move_constructible_v<T>` is `true` and
|
| 302 |
+
`is_move_assignable_v<T>` is `true`. The expression inside `noexcept` is
|
| 303 |
+
equivalent to:
|
| 304 |
|
| 305 |
``` cpp
|
| 306 |
+
is_nothrow_move_constructible_v<T> && is_nothrow_move_assignable_v<T>
|
|
|
|
| 307 |
```
|
| 308 |
|
| 309 |
*Requires:* Type `T` shall be `MoveConstructible`
|
| 310 |
+
(Table [[tab:moveconstructible]]) and `MoveAssignable`
|
| 311 |
+
(Table [[tab:moveassignable]]).
|
| 312 |
|
| 313 |
*Effects:* Exchanges values stored in two locations.
|
| 314 |
|
| 315 |
``` cpp
|
| 316 |
template <class T, size_t N>
|
| 317 |
+
void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v<T>);
|
| 318 |
```
|
| 319 |
|
| 320 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 321 |
+
unless `is_swappable_v<T>` is `true`.
|
| 322 |
+
|
| 323 |
*Requires:* `a[i]` shall be swappable with ([[swappable.requirements]])
|
| 324 |
`b[i]` for all `i` in the range \[`0`, `N`).
|
| 325 |
|
| 326 |
+
*Effects:* As if by `swap_ranges(a, a + N, b)`.
|
| 327 |
|
| 328 |
+
### `exchange` <a id="utility.exchange">[[utility.exchange]]</a>
|
| 329 |
|
| 330 |
``` cpp
|
| 331 |
template <class T, class U = T> T exchange(T& obj, U&& new_val);
|
| 332 |
```
|
| 333 |
|
|
|
|
| 337 |
T old_val = std::move(obj);
|
| 338 |
obj = std::forward<U>(new_val);
|
| 339 |
return old_val;
|
| 340 |
```
|
| 341 |
|
| 342 |
+
### Forward/move helpers <a id="forward">[[forward]]</a>
|
| 343 |
|
| 344 |
The library provides templated helper functions to simplify applying
|
| 345 |
move semantics to an lvalue and to simplify the implementation of
|
| 346 |
+
forwarding functions. All functions specified in this subclause are
|
| 347 |
+
signal-safe ([[csignal.syn]]).
|
| 348 |
|
| 349 |
``` cpp
|
| 350 |
template <class T> constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 351 |
template <class T> constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
|
| 352 |
```
|
| 353 |
|
| 354 |
*Returns:* `static_cast<T&&>(t)`.
|
| 355 |
|
| 356 |
+
*Remarks:* If the second form is instantiated with an lvalue reference
|
| 357 |
+
type, the program is ill-formed.
|
| 358 |
+
|
| 359 |
+
[*Example 1*:
|
| 360 |
|
| 361 |
``` cpp
|
| 362 |
template <class T, class A1, class A2>
|
| 363 |
shared_ptr<T> factory(A1&& a1, A2&& a2) {
|
| 364 |
return shared_ptr<T>(new T(std::forward<A1>(a1), std::forward<A2>(a2)));
|
|
|
|
| 379 |
forwarded to `A`’s constructor as an rvalue. In the second call to
|
| 380 |
`factory`, `A1` is deduced as `int&`, so `i` is forwarded to `A`’s
|
| 381 |
constructor as an lvalue. In both cases, `A2` is deduced as `double`, so
|
| 382 |
1.414 is forwarded to `A`’s constructor as an rvalue.
|
| 383 |
|
| 384 |
+
— *end example*]
|
| 385 |
+
|
| 386 |
``` cpp
|
| 387 |
template <class T> constexpr remove_reference_t<T>&& move(T&& t) noexcept;
|
| 388 |
```
|
| 389 |
|
| 390 |
*Returns:* `static_cast<remove_reference_t<T>&&>(t)`.
|
| 391 |
|
| 392 |
+
[*Example 2*:
|
| 393 |
+
|
| 394 |
``` cpp
|
| 395 |
template <class T, class A1>
|
| 396 |
shared_ptr<T> factory(A1&& a1) {
|
| 397 |
return shared_ptr<T>(new T(std::forward<A1>(a1)));
|
| 398 |
}
|
|
|
|
| 415 |
`A(const A&)`, which copies the value from `a`. In the second call to
|
| 416 |
`factory`, because of the call `std::move(a)`, `A1` is deduced as `A`,
|
| 417 |
so `a` is forwarded as an rvalue. This binds to the constructor
|
| 418 |
`A(A&&)`, which moves the value from `a`.
|
| 419 |
|
| 420 |
+
— *end example*]
|
| 421 |
+
|
| 422 |
``` cpp
|
| 423 |
template <class T> constexpr conditional_t<
|
| 424 |
+
!is_nothrow_move_constructible_v<T> && is_copy_constructible_v<T>, const T&, T&&>
|
| 425 |
+
move_if_noexcept(T& x) noexcept;
|
| 426 |
```
|
| 427 |
|
| 428 |
+
*Returns:* `std::move(x)`.
|
| 429 |
+
|
| 430 |
+
### Function template `as_const` <a id="utility.as_const">[[utility.as_const]]</a>
|
| 431 |
+
|
| 432 |
+
``` cpp
|
| 433 |
+
template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept;
|
| 434 |
+
```
|
| 435 |
+
|
| 436 |
+
*Returns:* `t`.
|
| 437 |
|
| 438 |
### Function template `declval` <a id="declval">[[declval]]</a>
|
| 439 |
|
| 440 |
The library provides the function template `declval` to simplify the
|
| 441 |
definition of expressions which occur as unevaluated operands (Clause
|
| 442 |
[[expr]]).
|
| 443 |
|
| 444 |
``` cpp
|
| 445 |
+
template <class T> add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
|
|
|
| 446 |
```
|
| 447 |
|
| 448 |
*Remarks:* If this function is odr-used ([[basic.def.odr]]), the
|
| 449 |
program is ill-formed.
|
| 450 |
|
| 451 |
*Remarks:* The template parameter `T` of `declval` may be an incomplete
|
| 452 |
type.
|
| 453 |
|
| 454 |
+
[*Example 1*:
|
| 455 |
+
|
| 456 |
``` cpp
|
| 457 |
+
template <class To, class From> decltype(static_cast<To>(declval<From>())) convert(From&&);
|
|
|
|
| 458 |
```
|
| 459 |
|
| 460 |
declares a function template `convert` which only participates in
|
| 461 |
overloading if the type `From` can be explicitly converted to type `To`.
|
| 462 |
+
For another example see class template `common_type` (
|
| 463 |
+
[[meta.trans.other]]).
|
| 464 |
+
|
| 465 |
+
— *end example*]
|
| 466 |
+
|
| 467 |
+
### Primitive numeric output conversion <a id="utility.to.chars">[[utility.to.chars]]</a>
|
| 468 |
+
|
| 469 |
+
All functions named `to_chars` convert `value` into a character string
|
| 470 |
+
by successively filling the range \[`first`, `last`), where \[`first`,
|
| 471 |
+
`last`) is required to be a valid range. If the member `ec` of the
|
| 472 |
+
return value is such that the value, when converted to `bool`, is
|
| 473 |
+
`false`, the conversion was successful and the member `ptr` is the
|
| 474 |
+
one-past-the-end pointer of the characters written. Otherwise, the
|
| 475 |
+
member `ec` has the value `errc::value_too_large`, the member `ptr` has
|
| 476 |
+
the value `last`, and the contents of the range \[`first`, `last`) are
|
| 477 |
+
unspecified.
|
| 478 |
+
|
| 479 |
+
The functions that take a floating-point `value` but not a `precision`
|
| 480 |
+
parameter ensure that the string representation consists of the smallest
|
| 481 |
+
number of characters such that there is at least one digit before the
|
| 482 |
+
radix point (if present) and parsing the representation using the
|
| 483 |
+
corresponding `from_chars` function recovers `value` exactly.
|
| 484 |
+
|
| 485 |
+
[*Note 1*: This guarantee applies only if `to_chars` and `from_chars`
|
| 486 |
+
are executed on the same implementation. — *end note*]
|
| 487 |
+
|
| 488 |
+
The functions taking a `chars_format` parameter determine the conversion
|
| 489 |
+
specifier for `printf` as follows: The conversion specifier is `f` if
|
| 490 |
+
`fmt` is `chars_format::fixed`, `e` if `fmt` is
|
| 491 |
+
`chars_format::scientific`, `a` (without leading `"0x"` in the result)
|
| 492 |
+
if `fmt` is `chars_format::hex`, and `g` if `fmt` is
|
| 493 |
+
`chars_format::general`.
|
| 494 |
+
|
| 495 |
+
``` cpp
|
| 496 |
+
to_chars_result to_chars(char* first, char* last, see below value, int base = 10);
|
| 497 |
+
```
|
| 498 |
+
|
| 499 |
+
*Requires:* `base` has a value between 2 and 36 (inclusive).
|
| 500 |
+
|
| 501 |
+
*Effects:* The value of `value` is converted to a string of digits in
|
| 502 |
+
the given base (with no redundant leading zeroes). Digits in the range
|
| 503 |
+
10..35 (inclusive) are represented as lowercase characters `a`..`z`. If
|
| 504 |
+
`value` is less than zero, the representation starts with a minus sign.
|
| 505 |
+
|
| 506 |
+
*Throws:* Nothing.
|
| 507 |
+
|
| 508 |
+
*Remarks:* The implementation shall provide overloads for all signed and
|
| 509 |
+
unsigned integer types and `char` as the type of the parameter `value`.
|
| 510 |
+
|
| 511 |
+
``` cpp
|
| 512 |
+
to_chars_result to_chars(char* first, char* last, float value);
|
| 513 |
+
to_chars_result to_chars(char* first, char* last, double value);
|
| 514 |
+
to_chars_result to_chars(char* first, char* last, long double value);
|
| 515 |
+
```
|
| 516 |
+
|
| 517 |
+
*Effects:* `value` is converted to a string in the style of `printf` in
|
| 518 |
+
the `"C"` locale. The conversion specifier is `f` or `e`, chosen
|
| 519 |
+
according to the requirement for a shortest representation (see above);
|
| 520 |
+
a tie is resolved in favor of `f`.
|
| 521 |
+
|
| 522 |
+
*Throws:* Nothing.
|
| 523 |
+
|
| 524 |
+
``` cpp
|
| 525 |
+
to_chars_result to_chars(char* first, char* last, float value, chars_format fmt);
|
| 526 |
+
to_chars_result to_chars(char* first, char* last, double value, chars_format fmt);
|
| 527 |
+
to_chars_result to_chars(char* first, char* last, long double value, chars_format fmt);
|
| 528 |
+
```
|
| 529 |
+
|
| 530 |
+
*Requires:* `fmt` has the value of one of the enumerators of
|
| 531 |
+
`chars_format`.
|
| 532 |
+
|
| 533 |
+
*Effects:* `value` is converted to a string in the style of `printf` in
|
| 534 |
+
the `"C"` locale.
|
| 535 |
+
|
| 536 |
+
*Throws:* Nothing.
|
| 537 |
+
|
| 538 |
+
``` cpp
|
| 539 |
+
to_chars_result to_chars(char* first, char* last, float value,
|
| 540 |
+
chars_format fmt, int precision);
|
| 541 |
+
to_chars_result to_chars(char* first, char* last, double value,
|
| 542 |
+
chars_format fmt, int precision);
|
| 543 |
+
to_chars_result to_chars(char* first, char* last, long double value,
|
| 544 |
+
chars_format fmt, int precision);
|
| 545 |
+
```
|
| 546 |
+
|
| 547 |
+
*Requires:* `fmt` has the value of one of the enumerators of
|
| 548 |
+
`chars_format`.
|
| 549 |
+
|
| 550 |
+
*Effects:* `value` is converted to a string in the style of `printf` in
|
| 551 |
+
the `"C"` locale with the given precision.
|
| 552 |
+
|
| 553 |
+
*Throws:* Nothing.
|
| 554 |
+
|
| 555 |
+
ISO C 7.21.6.1.
|
| 556 |
+
|
| 557 |
+
### Primitive numeric input conversion <a id="utility.from.chars">[[utility.from.chars]]</a>
|
| 558 |
+
|
| 559 |
+
All functions named `from_chars` analyze the string \[`first`, `last`)
|
| 560 |
+
for a pattern, where \[`first`, `last`) is required to be a valid range.
|
| 561 |
+
If no characters match the pattern, `value` is unmodified, the member
|
| 562 |
+
`ptr` of the return value is `first` and the member `ec` is equal to
|
| 563 |
+
`errc::invalid_argument`. Otherwise, the characters matching the pattern
|
| 564 |
+
are interpreted as a representation of a value of the type of `value`.
|
| 565 |
+
The member `ptr` of the return value points to the first character not
|
| 566 |
+
matching the pattern, or has the value `last` if all characters match.
|
| 567 |
+
If the parsed value is not in the range representable by the type of
|
| 568 |
+
`value`, `value` is unmodified and the member `ec` of the return value
|
| 569 |
+
is equal to `errc::result_out_of_range`. Otherwise, `value` is set to
|
| 570 |
+
the parsed value and the member `ec` is set such that the conversion to
|
| 571 |
+
`bool` yields `false`.
|
| 572 |
+
|
| 573 |
+
``` cpp
|
| 574 |
+
from_chars_result from_chars(const char* first, const char* last,
|
| 575 |
+
see below& value, int base = 10);
|
| 576 |
+
```
|
| 577 |
+
|
| 578 |
+
*Requires:* `base` has a value between 2 and 36 (inclusive).
|
| 579 |
+
|
| 580 |
+
*Effects:* The pattern is the expected form of the subject sequence in
|
| 581 |
+
the `"C"` locale for the given nonzero base, as described for `strtol`,
|
| 582 |
+
except that no `"0x"` or `"0X"` prefix shall appear if the value of
|
| 583 |
+
`base` is 16, and except that a minus sign is the only sign that may
|
| 584 |
+
appear, and only if `value` has a signed type.
|
| 585 |
+
|
| 586 |
+
*Throws:* Nothing.
|
| 587 |
+
|
| 588 |
+
*Remarks:* The implementation shall provide overloads for all signed and
|
| 589 |
+
unsigned integer types and `char` as the referenced type of the
|
| 590 |
+
parameter `value`.
|
| 591 |
+
|
| 592 |
+
``` cpp
|
| 593 |
+
from_chars_result from_chars(const char* first, const char* last, float& value,
|
| 594 |
+
chars_format fmt = chars_format::general);
|
| 595 |
+
from_chars_result from_chars(const char* first, const char* last, double& value,
|
| 596 |
+
chars_format fmt = chars_format::general);
|
| 597 |
+
from_chars_result from_chars(const char* first, const char* last, long double& value,
|
| 598 |
+
chars_format fmt = chars_format::general);
|
| 599 |
+
```
|
| 600 |
+
|
| 601 |
+
*Requires:* `fmt` has the value of one of the enumerators of
|
| 602 |
+
`chars_format`.
|
| 603 |
+
|
| 604 |
+
*Effects:* The pattern is the expected form of the subject sequence in
|
| 605 |
+
the `"C"` locale, as described for `strtod`, except that
|
| 606 |
+
|
| 607 |
+
- the only sign that may appear is a minus sign;
|
| 608 |
+
- if `fmt` has `chars_format::scientific` set but not
|
| 609 |
+
`chars_format::fixed`, the otherwise optional exponent part shall
|
| 610 |
+
appear;
|
| 611 |
+
- if `fmt` has `chars_format::fixed` set but not
|
| 612 |
+
`chars_format::scientific`, the optional exponent part shall not
|
| 613 |
+
appear; and
|
| 614 |
+
- if `fmt` is `chars_format::hex`, the prefix `"0x"` or `"0X"` is
|
| 615 |
+
assumed. \[*Example 1*: The string `0x123` is parsed to have the value
|
| 616 |
+
`0` with remaining characters `x123`. — *end example*]
|
| 617 |
+
|
| 618 |
+
In any case, the resulting `value` is one of at most two floating-point
|
| 619 |
+
values closest to the value of the string matching the pattern.
|
| 620 |
+
|
| 621 |
+
*Throws:* Nothing.
|
| 622 |
+
|
| 623 |
+
ISO C 7.22.1.3, ISO C 7.22.1.4.
|
| 624 |
+
|
| 625 |
+
## Compile-time integer sequences <a id="intseq">[[intseq]]</a>
|
| 626 |
+
|
| 627 |
+
### In general <a id="intseq.general">[[intseq.general]]</a>
|
| 628 |
+
|
| 629 |
+
The library provides a class template that can represent an integer
|
| 630 |
+
sequence. When used as an argument to a function template the parameter
|
| 631 |
+
pack defining the sequence can be deduced and used in a pack expansion.
|
| 632 |
+
|
| 633 |
+
[*Note 1*: The `index_sequence` alias template is provided for the
|
| 634 |
+
common case of an integer sequence of type `size_t`; see also
|
| 635 |
+
[[tuple.apply]]. — *end note*]
|
| 636 |
+
|
| 637 |
+
### Class template `integer_sequence` <a id="intseq.intseq">[[intseq.intseq]]</a>
|
| 638 |
+
|
| 639 |
+
``` cpp
|
| 640 |
+
namespace std {
|
| 641 |
+
template<class T, T... I>
|
| 642 |
+
struct integer_sequence {
|
| 643 |
+
using value_type = T;
|
| 644 |
+
static constexpr size_t size() noexcept { return sizeof...(I); }
|
| 645 |
+
};
|
| 646 |
+
}
|
| 647 |
+
```
|
| 648 |
+
|
| 649 |
+
`T` shall be an integer type.
|
| 650 |
+
|
| 651 |
+
### Alias template `make_integer_sequence` <a id="intseq.make">[[intseq.make]]</a>
|
| 652 |
+
|
| 653 |
+
``` cpp
|
| 654 |
+
template<class T, T N>
|
| 655 |
+
using make_integer_sequence = integer_sequence<T, see below>;
|
| 656 |
+
```
|
| 657 |
+
|
| 658 |
+
If `N` is negative the program is ill-formed. The alias template
|
| 659 |
+
`make_integer_sequence` denotes a specialization of `integer_sequence`
|
| 660 |
+
with `N` template non-type arguments. The type
|
| 661 |
+
`make_integer_sequence<T, N>` denotes the type
|
| 662 |
+
`integer_sequence<T, 0, 1, ..., N-1>`.
|
| 663 |
+
|
| 664 |
+
[*Note 1*: `make_integer_sequence<int, 0>` denotes the type
|
| 665 |
+
`integer_sequence<int>` — *end note*]
|
| 666 |
|
| 667 |
## Pairs <a id="pairs">[[pairs]]</a>
|
| 668 |
|
| 669 |
### In general <a id="pairs.general">[[pairs.general]]</a>
|
| 670 |
|
|
|
|
| 675 |
[[tuple.elem]]).
|
| 676 |
|
| 677 |
### Class template `pair` <a id="pairs.pair">[[pairs.pair]]</a>
|
| 678 |
|
| 679 |
``` cpp
|
|
|
|
|
|
|
| 680 |
namespace std {
|
| 681 |
template <class T1, class T2>
|
| 682 |
struct pair {
|
| 683 |
+
using first_type = T1;
|
| 684 |
+
using second_type = T2;
|
| 685 |
|
| 686 |
T1 first;
|
| 687 |
T2 second;
|
| 688 |
+
|
| 689 |
pair(const pair&) = default;
|
| 690 |
pair(pair&&) = default;
|
| 691 |
+
\EXPLICIT constexpr pair();
|
| 692 |
+
\EXPLICIT constexpr pair(const T1& x, const T2& y);
|
| 693 |
+
template<class U1, class U2> \EXPLICIT constexpr pair(U1&& x, U2&& y);
|
| 694 |
+
template<class U1, class U2> \EXPLICIT constexpr pair(const pair<U1, U2>& p);
|
| 695 |
+
template<class U1, class U2> \EXPLICIT constexpr pair(pair<U1, U2>&& p);
|
| 696 |
template <class... Args1, class... Args2>
|
| 697 |
+
pair(piecewise_construct_t, tuple<Args1...> first_args, tuple<Args2...> second_args);
|
|
|
|
| 698 |
|
| 699 |
pair& operator=(const pair& p);
|
| 700 |
+
template<class U1, class U2> pair& operator=(const pair<U1, U2>& p);
|
| 701 |
pair& operator=(pair&& p) noexcept(see below);
|
| 702 |
+
template<class U1, class U2> pair& operator=(pair<U1, U2>&& p);
|
| 703 |
|
| 704 |
void swap(pair& p) noexcept(see below);
|
| 705 |
};
|
| 706 |
+
|
| 707 |
+
template<class T1, class T2>
|
| 708 |
+
pair(T1, T2) -> pair<T1, T2>;
|
| 709 |
}
|
| 710 |
```
|
| 711 |
|
| 712 |
Constructors and member functions of `pair` shall not throw exceptions
|
| 713 |
unless one of the element-wise operations specified to be called for
|
| 714 |
that operation throws an exception.
|
| 715 |
|
| 716 |
+
The defaulted move and copy constructor, respectively, of `pair` shall
|
| 717 |
+
be a constexpr function if and only if all required element-wise
|
| 718 |
initializations for copy and move, respectively, would satisfy the
|
| 719 |
+
requirements for a constexpr function. The destructor of `pair` shall be
|
| 720 |
+
a trivial destructor if
|
| 721 |
+
`(is_trivially_destructible_v<T1> && is_trivially_destructible_v<T2>)`
|
| 722 |
+
is `true`.
|
| 723 |
|
| 724 |
``` cpp
|
| 725 |
+
\EXPLICIT constexpr pair();
|
| 726 |
```
|
| 727 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 728 |
*Effects:* Value-initializes `first` and `second`.
|
| 729 |
|
| 730 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 731 |
+
unless `is_default_constructible_v<first_type>` is `true` and
|
| 732 |
+
`is_default_constructible_v<second_type>` is `true`.
|
| 733 |
+
|
| 734 |
+
[*Note 1*: This behavior can be implemented by a constructor template
|
| 735 |
+
with default template arguments. — *end note*]
|
| 736 |
+
|
| 737 |
+
The constructor is explicit if and only if either `first_type` or
|
| 738 |
+
`second_type` is not implicitly default-constructible.
|
| 739 |
+
|
| 740 |
+
[*Note 2*: This behavior can be implemented with a trait that checks
|
| 741 |
+
whether a `const first_type&` or a `const second_type&` can be
|
| 742 |
+
initialized with `{}`. — *end note*]
|
| 743 |
+
|
| 744 |
``` cpp
|
| 745 |
+
\EXPLICIT constexpr pair(const T1& x, const T2& y);
|
| 746 |
```
|
| 747 |
|
| 748 |
+
*Effects:* Initializes `first` with `x` and `second` with `y`.
|
|
|
|
| 749 |
|
| 750 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 751 |
+
unless `is_copy_constructible_v<first_type>` is `true` and
|
| 752 |
+
`is_copy_constructible_v<second_type>` is `true`. The constructor is
|
| 753 |
+
explicit if and only if
|
| 754 |
+
`is_convertible_v<const first_type&, first_type>` is `false` or
|
| 755 |
+
`is_convertible_v<const second_type&, second_type>` is `false`.
|
| 756 |
|
| 757 |
``` cpp
|
| 758 |
+
template<class U1, class U2> \EXPLICIT constexpr pair(U1&& x, U2&& y);
|
| 759 |
```
|
| 760 |
|
| 761 |
+
*Effects:* Initializes `first` with `std::forward<U1>(x)` and `second`
|
| 762 |
+
with `std::forward<U2>(y)`.
|
|
|
|
|
|
|
|
|
|
| 763 |
|
| 764 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 765 |
+
unless `is_constructible_v<first_type, U1&&>` is `true` and
|
| 766 |
+
`is_constructible_v<second_type, U2&&>` is `true`. The constructor is
|
| 767 |
+
explicit if and only if `is_convertible_v<U1&&, first_type>` is `false`
|
| 768 |
+
or `is_convertible_v<U2&&, second_type>` is `false`.
|
| 769 |
|
| 770 |
``` cpp
|
| 771 |
+
template<class U1, class U2> \EXPLICIT constexpr pair(const pair<U1, U2>& p);
|
| 772 |
```
|
| 773 |
|
|
|
|
|
|
|
|
|
|
| 774 |
*Effects:* Initializes members from the corresponding members of the
|
| 775 |
argument.
|
| 776 |
|
| 777 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 778 |
+
unless `is_constructible_v<first_type, const U1&>` is `true` and
|
| 779 |
+
`is_constructible_v<second_type, const U2&>` is `true`. The constructor
|
| 780 |
+
is explicit if and only if `is_convertible_v<const U1&, first_type>` is
|
| 781 |
+
`false` or `is_convertible_v<const U2&, second_type>` is `false`.
|
| 782 |
|
| 783 |
``` cpp
|
| 784 |
+
template<class U1, class U2> \EXPLICIT constexpr pair(pair<U1, U2>&& p);
|
| 785 |
```
|
| 786 |
|
| 787 |
+
*Effects:* Initializes `first` with `std::forward<U1>(p.first)` and
|
| 788 |
+
`second` with `std::forward<U2>(p.second)`.
|
| 789 |
|
| 790 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 791 |
+
unless `is_constructible_v<first_type, U1&&>` is `true` and
|
| 792 |
+
`is_constructible_v<second_type, U2&&>` is `true`. The constructor is
|
| 793 |
+
explicit if and only if `is_convertible_v<U1&&, first_type>` is `false`
|
| 794 |
+
or `is_convertible_v<U2&&, second_type>` is `false`.
|
|
|
|
|
|
|
| 795 |
|
| 796 |
``` cpp
|
| 797 |
template<class... Args1, class... Args2>
|
| 798 |
+
pair(piecewise_construct_t, tuple<Args1...> first_args, tuple<Args2...> second_args);
|
|
|
|
| 799 |
```
|
| 800 |
|
| 801 |
+
*Requires:* `is_constructible_v<first_type, Args1&&...>` is `true` and
|
| 802 |
+
`is_constructible_v<second_type, Args2&&...>` is `true`.
|
| 803 |
|
| 804 |
+
*Effects:* Initializes `first` with arguments of types `Args1...`
|
| 805 |
+
obtained by forwarding the elements of `first_args` and initializes
|
| 806 |
+
`second` with arguments of types `Args2...` obtained by forwarding the
|
| 807 |
+
elements of `second_args`. (Here, forwarding an element `x` of type `U`
|
| 808 |
+
within a `tuple` object means calling `std::forward<U>(x)`.) This form
|
| 809 |
+
of construction, whereby constructor arguments for `first` and `second`
|
| 810 |
+
are each provided in a separate `tuple` object, is called *piecewise
|
| 811 |
+
construction*.
|
| 812 |
|
| 813 |
``` cpp
|
| 814 |
pair& operator=(const pair& p);
|
| 815 |
```
|
| 816 |
|
|
|
|
|
|
|
|
|
|
| 817 |
*Effects:* Assigns `p.first` to `first` and `p.second` to `second`.
|
| 818 |
|
| 819 |
+
*Remarks:* This operator shall be defined as deleted unless
|
| 820 |
+
`is_copy_assignable_v<first_type>` is `true` and
|
| 821 |
+
`is_copy_assignable_v<second_type>` is `true`.
|
| 822 |
+
|
| 823 |
*Returns:* `*this`.
|
| 824 |
|
| 825 |
``` cpp
|
| 826 |
+
template<class U1, class U2> pair& operator=(const pair<U1, U2>& p);
|
| 827 |
```
|
| 828 |
|
|
|
|
|
|
|
|
|
|
| 829 |
*Effects:* Assigns `p.first` to `first` and `p.second` to `second`.
|
| 830 |
|
| 831 |
+
*Remarks:* This operator shall not participate in overload resolution
|
| 832 |
+
unless `is_assignable_v<first_type&, const U1&>` is `true` and
|
| 833 |
+
`is_assignable_v<second_type&, const U2&>` is `true`.
|
| 834 |
+
|
| 835 |
*Returns:* `*this`.
|
| 836 |
|
| 837 |
``` cpp
|
| 838 |
pair& operator=(pair&& p) noexcept(see below);
|
| 839 |
```
|
| 840 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 841 |
*Effects:* Assigns to `first` with `std::forward<first_type>(p.first)`
|
| 842 |
and to `second` with
|
| 843 |
`std::forward<second_type>(p.second)`.
|
| 844 |
|
| 845 |
+
*Remarks:* This operator shall be defined as deleted unless
|
| 846 |
+
`is_move_assignable_v<first_type>` is `true` and
|
| 847 |
+
`is_move_assignable_v<second_type>` is `true`.
|
| 848 |
+
|
| 849 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 850 |
+
|
| 851 |
+
``` cpp
|
| 852 |
+
is_nothrow_move_assignable_v<T1> && is_nothrow_move_assignable_v<T2>
|
| 853 |
+
```
|
| 854 |
+
|
| 855 |
*Returns:* `*this`.
|
| 856 |
|
| 857 |
``` cpp
|
| 858 |
+
template<class U1, class U2> pair& operator=(pair<U1, U2>&& p);
|
| 859 |
```
|
| 860 |
|
|
|
|
|
|
|
|
|
|
| 861 |
*Effects:* Assigns to `first` with `std::forward<U>(p.first)` and to
|
| 862 |
`second` with
|
| 863 |
`std::forward<V>(p.second)`.
|
| 864 |
|
| 865 |
+
*Remarks:* This operator shall not participate in overload resolution
|
| 866 |
+
unless `is_assignable_v<first_type&, U1&&>` is `true` and
|
| 867 |
+
`is_assignable_v<second_type&, U2&&>` is `true`.
|
| 868 |
+
|
| 869 |
*Returns:* `*this`.
|
| 870 |
|
| 871 |
``` cpp
|
| 872 |
void swap(pair& p) noexcept(see below);
|
| 873 |
```
|
| 874 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 875 |
*Requires:* `first` shall be swappable
|
| 876 |
with ([[swappable.requirements]]) `p.first` and `second` shall be
|
| 877 |
swappable with `p.second`.
|
| 878 |
|
| 879 |
*Effects:* Swaps `first` with `p.first` and `second` with `p.second`.
|
| 880 |
|
| 881 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 882 |
+
|
| 883 |
+
``` cpp
|
| 884 |
+
is_nothrow_swappable_v<first_type> && is_nothrow_swappable_v<second_type>
|
| 885 |
+
```
|
| 886 |
+
|
| 887 |
### Specialized algorithms <a id="pairs.spec">[[pairs.spec]]</a>
|
| 888 |
|
| 889 |
``` cpp
|
| 890 |
template <class T1, class T2>
|
| 891 |
constexpr bool operator==(const pair<T1, T2>& x, const pair<T1, T2>& y);
|
|
|
|
| 904 |
``` cpp
|
| 905 |
template <class T1, class T2>
|
| 906 |
constexpr bool operator!=(const pair<T1, T2>& x, const pair<T1, T2>& y);
|
| 907 |
```
|
| 908 |
|
| 909 |
+
*Returns:* `!(x == y)`.
|
| 910 |
|
| 911 |
``` cpp
|
| 912 |
template <class T1, class T2>
|
| 913 |
constexpr bool operator>(const pair<T1, T2>& x, const pair<T1, T2>& y);
|
| 914 |
```
|
| 915 |
|
| 916 |
+
*Returns:* `y < x`.
|
| 917 |
|
| 918 |
``` cpp
|
| 919 |
template <class T1, class T2>
|
| 920 |
constexpr bool operator>=(const pair<T1, T2>& x, const pair<T1, T2>& y);
|
| 921 |
```
|
| 922 |
|
| 923 |
+
*Returns:* `!(x < y)`.
|
| 924 |
|
| 925 |
``` cpp
|
| 926 |
template <class T1, class T2>
|
| 927 |
constexpr bool operator<=(const pair<T1, T2>& x, const pair<T1, T2>& y);
|
| 928 |
```
|
| 929 |
|
| 930 |
+
*Returns:* `!(y < x)`.
|
| 931 |
|
| 932 |
``` cpp
|
| 933 |
template<class T1, class T2> void swap(pair<T1, T2>& x, pair<T1, T2>& y)
|
| 934 |
noexcept(noexcept(x.swap(y)));
|
| 935 |
```
|
| 936 |
|
| 937 |
+
*Effects:* As if by `x.swap(y)`.
|
| 938 |
+
|
| 939 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 940 |
+
unless `is_swappable_v<T1>` is `true` and `is_swappable_v<T2>` is
|
| 941 |
+
`true`.
|
| 942 |
|
| 943 |
``` cpp
|
| 944 |
template <class T1, class T2>
|
| 945 |
constexpr pair<V1, V2> make_pair(T1&& x, T2&& y);
|
| 946 |
```
|
| 947 |
|
| 948 |
+
*Returns:* `pair<V1, V2>(std::forward<T1>(x), std::forward<T2>(y))`,
|
|
|
|
| 949 |
where `V1` and `V2` are determined as follows: Let `Ui` be `decay_t<Ti>`
|
| 950 |
+
for each `Ti`. If `Ui` is a specialization of `reference_wrapper`, then
|
| 951 |
+
`Vi` is `Ui::type&`, otherwise `Vi` is `Ui`.
|
| 952 |
+
|
| 953 |
+
[*Example 1*:
|
| 954 |
|
| 955 |
In place of:
|
| 956 |
|
| 957 |
``` cpp
|
| 958 |
return pair<int, double>(5, 3.1415926); // explicit types
|
|
|
|
| 962 |
|
| 963 |
``` cpp
|
| 964 |
return make_pair(5, 3.1415926); // types are deduced
|
| 965 |
```
|
| 966 |
|
| 967 |
+
— *end example*]
|
| 968 |
+
|
| 969 |
### Tuple-like access to pair <a id="pair.astuple">[[pair.astuple]]</a>
|
| 970 |
|
| 971 |
``` cpp
|
| 972 |
template <class T1, class T2>
|
| 973 |
+
struct tuple_size<pair<T1, T2>> : integral_constant<size_t, 2> { };
|
|
|
|
| 974 |
```
|
| 975 |
|
| 976 |
``` cpp
|
| 977 |
tuple_element<0, pair<T1, T2>>::type
|
| 978 |
```
|
| 979 |
|
| 980 |
+
*Value:* The type `T1`.
|
| 981 |
|
| 982 |
``` cpp
|
| 983 |
tuple_element<1, pair<T1, T2>>::type
|
| 984 |
```
|
| 985 |
|
| 986 |
+
*Value:* The type T2.
|
| 987 |
|
| 988 |
``` cpp
|
| 989 |
template<size_t I, class T1, class T2>
|
| 990 |
+
constexpr tuple_element_t<I, pair<T1, T2>>& get(pair<T1, T2>& p) noexcept;
|
|
|
|
| 991 |
template<size_t I, class T1, class T2>
|
| 992 |
+
constexpr const tuple_element_t<I, pair<T1, T2>>& get(const pair<T1, T2>& p) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 993 |
template<size_t I, class T1, class T2>
|
| 994 |
+
constexpr tuple_element_t<I, pair<T1, T2>>&& get(pair<T1, T2>&& p) noexcept;
|
| 995 |
+
template<size_t I, class T1, class T2>
|
| 996 |
+
constexpr const tuple_element_t<I, pair<T1, T2>>&& get(const pair<T1, T2>&& p) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 997 |
```
|
| 998 |
|
| 999 |
+
*Returns:* If `I == 0` returns a reference to `p.first`; if `I == 1`
|
| 1000 |
+
returns a reference to `p.second`; otherwise the program is ill-formed.
|
|
|
|
|
|
|
| 1001 |
|
| 1002 |
``` cpp
|
| 1003 |
+
template <class T1, class T2>
|
| 1004 |
+
constexpr T1& get(pair<T1, T2>& p) noexcept;
|
| 1005 |
+
template <class T1, class T2>
|
| 1006 |
+
constexpr const T1& get(const pair<T1, T2>& p) noexcept;
|
| 1007 |
+
template <class T1, class T2>
|
| 1008 |
+
constexpr T1&& get(pair<T1, T2>&& p) noexcept;
|
| 1009 |
+
template <class T1, class T2>
|
| 1010 |
+
constexpr const T1&& get(const pair<T1, T2>&& p) noexcept;
|
| 1011 |
```
|
| 1012 |
|
| 1013 |
+
*Requires:* `T1` and `T2` are distinct types. Otherwise, the program is
|
| 1014 |
ill-formed.
|
| 1015 |
|
| 1016 |
+
*Returns:* A reference to `p.first`.
|
| 1017 |
|
| 1018 |
``` cpp
|
| 1019 |
+
template <class T2, class T1>
|
| 1020 |
+
constexpr T2& get(pair<T1, T2>& p) noexcept;
|
| 1021 |
+
template <class T2, class T1>
|
| 1022 |
+
constexpr const T2& get(const pair<T1, T2>& p) noexcept;
|
| 1023 |
+
template <class T2, class T1>
|
| 1024 |
+
constexpr T2&& get(pair<T1, T2>&& p) noexcept;
|
| 1025 |
+
template <class T2, class T1>
|
| 1026 |
+
constexpr const T2&& get(const pair<T1, T2>&& p) noexcept;
|
| 1027 |
```
|
| 1028 |
|
| 1029 |
+
*Requires:* `T1` and `T2` are distinct types. Otherwise, the program is
|
| 1030 |
ill-formed.
|
| 1031 |
|
| 1032 |
+
*Returns:* A reference to `p.second`.
|
| 1033 |
|
| 1034 |
### Piecewise construction <a id="pair.piecewise">[[pair.piecewise]]</a>
|
| 1035 |
|
| 1036 |
``` cpp
|
| 1037 |
+
struct piecewise_construct_t {
|
| 1038 |
+
explicit piecewise_construct_t() = default;
|
| 1039 |
+
};
|
| 1040 |
+
inline constexpr piecewise_construct_t piecewise_construct{};
|
| 1041 |
```
|
| 1042 |
|
| 1043 |
The `struct` `piecewise_construct_t` is an empty structure type used as
|
| 1044 |
a unique type to disambiguate constructor and function overloading.
|
| 1045 |
Specifically, `pair` has a constructor with `piecewise_construct_t` as
|
|
|
|
| 1057 |
the `tuple`. Consequently, tuples are heterogeneous, fixed-size
|
| 1058 |
collections of values. An instantiation of `tuple` with two arguments is
|
| 1059 |
similar to an instantiation of `pair` with the same two arguments. See
|
| 1060 |
[[pairs]].
|
| 1061 |
|
| 1062 |
+
### Header `<tuple>` synopsis <a id="tuple.syn">[[tuple.syn]]</a>
|
| 1063 |
+
|
| 1064 |
``` cpp
|
| 1065 |
namespace std {
|
| 1066 |
+
// [tuple.tuple], class template tuple
|
| 1067 |
+
template <class... Types>
|
| 1068 |
+
class tuple;
|
| 1069 |
|
| 1070 |
+
// [tuple.creation], tuple creation functions
|
| 1071 |
+
inline constexpr unspecified ignore;
|
| 1072 |
|
| 1073 |
+
template <class... TTypes>
|
| 1074 |
+
constexpr tuple<VTypes...> make_tuple(TTypes&&...);
|
|
|
|
|
|
|
| 1075 |
|
| 1076 |
+
template <class... TTypes>
|
| 1077 |
+
constexpr tuple<TTypes&&...> forward_as_tuple(TTypes&&...) noexcept;
|
| 1078 |
+
|
| 1079 |
+
template<class... TTypes>
|
| 1080 |
+
constexpr tuple<TTypes&...> tie(TTypes&...) noexcept;
|
| 1081 |
|
| 1082 |
template <class... Tuples>
|
| 1083 |
+
constexpr tuple<CTypes...> tuple_cat(Tuples&&...);
|
| 1084 |
|
| 1085 |
+
// [tuple.apply], calling a function with a tuple of arguments
|
| 1086 |
+
template <class F, class Tuple>
|
| 1087 |
+
constexpr decltype(auto) apply(F&& f, Tuple&& t);
|
| 1088 |
+
|
| 1089 |
+
template <class T, class Tuple>
|
| 1090 |
+
constexpr T make_from_tuple(Tuple&& t);
|
| 1091 |
+
|
| 1092 |
+
// [tuple.helper], tuple helper classes
|
| 1093 |
+
template <class T> class tuple_size; // not defined
|
| 1094 |
template <class T> class tuple_size<const T>;
|
| 1095 |
template <class T> class tuple_size<volatile T>;
|
| 1096 |
template <class T> class tuple_size<const volatile T>;
|
| 1097 |
|
| 1098 |
template <class... Types> class tuple_size<tuple<Types...>>;
|
| 1099 |
|
| 1100 |
+
template <size_t I, class T> class tuple_element; // not defined
|
| 1101 |
template <size_t I, class T> class tuple_element<I, const T>;
|
| 1102 |
template <size_t I, class T> class tuple_element<I, volatile T>;
|
| 1103 |
template <size_t I, class T> class tuple_element<I, const volatile T>;
|
| 1104 |
|
| 1105 |
+
template <size_t I, class... Types>
|
| 1106 |
+
class tuple_element<I, tuple<Types...>>;
|
| 1107 |
|
| 1108 |
template <size_t I, class T>
|
| 1109 |
using tuple_element_t = typename tuple_element<I, T>::type;
|
| 1110 |
|
| 1111 |
+
// [tuple.elem], element access
|
| 1112 |
template <size_t I, class... Types>
|
| 1113 |
+
constexpr tuple_element_t<I, tuple<Types...>>& get(tuple<Types...>&) noexcept;
|
|
|
|
| 1114 |
template <size_t I, class... Types>
|
| 1115 |
+
constexpr tuple_element_t<I, tuple<Types...>>&& get(tuple<Types...>&&) noexcept;
|
|
|
|
| 1116 |
template <size_t I, class... Types>
|
| 1117 |
+
constexpr const tuple_element_t<I, tuple<Types...>>& get(const tuple<Types...>&) noexcept;
|
| 1118 |
+
template <size_t I, class... Types>
|
| 1119 |
+
constexpr const tuple_element_t<I, tuple<Types...>>&& get(const tuple<Types...>&&) noexcept;
|
| 1120 |
template <class T, class... Types>
|
| 1121 |
constexpr T& get(tuple<Types...>& t) noexcept;
|
| 1122 |
template <class T, class... Types>
|
| 1123 |
constexpr T&& get(tuple<Types...>&& t) noexcept;
|
| 1124 |
template <class T, class... Types>
|
| 1125 |
constexpr const T& get(const tuple<Types...>& t) noexcept;
|
| 1126 |
+
template <class T, class... Types>
|
| 1127 |
+
constexpr const T&& get(const tuple<Types...>&& t) noexcept;
|
| 1128 |
|
| 1129 |
+
// [tuple.rel], relational operators
|
| 1130 |
template<class... TTypes, class... UTypes>
|
| 1131 |
constexpr bool operator==(const tuple<TTypes...>&, const tuple<UTypes...>&);
|
| 1132 |
template<class... TTypes, class... UTypes>
|
| 1133 |
constexpr bool operator<(const tuple<TTypes...>&, const tuple<UTypes...>&);
|
| 1134 |
template<class... TTypes, class... UTypes>
|
|
|
|
| 1142 |
|
| 1143 |
// [tuple.traits], allocator-related traits
|
| 1144 |
template <class... Types, class Alloc>
|
| 1145 |
struct uses_allocator<tuple<Types...>, Alloc>;
|
| 1146 |
|
| 1147 |
+
// [tuple.special], specialized algorithms
|
| 1148 |
template <class... Types>
|
| 1149 |
void swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(see below);
|
| 1150 |
+
|
| 1151 |
+
// [tuple.helper], tuple helper classes
|
| 1152 |
+
template <class T>
|
| 1153 |
+
inline constexpr size_t tuple_size_v = tuple_size<T>::value;
|
| 1154 |
}
|
| 1155 |
```
|
| 1156 |
|
| 1157 |
### Class template `tuple` <a id="tuple.tuple">[[tuple.tuple]]</a>
|
| 1158 |
|
| 1159 |
``` cpp
|
| 1160 |
namespace std {
|
| 1161 |
template <class... Types>
|
| 1162 |
class tuple {
|
| 1163 |
public:
|
|
|
|
| 1164 |
// [tuple.cnstr], tuple construction
|
| 1165 |
+
\EXPLICIT constexpr tuple();
|
| 1166 |
+
\EXPLICIT constexpr tuple(const Types&...); // only if sizeof...(Types) >= 1
|
| 1167 |
template <class... UTypes>
|
| 1168 |
+
\EXPLICIT constexpr tuple(UTypes&&...); // only if sizeof...(Types) >= 1
|
| 1169 |
|
| 1170 |
tuple(const tuple&) = default;
|
| 1171 |
tuple(tuple&&) = default;
|
| 1172 |
|
| 1173 |
template <class... UTypes>
|
| 1174 |
+
\EXPLICIT constexpr tuple(const tuple<UTypes...>&);
|
| 1175 |
template <class... UTypes>
|
| 1176 |
+
\EXPLICIT constexpr tuple(tuple<UTypes...>&&);
|
| 1177 |
|
| 1178 |
template <class U1, class U2>
|
| 1179 |
+
\EXPLICIT constexpr tuple(const pair<U1, U2>&); // only if sizeof...(Types) == 2
|
| 1180 |
template <class U1, class U2>
|
| 1181 |
+
\EXPLICIT constexpr tuple(pair<U1, U2>&&); // only if sizeof...(Types) == 2
|
| 1182 |
|
| 1183 |
// allocator-extended constructors
|
| 1184 |
template <class Alloc>
|
| 1185 |
tuple(allocator_arg_t, const Alloc& a);
|
| 1186 |
template <class Alloc>
|
| 1187 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, const Types&...);
|
| 1188 |
template <class Alloc, class... UTypes>
|
| 1189 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, UTypes&&...);
|
| 1190 |
template <class Alloc>
|
| 1191 |
tuple(allocator_arg_t, const Alloc& a, const tuple&);
|
| 1192 |
template <class Alloc>
|
| 1193 |
tuple(allocator_arg_t, const Alloc& a, tuple&&);
|
| 1194 |
template <class Alloc, class... UTypes>
|
| 1195 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&);
|
| 1196 |
template <class Alloc, class... UTypes>
|
| 1197 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&);
|
| 1198 |
template <class Alloc, class U1, class U2>
|
| 1199 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
|
| 1200 |
template <class Alloc, class U1, class U2>
|
| 1201 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
|
| 1202 |
|
| 1203 |
// [tuple.assign], tuple assignment
|
| 1204 |
tuple& operator=(const tuple&);
|
| 1205 |
tuple& operator=(tuple&&) noexcept(see below);
|
| 1206 |
|
|
|
|
| 1215 |
tuple& operator=(pair<U1, U2>&&); // only if sizeof...(Types) == 2
|
| 1216 |
|
| 1217 |
// [tuple.swap], tuple swap
|
| 1218 |
void swap(tuple&) noexcept(see below);
|
| 1219 |
};
|
| 1220 |
+
|
| 1221 |
+
template<class... UTypes>
|
| 1222 |
+
tuple(UTypes...) -> tuple<UTypes...>;
|
| 1223 |
+
template<class T1, class T2>
|
| 1224 |
+
tuple(pair<T1, T2>) -> tuple<T1, T2>;
|
| 1225 |
+
template<class Alloc, class... UTypes>
|
| 1226 |
+
tuple(allocator_arg_t, Alloc, UTypes...) -> tuple<UTypes...>;
|
| 1227 |
+
template<class Alloc, class T1, class T2>
|
| 1228 |
+
tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>;
|
| 1229 |
+
template<class Alloc, class... UTypes>
|
| 1230 |
+
tuple(allocator_arg_t, Alloc, tuple<UTypes...>) -> tuple<UTypes...>;
|
| 1231 |
}
|
| 1232 |
```
|
| 1233 |
|
| 1234 |
#### Construction <a id="tuple.cnstr">[[tuple.cnstr]]</a>
|
| 1235 |
|
| 1236 |
For each `tuple` constructor, an exception is thrown only if the
|
| 1237 |
construction of one of the types in `Types` throws an exception.
|
| 1238 |
|
| 1239 |
The defaulted move and copy constructor, respectively, of `tuple` shall
|
| 1240 |
+
be a constexpr function if and only if all required element-wise
|
| 1241 |
initializations for copy and move, respectively, would satisfy the
|
| 1242 |
+
requirements for a constexpr function. The defaulted move and copy
|
| 1243 |
+
constructor of `tuple<>` shall be constexpr functions.
|
| 1244 |
+
|
| 1245 |
+
The destructor of tuple shall be a trivial destructor if
|
| 1246 |
+
`(is_trivially_destructible_v<Types> && ...)` is `true`.
|
| 1247 |
|
| 1248 |
In the constructor descriptions that follow, let i be in the range
|
| 1249 |
+
\[`0`, `sizeof...(Types)`) in order, `Tᵢ` be the iᵗʰ type in `Types`,
|
| 1250 |
+
and `Uᵢ` be the iᵗʰ type in a template parameter pack named `UTypes`,
|
| 1251 |
+
where indexing is zero-based.
|
| 1252 |
|
| 1253 |
``` cpp
|
| 1254 |
+
\EXPLICIT constexpr tuple();
|
| 1255 |
```
|
| 1256 |
|
| 1257 |
+
*Effects:* Value-initializes each element.
|
| 1258 |
|
| 1259 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 1260 |
+
unless `is_default_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 1261 |
+
|
| 1262 |
+
[*Note 1*: This behavior can be implemented by a constructor template
|
| 1263 |
+
with default template arguments. — *end note*]
|
| 1264 |
+
|
| 1265 |
+
The constructor is explicit if and only if `Tᵢ` is not implicitly
|
| 1266 |
+
default-constructible for at least one i.
|
| 1267 |
+
|
| 1268 |
+
[*Note 2*: This behavior can be implemented with a trait that checks
|
| 1269 |
+
whether a `const ``Tᵢ``&` can be initialized with `{}`. — *end note*]
|
| 1270 |
|
| 1271 |
``` cpp
|
| 1272 |
+
\EXPLICIT constexpr tuple(const Types&...);
|
| 1273 |
```
|
| 1274 |
|
|
|
|
|
|
|
| 1275 |
*Effects:* Initializes each element with the value of the corresponding
|
| 1276 |
parameter.
|
| 1277 |
|
| 1278 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 1279 |
+
unless `sizeof...(Types) >= 1` and `is_copy_constructible_v<``Tᵢ``>` is
|
| 1280 |
+
`true` for all i. The constructor is explicit if and only if
|
| 1281 |
+
`is_convertible_v<const ``Tᵢ``&, ``Tᵢ``>` is `false` for at least one i.
|
| 1282 |
+
|
| 1283 |
``` cpp
|
| 1284 |
+
template <class... UTypes> \EXPLICIT constexpr tuple(UTypes&&... u);
|
|
|
|
| 1285 |
```
|
| 1286 |
|
|
|
|
|
|
|
|
|
|
| 1287 |
*Effects:* Initializes the elements in the tuple with the corresponding
|
| 1288 |
value in `std::forward<UTypes>(u)`.
|
| 1289 |
|
| 1290 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 1291 |
+
unless `sizeof...(Types)` `==` `sizeof...(UTypes)` and
|
| 1292 |
+
`sizeof...(Types) >= 1` and `is_constructible_v<``Tᵢ``, ``Uᵢ``&&>` is
|
| 1293 |
+
`true` for all i. The constructor is explicit if and only if
|
| 1294 |
+
`is_convertible_v<``Uᵢ``&&, ``Tᵢ``>` is `false` for at least one i.
|
| 1295 |
|
| 1296 |
``` cpp
|
| 1297 |
tuple(const tuple& u) = default;
|
| 1298 |
```
|
| 1299 |
|
| 1300 |
+
*Requires:* `is_copy_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 1301 |
|
| 1302 |
*Effects:* Initializes each element of `*this` with the corresponding
|
| 1303 |
element of `u`.
|
| 1304 |
|
| 1305 |
``` cpp
|
| 1306 |
tuple(tuple&& u) = default;
|
| 1307 |
```
|
| 1308 |
|
| 1309 |
+
*Requires:* `is_move_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 1310 |
|
| 1311 |
*Effects:* For all i, initializes the iᵗʰ element of `*this` with
|
| 1312 |
+
`std::forward<``Tᵢ``>(get<`i`>(u))`.
|
| 1313 |
|
| 1314 |
``` cpp
|
| 1315 |
+
template <class... UTypes> \EXPLICIT constexpr tuple(const tuple<UTypes...>& u);
|
| 1316 |
```
|
| 1317 |
|
| 1318 |
+
*Effects:* Initializes each element of `*this` with the corresponding
|
|
|
|
|
|
|
|
|
|
| 1319 |
element of `u`.
|
| 1320 |
|
| 1321 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 1322 |
+
unless
|
| 1323 |
+
|
| 1324 |
+
- `sizeof...(Types)` `==` `sizeof...(UTypes)` and
|
| 1325 |
+
- `is_constructible_v<``Tᵢ``, const ``Uᵢ``&>` is `true` for all i, and
|
| 1326 |
+
- `sizeof...(Types) != 1`, or (when `Types...` expands to `T` and
|
| 1327 |
+
`UTypes...` expands to `U`)
|
| 1328 |
+
`!is_convertible_v<const tuple<U>&, T> && !is_constructible_v<T, const tuple<U>&>&& !is_same_v<T, U>`
|
| 1329 |
+
is `true`.
|
| 1330 |
+
|
| 1331 |
+
The constructor is explicit if and only if
|
| 1332 |
+
`is_convertible_v<const ``Uᵢ``&, ``Tᵢ``>` is `false` for at least one i.
|
| 1333 |
|
| 1334 |
``` cpp
|
| 1335 |
+
template <class... UTypes> \EXPLICIT constexpr tuple(tuple<UTypes...>&& u);
|
| 1336 |
```
|
| 1337 |
|
|
|
|
|
|
|
|
|
|
| 1338 |
*Effects:* For all i, initializes the iᵗʰ element of `*this` with
|
| 1339 |
+
`std::forward<``Uᵢ``>(get<`i`>(u))`.
|
| 1340 |
|
| 1341 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 1342 |
+
unless
|
| 1343 |
+
|
| 1344 |
+
- `sizeof...(Types)` `==` `sizeof...(UTypes)`, and
|
| 1345 |
+
- `is_constructible_v<``Tᵢ``, ``Uᵢ``&&>` is `true` for all i, and
|
| 1346 |
+
- `sizeof...(Types) != 1`, or (when `Types...` expands to `T` and
|
| 1347 |
+
`UTypes...` expands to `U`)
|
| 1348 |
+
`!is_convertible_v<tuple<U>, T> && !is_constructible_v<T, tuple<U>> &&!is_same_v<T, U>`
|
| 1349 |
+
is `true`.
|
| 1350 |
+
|
| 1351 |
+
The constructor is explicit if and only if
|
| 1352 |
+
`is_convertible_v<``Uᵢ``&&, ``Tᵢ``>` is `false` for at least one i.
|
| 1353 |
|
| 1354 |
``` cpp
|
| 1355 |
+
template <class U1, class U2> \EXPLICIT constexpr tuple(const pair<U1, U2>& u);
|
| 1356 |
```
|
| 1357 |
|
| 1358 |
+
*Effects:* Initializes the first element with `u.first` and the second
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1359 |
element with `u.second`.
|
| 1360 |
|
| 1361 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 1362 |
+
unless `sizeof...(Types) == 2`, `is_constructible_v<``T₀``, const U1&>`
|
| 1363 |
+
is `true` and `is_constructible_v<``T₁``, const U2&>` is `true`.
|
| 1364 |
+
|
| 1365 |
+
The constructor is explicit if and only if
|
| 1366 |
+
`is_convertible_v<const U1&, ``T₀``>` is `false` or
|
| 1367 |
+
`is_convertible_v<const U2&, ``T₁``>` is `false`.
|
| 1368 |
|
| 1369 |
``` cpp
|
| 1370 |
+
template <class U1, class U2> \EXPLICIT constexpr tuple(pair<U1, U2>&& u);
|
| 1371 |
```
|
| 1372 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1373 |
*Effects:* Initializes the first element with
|
| 1374 |
`std::forward<U1>(u.first)` and the second element with
|
| 1375 |
`std::forward<U2>(u.second)`.
|
| 1376 |
|
| 1377 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 1378 |
+
unless `sizeof...(Types) == 2`, `is_constructible_v<``T₀``, U1&&>` is
|
| 1379 |
+
`true` and `is_constructible_v<``T₁``, U2&&>` is `true`.
|
| 1380 |
+
|
| 1381 |
+
The constructor is explicit if and only if
|
| 1382 |
+
`is_convertible_v<U1&&, ``T₀``>` is `false` or
|
| 1383 |
+
`is_convertible_v<U2&&, ``T₁``>` is `false`.
|
| 1384 |
|
| 1385 |
``` cpp
|
| 1386 |
template <class Alloc>
|
| 1387 |
tuple(allocator_arg_t, const Alloc& a);
|
| 1388 |
template <class Alloc>
|
| 1389 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, const Types&...);
|
| 1390 |
template <class Alloc, class... UTypes>
|
| 1391 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, UTypes&&...);
|
| 1392 |
template <class Alloc>
|
| 1393 |
tuple(allocator_arg_t, const Alloc& a, const tuple&);
|
| 1394 |
template <class Alloc>
|
| 1395 |
tuple(allocator_arg_t, const Alloc& a, tuple&&);
|
| 1396 |
template <class Alloc, class... UTypes>
|
| 1397 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&);
|
| 1398 |
template <class Alloc, class... UTypes>
|
| 1399 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&);
|
| 1400 |
template <class Alloc, class U1, class U2>
|
| 1401 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
|
| 1402 |
template <class Alloc, class U1, class U2>
|
| 1403 |
+
\EXPLICIT tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
|
| 1404 |
```
|
| 1405 |
|
| 1406 |
*Requires:* `Alloc` shall meet the requirements for an
|
| 1407 |
`Allocator` ([[allocator.requirements]]).
|
| 1408 |
|
|
|
|
| 1413 |
#### Assignment <a id="tuple.assign">[[tuple.assign]]</a>
|
| 1414 |
|
| 1415 |
For each `tuple` assignment operator, an exception is thrown only if the
|
| 1416 |
assignment of one of the types in `Types` throws an exception. In the
|
| 1417 |
function descriptions that follow, let i be in the range \[`0`,
|
| 1418 |
+
`sizeof...(Types)`) in order, `Tᵢ` be the iᵗʰ type in `Types`, and `Uᵢ`
|
| 1419 |
+
be the iᵗʰ type in a template parameter pack named `UTypes`, where
|
| 1420 |
+
indexing is zero-based.
|
| 1421 |
|
| 1422 |
``` cpp
|
| 1423 |
tuple& operator=(const tuple& u);
|
| 1424 |
```
|
| 1425 |
|
|
|
|
|
|
|
| 1426 |
*Effects:* Assigns each element of `u` to the corresponding element of
|
| 1427 |
`*this`.
|
| 1428 |
|
| 1429 |
+
*Remarks:* This operator shall be defined as deleted unless
|
| 1430 |
+
`is_copy_assignable_v<``Tᵢ``>` is `true` for all i.
|
| 1431 |
+
|
| 1432 |
+
*Returns:* `*this`.
|
| 1433 |
|
| 1434 |
``` cpp
|
| 1435 |
tuple& operator=(tuple&& u) noexcept(see below);
|
| 1436 |
```
|
| 1437 |
|
| 1438 |
+
*Effects:* For all i, assigns `std::forward<``Tᵢ``>(get<`i`>(u))` to
|
| 1439 |
+
`get<`i`>(*this)`.
|
| 1440 |
+
|
| 1441 |
+
*Remarks:* This operator shall be defined as deleted unless
|
| 1442 |
+
`is_move_assignable_v<``Tᵢ``>` is `true` for all i.
|
| 1443 |
+
|
| 1444 |
+
*Remarks:* The expression inside `noexcept` is equivalent to the logical
|
| 1445 |
<span class="smallcaps">and</span> of the following expressions:
|
| 1446 |
|
| 1447 |
``` cpp
|
| 1448 |
+
is_nothrow_move_assignable_v<Tᵢ>
|
| 1449 |
```
|
| 1450 |
|
| 1451 |
where Tᵢ is the iᵗʰ type in `Types`.
|
| 1452 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1453 |
*Returns:* `*this`.
|
| 1454 |
|
| 1455 |
``` cpp
|
| 1456 |
+
template <class... UTypes> tuple& operator=(const tuple<UTypes...>& u);
|
|
|
|
| 1457 |
```
|
| 1458 |
|
|
|
|
|
|
|
|
|
|
| 1459 |
*Effects:* Assigns each element of `u` to the corresponding element of
|
| 1460 |
`*this`.
|
| 1461 |
|
| 1462 |
+
*Remarks:* This operator shall not participate in overload resolution
|
| 1463 |
+
unless `sizeof...(Types) == sizeof...(UTypes)` and
|
| 1464 |
+
`is_assignable_v<``Tᵢ``&, const ``Uᵢ``&>` is `true` for all i.
|
| 1465 |
+
|
| 1466 |
+
*Returns:* `*this`.
|
| 1467 |
|
| 1468 |
``` cpp
|
| 1469 |
+
template <class... UTypes> tuple& operator=(tuple<UTypes...>&& u);
|
|
|
|
| 1470 |
```
|
| 1471 |
|
| 1472 |
+
*Effects:* For all i, assigns `std::forward<``Uᵢ``>(get<`i`>(u))` to
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1473 |
`get<`i`>(*this)`.
|
| 1474 |
|
| 1475 |
+
*Remarks:* This operator shall not participate in overload resolution
|
| 1476 |
+
unless `is_assignable_v<``Tᵢ``&, ``Uᵢ``&&> == true` for all i and
|
| 1477 |
+
`sizeof...(Types) == sizeof...(UTypes)`.
|
| 1478 |
+
|
| 1479 |
*Returns:* `*this`.
|
| 1480 |
|
| 1481 |
``` cpp
|
| 1482 |
template <class U1, class U2> tuple& operator=(const pair<U1, U2>& u);
|
| 1483 |
```
|
| 1484 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1485 |
*Effects:* Assigns `u.first` to the first element of `*this` and
|
| 1486 |
`u.second` to the second element of `*this`.
|
| 1487 |
|
| 1488 |
+
*Remarks:* This operator shall not participate in overload resolution
|
| 1489 |
+
unless `sizeof...(Types) == 2` and `is_assignable_v<``T₀``&, const U1&>`
|
| 1490 |
+
is `true` for the first type `T₀` in `Types` and
|
| 1491 |
+
`is_assignable_v<``T₁``&, const U2&>` is `true` for the second type `T₁`
|
| 1492 |
+
in `Types`.
|
| 1493 |
+
|
| 1494 |
+
*Returns:* `*this`.
|
| 1495 |
|
| 1496 |
``` cpp
|
| 1497 |
template <class U1, class U2> tuple& operator=(pair<U1, U2>&& u);
|
| 1498 |
```
|
| 1499 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1500 |
*Effects:* Assigns `std::forward<U1>(u.first)` to the first element of
|
| 1501 |
`*this` and
|
| 1502 |
`std::forward<U2>(u.second)` to the second element of `*this`.
|
| 1503 |
|
| 1504 |
+
*Remarks:* This operator shall not participate in overload resolution
|
| 1505 |
+
unless `sizeof...(Types) == 2` and `is_assignable_v<``T₀``&, U1&&>` is
|
| 1506 |
+
`true` for the first type `T₀` in `Types` and
|
| 1507 |
+
`is_assignable_v<``T₁``&, U2&&>` is `true` for the second type `T₁` in
|
| 1508 |
+
`Types`.
|
| 1509 |
+
|
| 1510 |
*Returns:* `*this`.
|
| 1511 |
|
| 1512 |
#### `swap` <a id="tuple.swap">[[tuple.swap]]</a>
|
| 1513 |
|
| 1514 |
``` cpp
|
| 1515 |
void swap(tuple& rhs) noexcept(see below);
|
| 1516 |
```
|
| 1517 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1518 |
*Requires:* Each element in `*this` shall be swappable
|
| 1519 |
with ([[swappable.requirements]]) the corresponding element in `rhs`.
|
| 1520 |
|
| 1521 |
*Effects:* Calls `swap` for each element in `*this` and its
|
| 1522 |
corresponding element in `rhs`.
|
| 1523 |
|
| 1524 |
+
*Remarks:* The expression inside `noexcept` is equivalent to the logical
|
| 1525 |
+
<span class="smallcaps">and</span> of the following expressions:
|
| 1526 |
+
|
| 1527 |
+
``` cpp
|
| 1528 |
+
is_nothrow_swappable_v<Tᵢ>
|
| 1529 |
+
```
|
| 1530 |
+
|
| 1531 |
+
where Tᵢ is the iᵗʰ type in `Types`.
|
| 1532 |
+
|
| 1533 |
*Throws:* Nothing unless one of the element-wise `swap` calls throws an
|
| 1534 |
exception.
|
| 1535 |
|
| 1536 |
#### Tuple creation functions <a id="tuple.creation">[[tuple.creation]]</a>
|
| 1537 |
|
| 1538 |
+
In the function descriptions that follow, the members of a parameter
|
| 1539 |
+
pack `XTypes` are denoted by `X`ᵢ for i in \[`0`,
|
| 1540 |
+
`sizeof...(`*X*`Types)`) in order, where indexing is zero-based.
|
|
|
|
|
|
|
| 1541 |
|
| 1542 |
``` cpp
|
| 1543 |
+
template<class... TTypes>
|
| 1544 |
+
constexpr tuple<VTypes...> make_tuple(TTypes&&... t);
|
| 1545 |
```
|
| 1546 |
|
| 1547 |
+
The pack `VTypes` is defined as follows. Let `U`ᵢ be `decay_t<T`ᵢ`>` for
|
| 1548 |
+
each `T`ᵢ in `TTypes`. If `U`ᵢ is a specialization of
|
| 1549 |
+
`reference_wrapper`, then `V`ᵢ in `VTypes` is `U`ᵢ`::type&`, otherwise
|
| 1550 |
+
`V`ᵢ is `U`ᵢ.
|
| 1551 |
|
| 1552 |
+
*Returns:* `tuple<VTypes...>(std::forward<TTypes>(t)...)`.
|
| 1553 |
+
|
| 1554 |
+
[*Example 1*:
|
| 1555 |
|
| 1556 |
``` cpp
|
| 1557 |
int i; float j;
|
| 1558 |
make_tuple(1, ref(i), cref(j))
|
| 1559 |
```
|
| 1560 |
|
| 1561 |
+
creates a tuple of type `tuple<int, int&, const float&>`.
|
| 1562 |
|
| 1563 |
+
— *end example*]
|
|
|
|
|
|
|
| 1564 |
|
| 1565 |
``` cpp
|
| 1566 |
+
template<class... TTypes>
|
| 1567 |
+
constexpr tuple<TTypes&&...> forward_as_tuple(TTypes&&... t) noexcept;
|
| 1568 |
```
|
| 1569 |
|
| 1570 |
*Effects:* Constructs a tuple of references to the arguments in `t`
|
| 1571 |
suitable for forwarding as arguments to a function. Because the result
|
| 1572 |
may contain references to temporary variables, a program shall ensure
|
| 1573 |
that the return value of this function does not outlive any of its
|
| 1574 |
+
arguments (e.g., the program should typically not store the result in a
|
| 1575 |
named variable).
|
| 1576 |
|
| 1577 |
+
*Returns:* `tuple<TTypes&&...>(std::forward<TTypes>(t)...)`.
|
| 1578 |
|
| 1579 |
``` cpp
|
| 1580 |
+
template<class... TTypes>
|
| 1581 |
+
constexpr tuple<TTypes&...> tie(TTypes&... t) noexcept;
|
| 1582 |
```
|
| 1583 |
|
| 1584 |
+
*Returns:* `tuple<TTypes&...>(t...)`. When an argument in `t` is
|
| 1585 |
`ignore`, assigning any value to the corresponding tuple element has no
|
| 1586 |
effect.
|
| 1587 |
|
| 1588 |
+
[*Example 2*:
|
| 1589 |
+
|
| 1590 |
`tie` functions allow one to create tuples that unpack tuples into
|
| 1591 |
variables. `ignore` can be used for elements that are not needed:
|
| 1592 |
|
| 1593 |
``` cpp
|
| 1594 |
int i; std::string s;
|
| 1595 |
tie(i, ignore, s) = make_tuple(42, 3.14, "C++");
|
| 1596 |
// i == 42, s == "C++"
|
| 1597 |
```
|
| 1598 |
|
| 1599 |
+
— *end example*]
|
| 1600 |
+
|
| 1601 |
``` cpp
|
| 1602 |
template <class... Tuples>
|
| 1603 |
constexpr tuple<CTypes...> tuple_cat(Tuples&&... tpls);
|
| 1604 |
```
|
| 1605 |
|
| 1606 |
+
In the following paragraphs, let `Tᵢ` be the iᵗʰ type in `Tuples`, `Uᵢ`
|
| 1607 |
+
be `remove_reference_t<T`ᵢ`>`, and `tpᵢ` be the iᵗʰ parameter in the
|
| 1608 |
+
function parameter pack `tpls`, where all indexing is zero-based.
|
| 1609 |
|
| 1610 |
+
*Requires:* For all i, `Uᵢ` shall be the type cvᵢ `tuple<``Argsᵢ``...>`,
|
| 1611 |
+
where cvᵢ is the (possibly empty) iᵗʰ *cv-qualifier-seq* and `Argsᵢ` is
|
| 1612 |
+
the parameter pack representing the element types in `Uᵢ`. Let `A_ik` be
|
| 1613 |
+
the kᵗʰ type in `Argsᵢ`. For all `A_ik` the following requirements shall
|
| 1614 |
+
be satisfied:
|
|
|
|
|
|
|
| 1615 |
|
| 1616 |
+
- If `Tᵢ` is deduced as an lvalue reference type, then
|
| 1617 |
+
`is_constructible_v<``A_ik``, `cvᵢ `A_ik``&> == true`, otherwise
|
| 1618 |
+
- `is_constructible_v<``A_ik``, `cvᵢ `A_ik``&&> == true`.
|
| 1619 |
+
|
| 1620 |
+
*Remarks:* The types in `CTypes` shall be equal to the ordered sequence
|
| 1621 |
+
of the extended types `Args₀``..., ``Args₁``..., `…`, ``Args_n-1``...`,
|
| 1622 |
+
where n is equal to `sizeof...(Tuples)`. Let `eᵢ``...` be the iᵗʰ
|
| 1623 |
+
ordered sequence of tuple elements of the resulting `tuple` object
|
| 1624 |
+
corresponding to the type sequence `Argsᵢ`.
|
| 1625 |
|
| 1626 |
*Returns:* A `tuple` object constructed by initializing the kᵢᵗʰ type
|
| 1627 |
+
element `e_ik` in `eᵢ``...` with
|
|
|
|
|
|
|
| 1628 |
|
| 1629 |
+
``` cpp
|
| 1630 |
+
get<kᵢ>(std::forward<$T_i$>($tp_i$))
|
| 1631 |
+
```
|
| 1632 |
+
|
| 1633 |
+
for each valid kᵢ and each group `eᵢ` in order.
|
| 1634 |
+
|
| 1635 |
+
[*Note 1*: An implementation may support additional types in the
|
| 1636 |
+
parameter pack `Tuples` that support the `tuple`-like protocol, such as
|
| 1637 |
+
`pair` and `array`. — *end note*]
|
| 1638 |
+
|
| 1639 |
+
#### Calling a function with a `tuple` of arguments <a id="tuple.apply">[[tuple.apply]]</a>
|
| 1640 |
+
|
| 1641 |
+
``` cpp
|
| 1642 |
+
template <class F, class Tuple>
|
| 1643 |
+
constexpr decltype(auto) apply(F&& f, Tuple&& t);
|
| 1644 |
+
```
|
| 1645 |
+
|
| 1646 |
+
*Effects:* Given the exposition-only function:
|
| 1647 |
+
|
| 1648 |
+
``` cpp
|
| 1649 |
+
template <class F, class Tuple, size_t... I>
|
| 1650 |
+
constexpr decltype(auto)
|
| 1651 |
+
apply_impl(F&& f, Tuple&& t, index_sequence<I...>) { // exposition only
|
| 1652 |
+
return INVOKE(std::forward<F>(f), std::get<I>(std::forward<Tuple>(t))...);
|
| 1653 |
+
}
|
| 1654 |
+
```
|
| 1655 |
+
|
| 1656 |
+
Equivalent to:
|
| 1657 |
+
|
| 1658 |
+
``` cpp
|
| 1659 |
+
return apply_impl(std::forward<F>(f), std::forward<Tuple>(t),
|
| 1660 |
+
make_index_sequence<tuple_size_v<decay_t<Tuple>>>{});
|
| 1661 |
+
```
|
| 1662 |
+
|
| 1663 |
+
``` cpp
|
| 1664 |
+
template <class T, class Tuple>
|
| 1665 |
+
constexpr T make_from_tuple(Tuple&& t);
|
| 1666 |
+
```
|
| 1667 |
+
|
| 1668 |
+
*Effects:* Given the exposition-only function:
|
| 1669 |
+
|
| 1670 |
+
``` cpp
|
| 1671 |
+
template <class T, class Tuple, size_t... I>
|
| 1672 |
+
constexpr T make_from_tuple_impl(Tuple&& t, index_sequence<I...>) { // exposition only
|
| 1673 |
+
return T(get<I>(std::forward<Tuple>(t))...);
|
| 1674 |
+
}
|
| 1675 |
+
```
|
| 1676 |
+
|
| 1677 |
+
Equivalent to:
|
| 1678 |
+
|
| 1679 |
+
``` cpp
|
| 1680 |
+
return make_from_tuple_impl<T>(forward<Tuple>(t),
|
| 1681 |
+
make_index_sequence<tuple_size_v<decay_t<Tuple>>>{});
|
| 1682 |
+
```
|
| 1683 |
+
|
| 1684 |
+
[*Note 1*: The type of `T` must be supplied as an explicit template
|
| 1685 |
+
parameter, as it cannot be deduced from the argument
|
| 1686 |
+
list. — *end note*]
|
| 1687 |
|
| 1688 |
#### Tuple helper classes <a id="tuple.helper">[[tuple.helper]]</a>
|
| 1689 |
|
| 1690 |
``` cpp
|
| 1691 |
template <class T> struct tuple_size;
|
| 1692 |
```
|
| 1693 |
|
| 1694 |
+
*Remarks:* All specializations of `tuple_size` shall meet the
|
| 1695 |
+
`UnaryTypeTrait` requirements ([[meta.rqmts]]) with a base
|
| 1696 |
+
characteristic of `integral_constant<size_t, N>` for some `N`.
|
| 1697 |
|
| 1698 |
``` cpp
|
| 1699 |
template <class... Types>
|
| 1700 |
+
class tuple_size<tuple<Types...>> : public integral_constant<size_t, sizeof...(Types)> { };
|
|
|
|
| 1701 |
```
|
| 1702 |
|
| 1703 |
``` cpp
|
| 1704 |
template <size_t I, class... Types>
|
| 1705 |
class tuple_element<I, tuple<Types...>> {
|
| 1706 |
public:
|
| 1707 |
+
using type = TI;
|
| 1708 |
};
|
| 1709 |
```
|
| 1710 |
|
| 1711 |
*Requires:* `I < sizeof...(Types)`. The program is ill-formed if `I` is
|
| 1712 |
out of bounds.
|
|
|
|
| 1718 |
template <class T> class tuple_size<const T>;
|
| 1719 |
template <class T> class tuple_size<volatile T>;
|
| 1720 |
template <class T> class tuple_size<const volatile T>;
|
| 1721 |
```
|
| 1722 |
|
| 1723 |
+
Let *`TS`* denote `tuple_size<T>` of the cv-unqualified type `T`. If the
|
| 1724 |
+
expression *`TS`*`::value` is well-formed when treated as an unevaluated
|
| 1725 |
+
operand, then each of the three templates shall meet the
|
| 1726 |
+
`UnaryTypeTrait` requirements ([[meta.rqmts]]) with a base
|
| 1727 |
+
characteristic of
|
| 1728 |
|
| 1729 |
``` cpp
|
| 1730 |
integral_constant<size_t, TS::value>
|
| 1731 |
```
|
| 1732 |
|
| 1733 |
+
Otherwise, they shall have no member `value`.
|
| 1734 |
+
|
| 1735 |
+
Access checking is performed as if in a context unrelated to *`TS`* and
|
| 1736 |
+
`T`. Only the validity of the immediate context of the expression is
|
| 1737 |
+
considered.
|
| 1738 |
+
|
| 1739 |
+
[*Note 1*: The compilation of the expression can result in side effects
|
| 1740 |
+
such as the instantiation of class template specializations and function
|
| 1741 |
+
template specializations, the generation of implicitly-defined
|
| 1742 |
+
functions, and so on. Such side effects are not in the “immediate
|
| 1743 |
+
context” and can result in the program being ill-formed. — *end note*]
|
| 1744 |
+
|
| 1745 |
+
In addition to being available via inclusion of the `<tuple>` header,
|
| 1746 |
+
the three templates are available when either of the headers `<array>`
|
| 1747 |
+
or `<utility>` are included.
|
| 1748 |
+
|
| 1749 |
``` cpp
|
| 1750 |
template <size_t I, class T> class tuple_element<I, const T>;
|
| 1751 |
template <size_t I, class T> class tuple_element<I, volatile T>;
|
| 1752 |
template <size_t I, class T> class tuple_element<I, const volatile T>;
|
| 1753 |
```
|
| 1754 |
|
| 1755 |
+
Let *`TE`* denote `tuple_element_t<I, T>` of the cv-unqualified type
|
| 1756 |
+
`T`. Then each of the three templates shall meet the
|
| 1757 |
+
`TransformationTrait` requirements ([[meta.rqmts]]) with a member
|
| 1758 |
+
typedef `type` that names the following type:
|
| 1759 |
|
| 1760 |
+
- for the first specialization, `add_const_t<`*`TE`*`>`,
|
| 1761 |
+
- for the second specialization, `add_volatile_t<`*`TE`*`>`, and
|
| 1762 |
+
- for the third specialization, `add_cv_t<`*`TE`*`>`.
|
| 1763 |
+
|
| 1764 |
+
In addition to being available via inclusion of the `<tuple>` header,
|
| 1765 |
+
the three templates are available when either of the headers `<array>`
|
| 1766 |
+
or `<utility>` are included.
|
| 1767 |
|
| 1768 |
#### Element access <a id="tuple.elem">[[tuple.elem]]</a>
|
| 1769 |
|
| 1770 |
``` cpp
|
| 1771 |
template <size_t I, class... Types>
|
| 1772 |
+
constexpr tuple_element_t<I, tuple<Types...>>&
|
| 1773 |
+
get(tuple<Types...>& t) noexcept;
|
| 1774 |
+
template <size_t I, class... Types>
|
| 1775 |
+
constexpr tuple_element_t<I, tuple<Types...>>&&
|
| 1776 |
+
get(tuple<Types...>&& t) noexcept; // Note A
|
| 1777 |
+
template <size_t I, class... Types>
|
| 1778 |
+
constexpr const tuple_element_t<I, tuple<Types...>>&
|
| 1779 |
+
get(const tuple<Types...>& t) noexcept; // Note B
|
| 1780 |
+
template <size_t I, class... Types>
|
| 1781 |
+
constexpr const tuple_element_t<I, tuple<Types...>>&& get(const tuple<Types...>&& t) noexcept;
|
| 1782 |
```
|
| 1783 |
|
| 1784 |
*Requires:* `I < sizeof...(Types)`. The program is ill-formed if `I` is
|
| 1785 |
out of bounds.
|
| 1786 |
|
| 1787 |
*Returns:* A reference to the `I`th element of `t`, where indexing is
|
| 1788 |
zero-based.
|
| 1789 |
|
| 1790 |
+
[*Note 1*: \[Note A\]If a `T` in `Types` is some reference type `X&`,
|
| 1791 |
+
the return type is `X&`, not `X&&`. However, if the element type is a
|
| 1792 |
+
non-reference type `T`, the return type is `T&&`. — *end note*]
|
| 1793 |
+
|
| 1794 |
+
[*Note 2*: \[Note B\]Constness is shallow. If a `T` in `Types` is some
|
| 1795 |
+
reference type `X&`, the return type is `X&`, not `const X&`. However,
|
| 1796 |
+
if the element type is a non-reference type `T`, the return type is
|
| 1797 |
+
`const T&`. This is consistent with how constness is defined to work for
|
| 1798 |
+
member variables of reference type. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1799 |
|
| 1800 |
``` cpp
|
| 1801 |
template <class T, class... Types>
|
| 1802 |
constexpr T& get(tuple<Types...>& t) noexcept;
|
| 1803 |
template <class T, class... Types>
|
| 1804 |
constexpr T&& get(tuple<Types...>&& t) noexcept;
|
| 1805 |
template <class T, class... Types>
|
| 1806 |
constexpr const T& get(const tuple<Types...>& t) noexcept;
|
| 1807 |
+
template <class T, class... Types>
|
| 1808 |
+
constexpr const T&& get(const tuple<Types...>&& t) noexcept;
|
| 1809 |
```
|
| 1810 |
|
| 1811 |
*Requires:* The type `T` occurs exactly once in `Types...`. Otherwise,
|
| 1812 |
the program is ill-formed.
|
| 1813 |
|
| 1814 |
*Returns:* A reference to the element of `t` corresponding to the type
|
| 1815 |
`T` in `Types...`.
|
| 1816 |
|
| 1817 |
+
[*Example 1*:
|
| 1818 |
+
|
| 1819 |
``` cpp
|
| 1820 |
const tuple<int, const int, double, double> t(1, 2, 3.4, 5.6);
|
| 1821 |
const int& i1 = get<int>(t); // OK. Not ambiguous. i1 == 1
|
| 1822 |
const int& i2 = get<const int>(t); // OK. Not ambiguous. i2 == 2
|
| 1823 |
const double& d = get<double>(t); // ERROR. ill-formed
|
| 1824 |
```
|
| 1825 |
|
| 1826 |
+
— *end example*]
|
| 1827 |
+
|
| 1828 |
+
[*Note 1*: The reason `get` is a non-member function is that if this
|
| 1829 |
+
functionality had been provided as a member function, code where the
|
| 1830 |
+
type depended on a template parameter would have required using the
|
| 1831 |
+
`template` keyword. — *end note*]
|
| 1832 |
|
| 1833 |
#### Relational operators <a id="tuple.rel">[[tuple.rel]]</a>
|
| 1834 |
|
| 1835 |
``` cpp
|
| 1836 |
template<class... TTypes, class... UTypes>
|
|
|
|
| 1853 |
template<class... TTypes, class... UTypes>
|
| 1854 |
constexpr bool operator<(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
|
| 1855 |
```
|
| 1856 |
|
| 1857 |
*Requires:* For all `i`, where `0 <= i` and `i < sizeof...(TTypes)`,
|
| 1858 |
+
both `get<i>(t) < get<i>(u)` and `get<i>(u) < get<i>(t)` are valid
|
| 1859 |
expressions returning types that are convertible to `bool`.
|
| 1860 |
`sizeof...(TTypes)` `==` `sizeof...(UTypes)`.
|
| 1861 |
|
| 1862 |
*Returns:* The result of a lexicographical comparison between `t` and
|
| 1863 |
`u`. The result is defined as:
|
|
|
|
| 1883 |
``` cpp
|
| 1884 |
template<class... TTypes, class... UTypes>
|
| 1885 |
constexpr bool operator<=(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
|
| 1886 |
```
|
| 1887 |
|
| 1888 |
+
*Returns:* `!(u < t)`.
|
| 1889 |
|
| 1890 |
``` cpp
|
| 1891 |
template<class... TTypes, class... UTypes>
|
| 1892 |
constexpr bool operator>=(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
|
| 1893 |
```
|
| 1894 |
|
| 1895 |
+
*Returns:* `!(t < u)`.
|
| 1896 |
|
| 1897 |
+
[*Note 1*: The above definitions for comparison functions do not
|
| 1898 |
+
require `tₜₐᵢₗ` (or `uₜₐᵢₗ`) to be constructed. It may not even be
|
| 1899 |
+
possible, as `t` and `u` are not required to be copy constructible.
|
| 1900 |
+
Also, all comparison functions are short circuited; they do not perform
|
| 1901 |
+
element accesses beyond what is required to determine the result of the
|
| 1902 |
+
comparison. — *end note*]
|
| 1903 |
|
| 1904 |
#### Tuple traits <a id="tuple.traits">[[tuple.traits]]</a>
|
| 1905 |
|
| 1906 |
``` cpp
|
| 1907 |
template <class... Types, class Alloc>
|
|
|
|
| 1909 |
```
|
| 1910 |
|
| 1911 |
*Requires:* `Alloc` shall be an
|
| 1912 |
`Allocator` ([[allocator.requirements]]).
|
| 1913 |
|
| 1914 |
+
[*Note 1*: Specialization of this trait informs other library
|
| 1915 |
+
components that `tuple` can be constructed with an allocator, even
|
| 1916 |
+
though it does not have a nested `allocator_type`. — *end note*]
|
| 1917 |
|
| 1918 |
#### Tuple specialized algorithms <a id="tuple.special">[[tuple.special]]</a>
|
| 1919 |
|
| 1920 |
``` cpp
|
| 1921 |
template <class... Types>
|
| 1922 |
void swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(see below);
|
| 1923 |
```
|
| 1924 |
|
| 1925 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 1926 |
+
unless `is_swappable_v<``Tᵢ``>` is `true` for all i, where
|
| 1927 |
+
0 ≤ i < `sizeof...(Types)`. The expression inside `noexcept` is
|
| 1928 |
+
equivalent to:
|
| 1929 |
|
| 1930 |
``` cpp
|
| 1931 |
noexcept(x.swap(y))
|
| 1932 |
```
|
| 1933 |
|
| 1934 |
+
*Effects:* As if by `x.swap(y)`.
|
| 1935 |
|
| 1936 |
+
## Optional objects <a id="optional">[[optional]]</a>
|
| 1937 |
|
| 1938 |
+
### In general <a id="optional.general">[[optional.general]]</a>
|
| 1939 |
|
| 1940 |
+
This subclause describes class template `optional` that represents
|
| 1941 |
+
optional objects. An *optional object* is an object that contains the
|
| 1942 |
+
storage for another object and manages the lifetime of this contained
|
| 1943 |
+
object, if any. The contained object may be initialized after the
|
| 1944 |
+
optional object has been initialized, and may be destroyed before the
|
| 1945 |
+
optional object has been destroyed. The initialization state of the
|
| 1946 |
+
contained object is tracked by the optional object.
|
| 1947 |
+
|
| 1948 |
+
### Header `<optional>` synopsis <a id="optional.syn">[[optional.syn]]</a>
|
| 1949 |
+
|
| 1950 |
+
``` cpp
|
| 1951 |
+
namespace std {
|
| 1952 |
+
// [optional.optional], class template optional
|
| 1953 |
+
template <class T>
|
| 1954 |
+
class optional;
|
| 1955 |
+
|
| 1956 |
+
// [optional.nullopt], no-value state indicator
|
| 1957 |
+
struct nullopt_t{see below};
|
| 1958 |
+
inline constexpr nullopt_t nullopt(unspecified);
|
| 1959 |
+
|
| 1960 |
+
// [optional.bad.access], class bad_optional_access
|
| 1961 |
+
class bad_optional_access;
|
| 1962 |
+
|
| 1963 |
+
// [optional.relops], relational operators
|
| 1964 |
+
template <class T, class U>
|
| 1965 |
+
constexpr bool operator==(const optional<T>&, const optional<U>&);
|
| 1966 |
+
template <class T, class U>
|
| 1967 |
+
constexpr bool operator!=(const optional<T>&, const optional<U>&);
|
| 1968 |
+
template <class T, class U>
|
| 1969 |
+
constexpr bool operator<(const optional<T>&, const optional<U>&);
|
| 1970 |
+
template <class T, class U>
|
| 1971 |
+
constexpr bool operator>(const optional<T>&, const optional<U>&);
|
| 1972 |
+
template <class T, class U>
|
| 1973 |
+
constexpr bool operator<=(const optional<T>&, const optional<U>&);
|
| 1974 |
+
template <class T, class U>
|
| 1975 |
+
constexpr bool operator>=(const optional<T>&, const optional<U>&);
|
| 1976 |
+
|
| 1977 |
+
// [optional.nullops], comparison with nullopt
|
| 1978 |
+
template <class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
|
| 1979 |
+
template <class T> constexpr bool operator==(nullopt_t, const optional<T>&) noexcept;
|
| 1980 |
+
template <class T> constexpr bool operator!=(const optional<T>&, nullopt_t) noexcept;
|
| 1981 |
+
template <class T> constexpr bool operator!=(nullopt_t, const optional<T>&) noexcept;
|
| 1982 |
+
template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept;
|
| 1983 |
+
template <class T> constexpr bool operator<(nullopt_t, const optional<T>&) noexcept;
|
| 1984 |
+
template <class T> constexpr bool operator<=(const optional<T>&, nullopt_t) noexcept;
|
| 1985 |
+
template <class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept;
|
| 1986 |
+
template <class T> constexpr bool operator>(const optional<T>&, nullopt_t) noexcept;
|
| 1987 |
+
template <class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept;
|
| 1988 |
+
template <class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept;
|
| 1989 |
+
template <class T> constexpr bool operator>=(nullopt_t, const optional<T>&) noexcept;
|
| 1990 |
+
|
| 1991 |
+
// [optional.comp_with_t], comparison with T
|
| 1992 |
+
template <class T, class U> constexpr bool operator==(const optional<T>&, const U&);
|
| 1993 |
+
template <class T, class U> constexpr bool operator==(const U&, const optional<T>&);
|
| 1994 |
+
template <class T, class U> constexpr bool operator!=(const optional<T>&, const U&);
|
| 1995 |
+
template <class T, class U> constexpr bool operator!=(const U&, const optional<T>&);
|
| 1996 |
+
template <class T, class U> constexpr bool operator<(const optional<T>&, const U&);
|
| 1997 |
+
template <class T, class U> constexpr bool operator<(const U&, const optional<T>&);
|
| 1998 |
+
template <class T, class U> constexpr bool operator<=(const optional<T>&, const U&);
|
| 1999 |
+
template <class T, class U> constexpr bool operator<=(const U&, const optional<T>&);
|
| 2000 |
+
template <class T, class U> constexpr bool operator>(const optional<T>&, const U&);
|
| 2001 |
+
template <class T, class U> constexpr bool operator>(const U&, const optional<T>&);
|
| 2002 |
+
template <class T, class U> constexpr bool operator>=(const optional<T>&, const U&);
|
| 2003 |
+
template <class T, class U> constexpr bool operator>=(const U&, const optional<T>&);
|
| 2004 |
+
|
| 2005 |
+
// [optional.specalg], specialized algorithms
|
| 2006 |
+
template <class T>
|
| 2007 |
+
void swap(optional<T>&, optional<T>&) noexcept(see below);
|
| 2008 |
+
|
| 2009 |
+
template <class T>
|
| 2010 |
+
constexpr optional<see below> make_optional(T&&);
|
| 2011 |
+
template <class T, class... Args>
|
| 2012 |
+
constexpr optional<T> make_optional(Args&&... args);
|
| 2013 |
+
template <class T, class U, class... Args>
|
| 2014 |
+
constexpr optional<T> make_optional(initializer_list<U> il, Args&&... args);
|
| 2015 |
+
|
| 2016 |
+
// [optional.hash], hash support
|
| 2017 |
+
template <class T> struct hash;
|
| 2018 |
+
template <class T> struct hash<optional<T>>;
|
| 2019 |
+
}
|
| 2020 |
+
```
|
| 2021 |
+
|
| 2022 |
+
A program that necessitates the instantiation of template `optional` for
|
| 2023 |
+
a reference type, or for possibly cv-qualified types `in_place_t` or
|
| 2024 |
+
`nullopt_t` is ill-formed.
|
| 2025 |
+
|
| 2026 |
+
### Class template `optional` <a id="optional.optional">[[optional.optional]]</a>
|
| 2027 |
+
|
| 2028 |
+
``` cpp
|
| 2029 |
+
template <class T>
|
| 2030 |
+
class optional {
|
| 2031 |
+
public:
|
| 2032 |
+
using value_type = T;
|
| 2033 |
+
|
| 2034 |
+
// [optional.ctor], constructors
|
| 2035 |
+
constexpr optional() noexcept;
|
| 2036 |
+
constexpr optional(nullopt_t) noexcept;
|
| 2037 |
+
constexpr optional(const optional&);
|
| 2038 |
+
constexpr optional(optional&&) noexcept(see below);
|
| 2039 |
+
template <class... Args>
|
| 2040 |
+
constexpr explicit optional(in_place_t, Args&&...);
|
| 2041 |
+
template <class U, class... Args>
|
| 2042 |
+
constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
|
| 2043 |
+
template <class U = T>
|
| 2044 |
+
\EXPLICIT constexpr optional(U&&);
|
| 2045 |
+
template <class U>
|
| 2046 |
+
\EXPLICIT optional(const optional<U>&);
|
| 2047 |
+
template <class U>
|
| 2048 |
+
\EXPLICIT optional(optional<U>&&);
|
| 2049 |
+
|
| 2050 |
+
// [optional.dtor], destructor
|
| 2051 |
+
~optional();
|
| 2052 |
+
|
| 2053 |
+
// [optional.assign], assignment
|
| 2054 |
+
optional& operator=(nullopt_t) noexcept;
|
| 2055 |
+
optional& operator=(const optional&);
|
| 2056 |
+
optional& operator=(optional&&) noexcept(see below);
|
| 2057 |
+
template <class U = T> optional& operator=(U&&);
|
| 2058 |
+
template <class U> optional& operator=(const optional<U>&);
|
| 2059 |
+
template <class U> optional& operator=(optional<U>&&);
|
| 2060 |
+
template <class... Args> T& emplace(Args&&...);
|
| 2061 |
+
template <class U, class... Args> T& emplace(initializer_list<U>, Args&&...);
|
| 2062 |
+
|
| 2063 |
+
// [optional.swap], swap
|
| 2064 |
+
void swap(optional&) noexcept(see below);
|
| 2065 |
+
|
| 2066 |
+
// [optional.observe], observers
|
| 2067 |
+
constexpr const T* operator->() const;
|
| 2068 |
+
constexpr T* operator->();
|
| 2069 |
+
constexpr const T& operator*() const&;
|
| 2070 |
+
constexpr T& operator*() &;
|
| 2071 |
+
constexpr T&& operator*() &&;
|
| 2072 |
+
constexpr const T&& operator*() const&&;
|
| 2073 |
+
constexpr explicit operator bool() const noexcept;
|
| 2074 |
+
constexpr bool has_value() const noexcept;
|
| 2075 |
+
constexpr const T& value() const&;
|
| 2076 |
+
constexpr T& value() &;
|
| 2077 |
+
constexpr T&& value() &&;
|
| 2078 |
+
constexpr const T&& value() const&&;
|
| 2079 |
+
template <class U> constexpr T value_or(U&&) const&;
|
| 2080 |
+
template <class U> constexpr T value_or(U&&) &&;
|
| 2081 |
+
|
| 2082 |
+
// [optional.mod], modifiers
|
| 2083 |
+
void reset() noexcept;
|
| 2084 |
+
|
| 2085 |
+
private:
|
| 2086 |
+
T *val; // exposition only
|
| 2087 |
+
};
|
| 2088 |
+
|
| 2089 |
+
template<class T> optional(T) -> optional<T>;
|
| 2090 |
+
```
|
| 2091 |
+
|
| 2092 |
+
Any instance of `optional<T>` at any given time either contains a value
|
| 2093 |
+
or does not contain a value. When an instance of `optional<T>` *contains
|
| 2094 |
+
a value*, it means that an object of type `T`, referred to as the
|
| 2095 |
+
optional object’s *contained value*, is allocated within the storage of
|
| 2096 |
+
the optional object. Implementations are not permitted to use additional
|
| 2097 |
+
storage, such as dynamic memory, to allocate its contained value. The
|
| 2098 |
+
contained value shall be allocated in a region of the `optional<T>`
|
| 2099 |
+
storage suitably aligned for the type `T`. When an object of type
|
| 2100 |
+
`optional<T>` is contextually converted to `bool`, the conversion
|
| 2101 |
+
returns `true` if the object contains a value; otherwise the conversion
|
| 2102 |
+
returns `false`.
|
| 2103 |
+
|
| 2104 |
+
Member `val` is provided for exposition only. When an `optional<T>`
|
| 2105 |
+
object contains a value, `val` points to the contained value.
|
| 2106 |
+
|
| 2107 |
+
`T` shall be an object type and shall satisfy the requirements of
|
| 2108 |
+
`Destructible` (Table [[tab:destructible]]).
|
| 2109 |
+
|
| 2110 |
+
#### Constructors <a id="optional.ctor">[[optional.ctor]]</a>
|
| 2111 |
+
|
| 2112 |
+
``` cpp
|
| 2113 |
+
constexpr optional() noexcept;
|
| 2114 |
+
constexpr optional(nullopt_t) noexcept;
|
| 2115 |
+
```
|
| 2116 |
+
|
| 2117 |
+
*Postconditions:* `*this` does not contain a value.
|
| 2118 |
+
|
| 2119 |
+
*Remarks:* No contained value is initialized. For every object type `T`
|
| 2120 |
+
these constructors shall be constexpr constructors ([[dcl.constexpr]]).
|
| 2121 |
+
|
| 2122 |
+
``` cpp
|
| 2123 |
+
constexpr optional(const optional& rhs);
|
| 2124 |
+
```
|
| 2125 |
+
|
| 2126 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 2127 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 2128 |
+
expression `*rhs`.
|
| 2129 |
+
|
| 2130 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 2131 |
+
|
| 2132 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2133 |
+
|
| 2134 |
+
*Remarks:* This constructor shall be defined as deleted unless
|
| 2135 |
+
`is_copy_constructible_v<T>` is `true`. If
|
| 2136 |
+
`is_trivially_copy_constructible_v<T>` is `true`, this constructor shall
|
| 2137 |
+
be a `constexpr` constructor.
|
| 2138 |
+
|
| 2139 |
+
``` cpp
|
| 2140 |
+
constexpr optional(optional&& rhs) noexcept(see below);
|
| 2141 |
+
```
|
| 2142 |
+
|
| 2143 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 2144 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 2145 |
+
expression `std::move(*rhs)`. `bool(rhs)` is unchanged.
|
| 2146 |
+
|
| 2147 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 2148 |
+
|
| 2149 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2150 |
+
|
| 2151 |
+
*Remarks:* The expression inside `noexcept` is equivalent to
|
| 2152 |
+
`is_nothrow_move_constructible_v<T>`. This constructor shall not
|
| 2153 |
+
participate in overload resolution unless `is_move_constructible_v<T>`
|
| 2154 |
+
is `true`. If `is_trivially_move_constructible_v<T>` is `true`, this
|
| 2155 |
+
constructor shall be a `constexpr` constructor.
|
| 2156 |
+
|
| 2157 |
+
``` cpp
|
| 2158 |
+
template <class... Args> constexpr explicit optional(in_place_t, Args&&... args);
|
| 2159 |
+
```
|
| 2160 |
+
|
| 2161 |
+
*Effects:* Initializes the contained value as if
|
| 2162 |
+
direct-non-list-initializing an object of type `T` with the arguments
|
| 2163 |
+
`std::forward<Args>(args)...`.
|
| 2164 |
+
|
| 2165 |
+
*Postconditions:* `*this` contains a value.
|
| 2166 |
+
|
| 2167 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2168 |
+
|
| 2169 |
+
*Remarks:* If `T`’s constructor selected for the initialization is a
|
| 2170 |
+
constexpr constructor, this constructor shall be a constexpr
|
| 2171 |
+
constructor. This constructor shall not participate in overload
|
| 2172 |
+
resolution unless `is_constructible_v<T, Args...>` is `true`.
|
| 2173 |
+
|
| 2174 |
+
``` cpp
|
| 2175 |
+
template <class U, class... Args>
|
| 2176 |
+
constexpr explicit optional(in_place_t, initializer_list<U> il, Args&&... args);
|
| 2177 |
+
```
|
| 2178 |
+
|
| 2179 |
+
*Effects:* Initializes the contained value as if
|
| 2180 |
+
direct-non-list-initializing an object of type `T` with the arguments
|
| 2181 |
+
`il, std::forward<Args>(args)...`.
|
| 2182 |
+
|
| 2183 |
+
*Postconditions:* `*this` contains a value.
|
| 2184 |
+
|
| 2185 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2186 |
+
|
| 2187 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 2188 |
+
unless `is_constructible_v<T, initializer_list<U>&, Args&&...>` is
|
| 2189 |
+
`true`. If `T`’s constructor selected for the initialization is a
|
| 2190 |
+
constexpr constructor, this constructor shall be a constexpr
|
| 2191 |
+
constructor.
|
| 2192 |
+
|
| 2193 |
+
[*Note 1*: The following constructors are conditionally specified as
|
| 2194 |
+
explicit. This is typically implemented by declaring two such
|
| 2195 |
+
constructors, of which at most one participates in overload
|
| 2196 |
+
resolution. — *end note*]
|
| 2197 |
+
|
| 2198 |
+
``` cpp
|
| 2199 |
+
template <class U = T> \EXPLICIT constexpr optional(U&& v);
|
| 2200 |
+
```
|
| 2201 |
+
|
| 2202 |
+
*Effects:* Initializes the contained value as if
|
| 2203 |
+
direct-non-list-initializing an object of type `T` with the expression
|
| 2204 |
+
`std::forward<U>(v)`.
|
| 2205 |
+
|
| 2206 |
+
*Postconditions:* `*this` contains a value.
|
| 2207 |
+
|
| 2208 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2209 |
+
|
| 2210 |
+
*Remarks:* If `T`’s selected constructor is a constexpr constructor,
|
| 2211 |
+
this constructor shall be a constexpr constructor. This constructor
|
| 2212 |
+
shall not participate in overload resolution unless
|
| 2213 |
+
`is_constructible_v<T, U&&>` is `true`,
|
| 2214 |
+
`is_same_v<decay_t<U>, in_place_t>` is `false`, and
|
| 2215 |
+
`is_same_v<optional<T>, decay_t<U>>` is `false`. The constructor is
|
| 2216 |
+
explicit if and only if `is_convertible_v<U&&, T>` is `false`.
|
| 2217 |
+
|
| 2218 |
+
``` cpp
|
| 2219 |
+
template <class U> \EXPLICIT optional(const optional<U>& rhs);
|
| 2220 |
+
```
|
| 2221 |
+
|
| 2222 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 2223 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 2224 |
+
expression `*rhs`.
|
| 2225 |
+
|
| 2226 |
+
*Postconditions:* `bool(rhs)` == `bool(*this)`.
|
| 2227 |
+
|
| 2228 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2229 |
+
|
| 2230 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 2231 |
+
unless
|
| 2232 |
+
|
| 2233 |
+
- `is_constructible_v<T, const U&>` is `true`,
|
| 2234 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 2235 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 2236 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 2237 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 2238 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 2239 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 2240 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`, and
|
| 2241 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`.
|
| 2242 |
+
|
| 2243 |
+
The constructor is explicit if and only if
|
| 2244 |
+
`is_convertible_v<const U&, T>` is `false`.
|
| 2245 |
+
|
| 2246 |
+
``` cpp
|
| 2247 |
+
template <class U> \EXPLICIT optional(optional<U>&& rhs);
|
| 2248 |
+
```
|
| 2249 |
+
|
| 2250 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 2251 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 2252 |
+
expression `std::move(*rhs)`. `bool(rhs)` is unchanged.
|
| 2253 |
+
|
| 2254 |
+
*Postconditions:* `bool(rhs)` == `bool(*this)`.
|
| 2255 |
+
|
| 2256 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2257 |
+
|
| 2258 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 2259 |
+
unless
|
| 2260 |
+
|
| 2261 |
+
- `is_constructible_v<T, U&&>` is true,
|
| 2262 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 2263 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 2264 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 2265 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 2266 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 2267 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 2268 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`, and
|
| 2269 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`.
|
| 2270 |
+
|
| 2271 |
+
The constructor is explicit if and only if `is_convertible_v<U&&, T>` is
|
| 2272 |
+
`false`.
|
| 2273 |
+
|
| 2274 |
+
#### Destructor <a id="optional.dtor">[[optional.dtor]]</a>
|
| 2275 |
+
|
| 2276 |
+
``` cpp
|
| 2277 |
+
~optional();
|
| 2278 |
+
```
|
| 2279 |
+
|
| 2280 |
+
*Effects:* If `is_trivially_destructible_v<T> != true` and `*this`
|
| 2281 |
+
contains a value, calls
|
| 2282 |
+
|
| 2283 |
+
``` cpp
|
| 2284 |
+
val->T::~T()
|
| 2285 |
+
```
|
| 2286 |
+
|
| 2287 |
+
*Remarks:* If `is_trivially_destructible_v<T> == true` then this
|
| 2288 |
+
destructor shall be a trivial destructor.
|
| 2289 |
+
|
| 2290 |
+
#### Assignment <a id="optional.assign">[[optional.assign]]</a>
|
| 2291 |
+
|
| 2292 |
+
``` cpp
|
| 2293 |
+
optional<T>& operator=(nullopt_t) noexcept;
|
| 2294 |
+
```
|
| 2295 |
+
|
| 2296 |
+
*Effects:* If `*this` contains a value, calls `val->T::T̃()` to destroy
|
| 2297 |
+
the contained value; otherwise no effect.
|
| 2298 |
+
|
| 2299 |
+
*Returns:* `*this`.
|
| 2300 |
+
|
| 2301 |
+
*Postconditions:* `*this` does not contain a value.
|
| 2302 |
+
|
| 2303 |
+
``` cpp
|
| 2304 |
+
optional<T>& operator=(const optional& rhs);
|
| 2305 |
+
```
|
| 2306 |
+
|
| 2307 |
+
*Effects:* See Table [[tab:optional.assign.copy]].
|
| 2308 |
+
|
| 2309 |
+
**Table: `optional::operator=(const optional&)` effects** <a id="tab:optional.assign.copy">[tab:optional.assign.copy]</a>
|
| 2310 |
+
|
| 2311 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 2312 |
+
| ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
|
| 2313 |
+
| `rhs` contains a value | assigns `*rhs` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `*rhs` |
|
| 2314 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 2315 |
+
|
| 2316 |
+
|
| 2317 |
+
*Returns:* `*this`.
|
| 2318 |
+
|
| 2319 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 2320 |
+
|
| 2321 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 2322 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 2323 |
+
call to `T`’s copy constructor, no effect. If an exception is thrown
|
| 2324 |
+
during the call to `T`’s copy assignment, the state of its contained
|
| 2325 |
+
value is as defined by the exception safety guarantee of `T`’s copy
|
| 2326 |
+
assignment. This operator shall be defined as deleted unless
|
| 2327 |
+
`is_copy_constructible_v<T>` is `true` and `is_copy_assignable_v<T>` is
|
| 2328 |
+
`true`.
|
| 2329 |
+
|
| 2330 |
+
``` cpp
|
| 2331 |
+
optional<T>& operator=(optional&& rhs) noexcept(see below);
|
| 2332 |
+
```
|
| 2333 |
+
|
| 2334 |
+
*Effects:* See Table [[tab:optional.assign.move]]. The result of the
|
| 2335 |
+
expression `bool(rhs)` remains unchanged.
|
| 2336 |
+
|
| 2337 |
+
**Table: `optional::operator=(optional&&)` effects** <a id="tab:optional.assign.move">[tab:optional.assign.move]</a>
|
| 2338 |
+
|
| 2339 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 2340 |
+
| ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 2341 |
+
| `rhs` contains a value | assigns `std::move(*rhs)` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `std::move(*rhs)` |
|
| 2342 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 2343 |
+
|
| 2344 |
+
|
| 2345 |
+
*Returns:* `*this`.
|
| 2346 |
+
|
| 2347 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 2348 |
+
|
| 2349 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 2350 |
+
|
| 2351 |
+
``` cpp
|
| 2352 |
+
is_nothrow_move_assignable_v<T> && is_nothrow_move_constructible_v<T>
|
| 2353 |
+
```
|
| 2354 |
+
|
| 2355 |
+
If any exception is thrown, the result of the expression `bool(*this)`
|
| 2356 |
+
remains unchanged. If an exception is thrown during the call to `T`’s
|
| 2357 |
+
move constructor, the state of `*rhs.val` is determined by the exception
|
| 2358 |
+
safety guarantee of `T`’s move constructor. If an exception is thrown
|
| 2359 |
+
during the call to `T`’s move assignment, the state of `*val` and
|
| 2360 |
+
`*rhs.val` is determined by the exception safety guarantee of `T`’s move
|
| 2361 |
+
assignment. This operator shall not participate in overload resolution
|
| 2362 |
+
unless `is_move_constructible_v<T>` is `true` and
|
| 2363 |
+
`is_move_assignable_v<T>` is `true`.
|
| 2364 |
+
|
| 2365 |
+
``` cpp
|
| 2366 |
+
template <class U = T> optional<T>& operator=(U&& v);
|
| 2367 |
+
```
|
| 2368 |
+
|
| 2369 |
+
*Effects:* If `*this` contains a value, assigns `std::forward<U>(v)` to
|
| 2370 |
+
the contained value; otherwise initializes the contained value as if
|
| 2371 |
+
direct-non-list-initializing object of type `T` with
|
| 2372 |
+
`std::forward<U>(v)`.
|
| 2373 |
+
|
| 2374 |
+
*Returns:* `*this`.
|
| 2375 |
+
|
| 2376 |
+
*Postconditions:* `*this` contains a value.
|
| 2377 |
+
|
| 2378 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 2379 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 2380 |
+
call to `T`’s constructor, the state of `v` is determined by the
|
| 2381 |
+
exception safety guarantee of `T`’s constructor. If an exception is
|
| 2382 |
+
thrown during the call to `T`’s assignment, the state of `*val` and `v`
|
| 2383 |
+
is determined by the exception safety guarantee of `T`’s assignment.
|
| 2384 |
+
This function shall not participate in overload resolution unless
|
| 2385 |
+
`is_same_v<optional<T>, decay_t<U>>` is `false`,
|
| 2386 |
+
`conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>>` is `false`,
|
| 2387 |
+
`is_constructible_v<T, U>` is `true`, and `is_assignable_v<T&, U>` is
|
| 2388 |
+
`true`.
|
| 2389 |
+
|
| 2390 |
+
``` cpp
|
| 2391 |
+
template <class U> optional<T>& operator=(const optional<U>& rhs);
|
| 2392 |
+
```
|
| 2393 |
+
|
| 2394 |
+
*Effects:* See Table [[tab:optional.assign.copy.templ]].
|
| 2395 |
+
|
| 2396 |
+
**Table: `optional::operator=(const optional<U>&)` effects** <a id="tab:optional.assign.copy.templ">[tab:optional.assign.copy.templ]</a>
|
| 2397 |
+
|
| 2398 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 2399 |
+
| ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
|
| 2400 |
+
| `rhs` contains a value | assigns `*rhs` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `*rhs` |
|
| 2401 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 2402 |
+
|
| 2403 |
+
|
| 2404 |
+
*Returns:* `*this`.
|
| 2405 |
+
|
| 2406 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 2407 |
+
|
| 2408 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 2409 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 2410 |
+
call to `T`’s constructor, the state of `*rhs.val` is determined by the
|
| 2411 |
+
exception safety guarantee of `T`’s constructor. If an exception is
|
| 2412 |
+
thrown during the call to `T`’s assignment, the state of `*val` and
|
| 2413 |
+
`*rhs.val` is determined by the exception safety guarantee of `T`’s
|
| 2414 |
+
assignment. This function shall not participate in overload resolution
|
| 2415 |
+
unless
|
| 2416 |
+
|
| 2417 |
+
- `is_constructible_v<T, const U&>` is `true`,
|
| 2418 |
+
- `is_assignable_v<T&, const U&>` is `true`,
|
| 2419 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 2420 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 2421 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 2422 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 2423 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 2424 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 2425 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`,
|
| 2426 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`,
|
| 2427 |
+
- `is_assignable_v<T&, optional<U>&>` is `false`,
|
| 2428 |
+
- `is_assignable_v<T&, optional<U>&&>` is `false`,
|
| 2429 |
+
- `is_assignable_v<T&, const optional<U>&>` is `false`, and
|
| 2430 |
+
- `is_assignable_v<T&, const optional<U>&&>` is `false`.
|
| 2431 |
+
|
| 2432 |
+
``` cpp
|
| 2433 |
+
template <class U> optional<T>& operator=(optional<U>&& rhs);
|
| 2434 |
+
```
|
| 2435 |
+
|
| 2436 |
+
*Effects:* See Table [[tab:optional.assign.move.templ]]. The result of
|
| 2437 |
+
the expression `bool(rhs)` remains unchanged.
|
| 2438 |
+
|
| 2439 |
+
**Table: `optional::operator=(optional<U>&&)` effects** <a id="tab:optional.assign.move.templ">[tab:optional.assign.move.templ]</a>
|
| 2440 |
+
|
| 2441 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 2442 |
+
| ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 2443 |
+
| `rhs` contains a value | assigns `std::move(*rhs)` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `std::move(*rhs)` |
|
| 2444 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 2445 |
+
|
| 2446 |
+
|
| 2447 |
+
*Returns:* `*this`.
|
| 2448 |
+
|
| 2449 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 2450 |
+
|
| 2451 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 2452 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 2453 |
+
call to `T`’s constructor, the state of `*rhs.val` is determined by the
|
| 2454 |
+
exception safety guarantee of `T`’s constructor. If an exception is
|
| 2455 |
+
thrown during the call to `T`’s assignment, the state of `*val` and
|
| 2456 |
+
`*rhs.val` is determined by the exception safety guarantee of `T`’s
|
| 2457 |
+
assignment. This function shall not participate in overload resolution
|
| 2458 |
+
unless
|
| 2459 |
+
|
| 2460 |
+
- `is_constructible_v<T, U>` is `true`,
|
| 2461 |
+
- `is_assignable_v<T&, U>` is `true`,
|
| 2462 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 2463 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 2464 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 2465 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 2466 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 2467 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 2468 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`,
|
| 2469 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`,
|
| 2470 |
+
- `is_assignable_v<T&, optional<U>&>` is `false`,
|
| 2471 |
+
- `is_assignable_v<T&, optional<U>&&>` is `false`,
|
| 2472 |
+
- `is_assignable_v<T&, const optional<U>&>` is `false`, and
|
| 2473 |
+
- `is_assignable_v<T&, const optional<U>&&>` is `false`.
|
| 2474 |
+
|
| 2475 |
+
``` cpp
|
| 2476 |
+
template <class... Args> T& emplace(Args&&... args);
|
| 2477 |
+
```
|
| 2478 |
+
|
| 2479 |
+
*Requires:* `is_constructible_v<T, Args&&...>` is `true`.
|
| 2480 |
+
|
| 2481 |
+
*Effects:* Calls `*this = nullopt`. Then initializes the contained value
|
| 2482 |
+
as if direct-non-list-initializing an object of type `T` with the
|
| 2483 |
+
arguments `std::forward<Args>(args)...`.
|
| 2484 |
+
|
| 2485 |
+
*Postconditions:* `*this` contains a value.
|
| 2486 |
+
|
| 2487 |
+
*Returns:* A reference to the new contained value.
|
| 2488 |
+
|
| 2489 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2490 |
+
|
| 2491 |
+
*Remarks:* If an exception is thrown during the call to `T`’s
|
| 2492 |
+
constructor, `*this` does not contain a value, and the previous `*val`
|
| 2493 |
+
(if any) has been destroyed.
|
| 2494 |
+
|
| 2495 |
+
``` cpp
|
| 2496 |
+
template <class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
|
| 2497 |
+
```
|
| 2498 |
+
|
| 2499 |
+
*Effects:* Calls `*this = nullopt`. Then initializes the contained value
|
| 2500 |
+
as if direct-non-list-initializing an object of type `T` with the
|
| 2501 |
+
arguments `il, std::forward<Args>(args)...`.
|
| 2502 |
+
|
| 2503 |
+
*Postconditions:* `*this` contains a value.
|
| 2504 |
+
|
| 2505 |
+
*Returns:* A reference to the new contained value.
|
| 2506 |
+
|
| 2507 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2508 |
+
|
| 2509 |
+
*Remarks:* If an exception is thrown during the call to `T`’s
|
| 2510 |
+
constructor, `*this` does not contain a value, and the previous `*val`
|
| 2511 |
+
(if any) has been destroyed. This function shall not participate in
|
| 2512 |
+
overload resolution unless
|
| 2513 |
+
`is_constructible_v<T, initializer_list<U>&, Args&&...>` is `true`.
|
| 2514 |
+
|
| 2515 |
+
#### Swap <a id="optional.swap">[[optional.swap]]</a>
|
| 2516 |
+
|
| 2517 |
+
``` cpp
|
| 2518 |
+
void swap(optional& rhs) noexcept(see below);
|
| 2519 |
+
```
|
| 2520 |
+
|
| 2521 |
+
*Requires:* Lvalues of type `T` shall be swappable and
|
| 2522 |
+
`is_move_constructible_v<T>` is `true`.
|
| 2523 |
+
|
| 2524 |
+
*Effects:* See Table [[tab:optional.swap]].
|
| 2525 |
+
|
| 2526 |
+
**Table: `optional::swap(optional&)` effects** <a id="tab:optional.swap">[tab:optional.swap]</a>
|
| 2527 |
+
|
| 2528 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 2529 |
+
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
| 2530 |
+
| `rhs` contains a value | calls `swap(*(*this), *rhs)` | initializes the contained value of `*this` as if direct-non-list-initializing an object of type `T` with the expression `std::move(*rhs)`, followed by `rhs.val->T::~T()`; postcondition is that `*this` contains a value and `rhs` does not contain a value |
|
| 2531 |
+
| `rhs` does not contain a value | initializes the contained value of `rhs` as if direct-non-list-initializing an object of type `T` with the expression `std::move(*(*this))`, followed by `val->T::~T()`; postcondition is that `*this` does not contain a value and `rhs` contains a value | no effect |
|
| 2532 |
+
|
| 2533 |
+
|
| 2534 |
+
*Throws:* Any exceptions thrown by the operations in the relevant part
|
| 2535 |
+
of Table [[tab:optional.swap]].
|
| 2536 |
+
|
| 2537 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 2538 |
+
|
| 2539 |
+
``` cpp
|
| 2540 |
+
is_nothrow_move_constructible_v<T> && is_nothrow_swappable_v<T>
|
| 2541 |
+
```
|
| 2542 |
+
|
| 2543 |
+
If any exception is thrown, the results of the expressions `bool(*this)`
|
| 2544 |
+
and `bool(rhs)` remain unchanged. If an exception is thrown during the
|
| 2545 |
+
call to function `swap`, the state of `*val` and `*rhs.val` is
|
| 2546 |
+
determined by the exception safety guarantee of `swap` for lvalues of
|
| 2547 |
+
`T`. If an exception is thrown during the call to `T`’s move
|
| 2548 |
+
constructor, the state of `*val` and `*rhs.val` is determined by the
|
| 2549 |
+
exception safety guarantee of `T`’s move constructor.
|
| 2550 |
+
|
| 2551 |
+
#### Observers <a id="optional.observe">[[optional.observe]]</a>
|
| 2552 |
+
|
| 2553 |
+
``` cpp
|
| 2554 |
+
constexpr const T* operator->() const;
|
| 2555 |
+
constexpr T* operator->();
|
| 2556 |
+
```
|
| 2557 |
+
|
| 2558 |
+
*Requires:* `*this` contains a value.
|
| 2559 |
+
|
| 2560 |
+
*Returns:* `val`.
|
| 2561 |
+
|
| 2562 |
+
*Throws:* Nothing.
|
| 2563 |
+
|
| 2564 |
+
*Remarks:* These functions shall be constexpr functions.
|
| 2565 |
+
|
| 2566 |
+
``` cpp
|
| 2567 |
+
constexpr const T& operator*() const&;
|
| 2568 |
+
constexpr T& operator*() &;
|
| 2569 |
+
```
|
| 2570 |
+
|
| 2571 |
+
*Requires:* `*this` contains a value.
|
| 2572 |
+
|
| 2573 |
+
*Returns:* `*val`.
|
| 2574 |
+
|
| 2575 |
+
*Throws:* Nothing.
|
| 2576 |
+
|
| 2577 |
+
*Remarks:* These functions shall be constexpr functions.
|
| 2578 |
+
|
| 2579 |
+
``` cpp
|
| 2580 |
+
constexpr T&& operator*() &&;
|
| 2581 |
+
constexpr const T&& operator*() const&&;
|
| 2582 |
+
```
|
| 2583 |
+
|
| 2584 |
+
*Requires:* `*this` contains a value.
|
| 2585 |
+
|
| 2586 |
+
*Effects:* Equivalent to: `return std::move(*val);`
|
| 2587 |
+
|
| 2588 |
+
``` cpp
|
| 2589 |
+
constexpr explicit operator bool() const noexcept;
|
| 2590 |
+
```
|
| 2591 |
+
|
| 2592 |
+
*Returns:* `true` if and only if `*this` contains a value.
|
| 2593 |
+
|
| 2594 |
+
*Remarks:* This function shall be a constexpr function.
|
| 2595 |
+
|
| 2596 |
+
``` cpp
|
| 2597 |
+
constexpr bool has_value() const noexcept;
|
| 2598 |
+
```
|
| 2599 |
+
|
| 2600 |
+
*Returns:* `true` if and only if `*this` contains a value.
|
| 2601 |
+
|
| 2602 |
+
*Remarks:* This function shall be a constexpr function.
|
| 2603 |
+
|
| 2604 |
+
``` cpp
|
| 2605 |
+
constexpr const T& value() const&;
|
| 2606 |
+
constexpr T& value() &;
|
| 2607 |
+
```
|
| 2608 |
+
|
| 2609 |
+
*Effects:* Equivalent to:
|
| 2610 |
+
|
| 2611 |
+
``` cpp
|
| 2612 |
+
return bool(*this) ? *val : throw bad_optional_access();
|
| 2613 |
+
```
|
| 2614 |
+
|
| 2615 |
+
``` cpp
|
| 2616 |
+
constexpr T&& value() &&;
|
| 2617 |
+
constexpr const T&& value() const&&;
|
| 2618 |
+
```
|
| 2619 |
+
|
| 2620 |
+
*Effects:* Equivalent to:
|
| 2621 |
+
|
| 2622 |
+
``` cpp
|
| 2623 |
+
return bool(*this) ? std::move(*val) : throw bad_optional_access();
|
| 2624 |
+
```
|
| 2625 |
+
|
| 2626 |
+
``` cpp
|
| 2627 |
+
template <class U> constexpr T value_or(U&& v) const&;
|
| 2628 |
+
```
|
| 2629 |
+
|
| 2630 |
+
*Effects:* Equivalent to:
|
| 2631 |
+
|
| 2632 |
+
``` cpp
|
| 2633 |
+
return bool(*this) ? **this : static_cast<T>(std::forward<U>(v));
|
| 2634 |
+
```
|
| 2635 |
+
|
| 2636 |
+
*Remarks:* If `is_copy_constructible_v<T> && is_convertible_v<U&&, T>`
|
| 2637 |
+
is `false`, the program is ill-formed.
|
| 2638 |
+
|
| 2639 |
+
``` cpp
|
| 2640 |
+
template <class U> constexpr T value_or(U&& v) &&;
|
| 2641 |
+
```
|
| 2642 |
+
|
| 2643 |
+
*Effects:* Equivalent to:
|
| 2644 |
+
|
| 2645 |
+
``` cpp
|
| 2646 |
+
return bool(*this) ? std::move(**this) : static_cast<T>(std::forward<U>(v));
|
| 2647 |
+
```
|
| 2648 |
+
|
| 2649 |
+
*Remarks:* If `is_move_constructible_v<T> && is_convertible_v<U&&, T>`
|
| 2650 |
+
is `false`, the program is ill-formed.
|
| 2651 |
+
|
| 2652 |
+
#### Modifiers <a id="optional.mod">[[optional.mod]]</a>
|
| 2653 |
+
|
| 2654 |
+
``` cpp
|
| 2655 |
+
void reset() noexcept;
|
| 2656 |
+
```
|
| 2657 |
+
|
| 2658 |
+
*Effects:* If `*this` contains a value, calls `val->T::T̃()` to destroy
|
| 2659 |
+
the contained value; otherwise no effect.
|
| 2660 |
+
|
| 2661 |
+
*Postconditions:* `*this` does not contain a value.
|
| 2662 |
+
|
| 2663 |
+
### No-value state indicator <a id="optional.nullopt">[[optional.nullopt]]</a>
|
| 2664 |
+
|
| 2665 |
+
``` cpp
|
| 2666 |
+
struct nullopt_t{see below};
|
| 2667 |
+
inline constexpr nullopt_t nullopt(unspecified);
|
| 2668 |
+
```
|
| 2669 |
+
|
| 2670 |
+
The struct `nullopt_t` is an empty structure type used as a unique type
|
| 2671 |
+
to indicate the state of not containing a value for `optional` objects.
|
| 2672 |
+
In particular, `optional<T>` has a constructor with `nullopt_t` as a
|
| 2673 |
+
single argument; this indicates that an optional object not containing a
|
| 2674 |
+
value shall be constructed.
|
| 2675 |
+
|
| 2676 |
+
Type `nullopt_t` shall not have a default constructor or an
|
| 2677 |
+
initializer-list constructor, and shall not be an aggregate.
|
| 2678 |
+
|
| 2679 |
+
### Class `bad_optional_access` <a id="optional.bad.access">[[optional.bad.access]]</a>
|
| 2680 |
+
|
| 2681 |
+
``` cpp
|
| 2682 |
+
class bad_optional_access : public exception {
|
| 2683 |
+
public:
|
| 2684 |
+
bad_optional_access();
|
| 2685 |
+
};
|
| 2686 |
+
```
|
| 2687 |
+
|
| 2688 |
+
The class `bad_optional_access` defines the type of objects thrown as
|
| 2689 |
+
exceptions to report the situation where an attempt is made to access
|
| 2690 |
+
the value of an optional object that does not contain a value.
|
| 2691 |
+
|
| 2692 |
+
``` cpp
|
| 2693 |
+
bad_optional_access();
|
| 2694 |
+
```
|
| 2695 |
+
|
| 2696 |
+
*Effects:* Constructs an object of class `bad_optional_access`.
|
| 2697 |
+
|
| 2698 |
+
*Postconditions:* `what()` returns an *implementation-defined* NTBS.
|
| 2699 |
+
|
| 2700 |
+
### Relational operators <a id="optional.relops">[[optional.relops]]</a>
|
| 2701 |
+
|
| 2702 |
+
``` cpp
|
| 2703 |
+
template <class T, class U> constexpr bool operator==(const optional<T>& x, const optional<U>& y);
|
| 2704 |
+
```
|
| 2705 |
+
|
| 2706 |
+
*Requires:* The expression `*x == *y` shall be well-formed and its
|
| 2707 |
+
result shall be convertible to `bool`.
|
| 2708 |
+
|
| 2709 |
+
[*Note 1*: `T` need not be `EqualityComparable`. — *end note*]
|
| 2710 |
+
|
| 2711 |
+
*Returns:* If `bool(x) != bool(y)`, `false`; otherwise if
|
| 2712 |
+
`bool(x) == false`, `true`; otherwise `*x == *y`.
|
| 2713 |
+
|
| 2714 |
+
*Remarks:* Specializations of this function template for which
|
| 2715 |
+
`*x == *y` is a core constant expression shall be constexpr functions.
|
| 2716 |
+
|
| 2717 |
+
``` cpp
|
| 2718 |
+
template <class T, class U> constexpr bool operator!=(const optional<T>& x, const optional<U>& y);
|
| 2719 |
+
```
|
| 2720 |
+
|
| 2721 |
+
*Requires:* The expression `*x != *y` shall be well-formed and its
|
| 2722 |
+
result shall be convertible to `bool`.
|
| 2723 |
+
|
| 2724 |
+
*Returns:* If `bool(x) != bool(y)`, `true`; otherwise, if
|
| 2725 |
+
`bool(x) == false`, `false`; otherwise `*x != *y`.
|
| 2726 |
+
|
| 2727 |
+
*Remarks:* Specializations of this function template for which
|
| 2728 |
+
`*x != *y` is a core constant expression shall be constexpr functions.
|
| 2729 |
+
|
| 2730 |
+
``` cpp
|
| 2731 |
+
template <class T, class U> constexpr bool operator<(const optional<T>& x, const optional<U>& y);
|
| 2732 |
+
```
|
| 2733 |
+
|
| 2734 |
+
*Requires:* `*x < *y` shall be well-formed and its result shall be
|
| 2735 |
+
convertible to `bool`.
|
| 2736 |
+
|
| 2737 |
+
*Returns:* If `!y`, `false`; otherwise, if `!x`, `true`; otherwise
|
| 2738 |
+
`*x < *y`.
|
| 2739 |
+
|
| 2740 |
+
*Remarks:* Specializations of this function template for which `*x < *y`
|
| 2741 |
+
is a core constant expression shall be constexpr functions.
|
| 2742 |
+
|
| 2743 |
+
``` cpp
|
| 2744 |
+
template <class T, class U> constexpr bool operator>(const optional<T>& x, const optional<U>& y);
|
| 2745 |
+
```
|
| 2746 |
+
|
| 2747 |
+
*Requires:* The expression `*x > *y` shall be well-formed and its result
|
| 2748 |
+
shall be convertible to `bool`.
|
| 2749 |
+
|
| 2750 |
+
*Returns:* If `!x`, `false`; otherwise, if `!y`, `true`; otherwise
|
| 2751 |
+
`*x > *y`.
|
| 2752 |
+
|
| 2753 |
+
*Remarks:* Specializations of this function template for which `*x > *y`
|
| 2754 |
+
is a core constant expression shall be constexpr functions.
|
| 2755 |
+
|
| 2756 |
+
``` cpp
|
| 2757 |
+
template <class T, class U> constexpr bool operator<=(const optional<T>& x, const optional<U>& y);
|
| 2758 |
+
```
|
| 2759 |
+
|
| 2760 |
+
*Requires:* The expression `*x <= *y` shall be well-formed and its
|
| 2761 |
+
result shall be convertible to `bool`.
|
| 2762 |
+
|
| 2763 |
+
*Returns:* If `!x`, `true`; otherwise, if `!y`, `false`; otherwise
|
| 2764 |
+
`*x <= *y`.
|
| 2765 |
+
|
| 2766 |
+
*Remarks:* Specializations of this function template for which
|
| 2767 |
+
`*x <= *y` is a core constant expression shall be constexpr functions.
|
| 2768 |
+
|
| 2769 |
+
``` cpp
|
| 2770 |
+
template <class T, class U> constexpr bool operator>=(const optional<T>& x, const optional<U>& y);
|
| 2771 |
+
```
|
| 2772 |
+
|
| 2773 |
+
*Requires:* The expression `*x >= *y` shall be well-formed and its
|
| 2774 |
+
result shall be convertible to `bool`.
|
| 2775 |
+
|
| 2776 |
+
*Returns:* If `!y`, `true`; otherwise, if `!x`, `false`; otherwise
|
| 2777 |
+
`*x >= *y`.
|
| 2778 |
+
|
| 2779 |
+
*Remarks:* Specializations of this function template for which
|
| 2780 |
+
`*x >= *y` is a core constant expression shall be constexpr functions.
|
| 2781 |
+
|
| 2782 |
+
### Comparison with `nullopt` <a id="optional.nullops">[[optional.nullops]]</a>
|
| 2783 |
+
|
| 2784 |
+
``` cpp
|
| 2785 |
+
template <class T> constexpr bool operator==(const optional<T>& x, nullopt_t) noexcept;
|
| 2786 |
+
template <class T> constexpr bool operator==(nullopt_t, const optional<T>& x) noexcept;
|
| 2787 |
+
```
|
| 2788 |
+
|
| 2789 |
+
*Returns:* `!x`.
|
| 2790 |
+
|
| 2791 |
+
``` cpp
|
| 2792 |
+
template <class T> constexpr bool operator!=(const optional<T>& x, nullopt_t) noexcept;
|
| 2793 |
+
template <class T> constexpr bool operator!=(nullopt_t, const optional<T>& x) noexcept;
|
| 2794 |
+
```
|
| 2795 |
+
|
| 2796 |
+
*Returns:* `bool(x)`.
|
| 2797 |
+
|
| 2798 |
+
``` cpp
|
| 2799 |
+
template <class T> constexpr bool operator<(const optional<T>& x, nullopt_t) noexcept;
|
| 2800 |
+
```
|
| 2801 |
+
|
| 2802 |
+
*Returns:* `false`.
|
| 2803 |
+
|
| 2804 |
+
``` cpp
|
| 2805 |
+
template <class T> constexpr bool operator<(nullopt_t, const optional<T>& x) noexcept;
|
| 2806 |
+
```
|
| 2807 |
+
|
| 2808 |
+
*Returns:* `bool(x)`.
|
| 2809 |
+
|
| 2810 |
+
``` cpp
|
| 2811 |
+
template <class T> constexpr bool operator<=(const optional<T>& x, nullopt_t) noexcept;
|
| 2812 |
+
```
|
| 2813 |
+
|
| 2814 |
+
*Returns:* `!x`.
|
| 2815 |
+
|
| 2816 |
+
``` cpp
|
| 2817 |
+
template <class T> constexpr bool operator<=(nullopt_t, const optional<T>& x) noexcept;
|
| 2818 |
+
```
|
| 2819 |
+
|
| 2820 |
+
*Returns:* `true`.
|
| 2821 |
+
|
| 2822 |
+
``` cpp
|
| 2823 |
+
template <class T> constexpr bool operator>(const optional<T>& x, nullopt_t) noexcept;
|
| 2824 |
+
```
|
| 2825 |
+
|
| 2826 |
+
*Returns:* `bool(x)`.
|
| 2827 |
+
|
| 2828 |
+
``` cpp
|
| 2829 |
+
template <class T> constexpr bool operator>(nullopt_t, const optional<T>& x) noexcept;
|
| 2830 |
+
```
|
| 2831 |
+
|
| 2832 |
+
*Returns:* `false`.
|
| 2833 |
+
|
| 2834 |
+
``` cpp
|
| 2835 |
+
template <class T> constexpr bool operator>=(const optional<T>& x, nullopt_t) noexcept;
|
| 2836 |
+
```
|
| 2837 |
+
|
| 2838 |
+
*Returns:* `true`.
|
| 2839 |
+
|
| 2840 |
+
``` cpp
|
| 2841 |
+
template <class T> constexpr bool operator>=(nullopt_t, const optional<T>& x) noexcept;
|
| 2842 |
+
```
|
| 2843 |
+
|
| 2844 |
+
*Returns:* `!x`.
|
| 2845 |
+
|
| 2846 |
+
### Comparison with `T` <a id="optional.comp_with_t">[[optional.comp_with_t]]</a>
|
| 2847 |
+
|
| 2848 |
+
``` cpp
|
| 2849 |
+
template <class T, class U> constexpr bool operator==(const optional<T>& x, const U& v);
|
| 2850 |
+
```
|
| 2851 |
+
|
| 2852 |
+
*Requires:* The expression `*x == v` shall be well-formed and its result
|
| 2853 |
+
shall be convertible to `bool`.
|
| 2854 |
+
|
| 2855 |
+
[*Note 1*: `T` need not be `EqualityComparable`. — *end note*]
|
| 2856 |
+
|
| 2857 |
+
*Effects:* Equivalent to: `return bool(x) ? *x == v : false;`
|
| 2858 |
+
|
| 2859 |
+
``` cpp
|
| 2860 |
+
template <class T, class U> constexpr bool operator==(const U& v, const optional<T>& x);
|
| 2861 |
+
```
|
| 2862 |
+
|
| 2863 |
+
*Requires:* The expression `v == *x` shall be well-formed and its result
|
| 2864 |
+
shall be convertible to `bool`.
|
| 2865 |
+
|
| 2866 |
+
*Effects:* Equivalent to: `return bool(x) ? v == *x : false;`
|
| 2867 |
+
|
| 2868 |
+
``` cpp
|
| 2869 |
+
template <class T, class U> constexpr bool operator!=(const optional<T>& x, const U& v);
|
| 2870 |
+
```
|
| 2871 |
+
|
| 2872 |
+
*Requires:* The expression `*x != v` shall be well-formed and its result
|
| 2873 |
+
shall be convertible to `bool`.
|
| 2874 |
+
|
| 2875 |
+
*Effects:* Equivalent to: `return bool(x) ? *x != v : true;`
|
| 2876 |
+
|
| 2877 |
+
``` cpp
|
| 2878 |
+
template <class T, class U> constexpr bool operator!=(const U& v, const optional<T>& x);
|
| 2879 |
+
```
|
| 2880 |
+
|
| 2881 |
+
*Requires:* The expression `v != *x` shall be well-formed and its result
|
| 2882 |
+
shall be convertible to `bool`.
|
| 2883 |
+
|
| 2884 |
+
*Effects:* Equivalent to: `return bool(x) ? v != *x : true;`
|
| 2885 |
+
|
| 2886 |
+
``` cpp
|
| 2887 |
+
template <class T, class U> constexpr bool operator<(const optional<T>& x, const U& v);
|
| 2888 |
+
```
|
| 2889 |
+
|
| 2890 |
+
*Requires:* The expression `*x < v` shall be well-formed and its result
|
| 2891 |
+
shall be convertible to `bool`.
|
| 2892 |
+
|
| 2893 |
+
*Effects:* Equivalent to: `return bool(x) ? *x < v : true;`
|
| 2894 |
+
|
| 2895 |
+
``` cpp
|
| 2896 |
+
template <class T, class U> constexpr bool operator<(const U& v, const optional<T>& x);
|
| 2897 |
+
```
|
| 2898 |
+
|
| 2899 |
+
*Requires:* The expression `v < *x` shall be well-formed and its result
|
| 2900 |
+
shall be convertible to `bool`.
|
| 2901 |
+
|
| 2902 |
+
*Effects:* Equivalent to: `return bool(x) ? v < *x : false;`
|
| 2903 |
+
|
| 2904 |
+
``` cpp
|
| 2905 |
+
template <class T, class U> constexpr bool operator<=(const optional<T>& x, const U& v);
|
| 2906 |
+
```
|
| 2907 |
+
|
| 2908 |
+
*Requires:* The expression `*x <= v` shall be well-formed and its result
|
| 2909 |
+
shall be convertible to `bool`.
|
| 2910 |
+
|
| 2911 |
+
*Effects:* Equivalent to: `return bool(x) ? *x <= v : true;`
|
| 2912 |
+
|
| 2913 |
+
``` cpp
|
| 2914 |
+
template <class T, class U> constexpr bool operator<=(const U& v, const optional<T>& x);
|
| 2915 |
+
```
|
| 2916 |
+
|
| 2917 |
+
*Requires:* The expression `v <= *x` shall be well-formed and its result
|
| 2918 |
+
shall be convertible to `bool`.
|
| 2919 |
+
|
| 2920 |
+
*Effects:* Equivalent to: `return bool(x) ? v <= *x : false;`
|
| 2921 |
+
|
| 2922 |
+
``` cpp
|
| 2923 |
+
template <class T, class U> constexpr bool operator>(const optional<T>& x, const U& v);
|
| 2924 |
+
```
|
| 2925 |
+
|
| 2926 |
+
*Requires:* The expression `*x > v` shall be well-formed and its result
|
| 2927 |
+
shall be convertible to `bool`.
|
| 2928 |
+
|
| 2929 |
+
*Effects:* Equivalent to: `return bool(x) ? *x > v : false;`
|
| 2930 |
+
|
| 2931 |
+
``` cpp
|
| 2932 |
+
template <class T, class U> constexpr bool operator>(const U& v, const optional<T>& x);
|
| 2933 |
+
```
|
| 2934 |
+
|
| 2935 |
+
*Requires:* The expression `v > *x` shall be well-formed and its result
|
| 2936 |
+
shall be convertible to `bool`.
|
| 2937 |
+
|
| 2938 |
+
*Effects:* Equivalent to: `return bool(x) ? v > *x : true;`
|
| 2939 |
+
|
| 2940 |
+
``` cpp
|
| 2941 |
+
template <class T, class U> constexpr bool operator>=(const optional<T>& x, const U& v);
|
| 2942 |
+
```
|
| 2943 |
+
|
| 2944 |
+
*Requires:* The expression `*x >= v` shall be well-formed and its result
|
| 2945 |
+
shall be convertible to `bool`.
|
| 2946 |
+
|
| 2947 |
+
*Effects:* Equivalent to: `return bool(x) ? *x >= v : false;`
|
| 2948 |
+
|
| 2949 |
+
``` cpp
|
| 2950 |
+
template <class T, class U> constexpr bool operator>=(const U& v, const optional<T>& x);
|
| 2951 |
+
```
|
| 2952 |
+
|
| 2953 |
+
*Requires:* The expression `v >= *x` shall be well-formed and its result
|
| 2954 |
+
shall be convertible to `bool`.
|
| 2955 |
+
|
| 2956 |
+
*Effects:* Equivalent to: `return bool(x) ? v >= *x : true;`
|
| 2957 |
+
|
| 2958 |
+
### Specialized algorithms <a id="optional.specalg">[[optional.specalg]]</a>
|
| 2959 |
+
|
| 2960 |
+
``` cpp
|
| 2961 |
+
template <class T> void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y)));
|
| 2962 |
+
```
|
| 2963 |
+
|
| 2964 |
+
*Effects:* Calls `x.swap(y)`.
|
| 2965 |
+
|
| 2966 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 2967 |
+
unless `is_move_constructible_v<T>` is `true` and `is_swappable_v<T>` is
|
| 2968 |
+
`true`.
|
| 2969 |
+
|
| 2970 |
+
``` cpp
|
| 2971 |
+
template <class T> constexpr optional<decay_t<T>> make_optional(T&& v);
|
| 2972 |
+
```
|
| 2973 |
+
|
| 2974 |
+
*Returns:* `optional<decay_t<T>>(std::forward<T>(v))`.
|
| 2975 |
+
|
| 2976 |
+
``` cpp
|
| 2977 |
+
template <class T, class...Args>
|
| 2978 |
+
constexpr optional<T> make_optional(Args&&... args);
|
| 2979 |
+
```
|
| 2980 |
+
|
| 2981 |
+
*Effects:* Equivalent to:
|
| 2982 |
+
`return optional<T>(in_place, std::forward<Args>(args)...);`
|
| 2983 |
+
|
| 2984 |
+
``` cpp
|
| 2985 |
+
template <class T, class U, class... Args>
|
| 2986 |
+
constexpr optional<T> make_optional(initializer_list<U> il, Args&&... args);
|
| 2987 |
+
```
|
| 2988 |
+
|
| 2989 |
+
*Effects:* Equivalent to:
|
| 2990 |
+
`return optional<T>(in_place, il, std::forward<Args>(args)...);`
|
| 2991 |
+
|
| 2992 |
+
### Hash support <a id="optional.hash">[[optional.hash]]</a>
|
| 2993 |
+
|
| 2994 |
+
``` cpp
|
| 2995 |
+
template <class T> struct hash<optional<T>>;
|
| 2996 |
+
```
|
| 2997 |
+
|
| 2998 |
+
The specialization `hash<optional<T>>` is enabled ([[unord.hash]]) if
|
| 2999 |
+
and only if `hash<remove_const_t<T>>` is enabled. When enabled, for an
|
| 3000 |
+
object `o` of type `optional<T>`, if `bool(o) == true`, then
|
| 3001 |
+
`hash<optional<T>>()(o)` shall evaluate to the same value as
|
| 3002 |
+
`hash<remove_const_t<T>>()(*o)`; otherwise it evaluates to an
|
| 3003 |
+
unspecified value. The member functions are not guaranteed to be
|
| 3004 |
+
`noexcept`.
|
| 3005 |
+
|
| 3006 |
+
## Variants <a id="variant">[[variant]]</a>
|
| 3007 |
+
|
| 3008 |
+
### In general <a id="variant.general">[[variant.general]]</a>
|
| 3009 |
+
|
| 3010 |
+
A variant object holds and manages the lifetime of a value. If the
|
| 3011 |
+
`variant` holds a value, that value’s type has to be one of the template
|
| 3012 |
+
argument types given to variant. These template arguments are called
|
| 3013 |
+
alternatives.
|
| 3014 |
+
|
| 3015 |
+
### Header `<variant>` synopsis <a id="variant.syn">[[variant.syn]]</a>
|
| 3016 |
+
|
| 3017 |
+
``` cpp
|
| 3018 |
+
namespace std {
|
| 3019 |
+
// [variant.variant], class template variant
|
| 3020 |
+
template <class... Types>
|
| 3021 |
+
class variant;
|
| 3022 |
+
|
| 3023 |
+
// [variant.helper], variant helper classes
|
| 3024 |
+
template <class T> struct variant_size; // not defined
|
| 3025 |
+
template <class T> struct variant_size<const T>;
|
| 3026 |
+
template <class T> struct variant_size<volatile T>;
|
| 3027 |
+
template <class T> struct variant_size<const volatile T>;
|
| 3028 |
+
template <class T>
|
| 3029 |
+
inline constexpr size_t variant_size_v = variant_size<T>::value;
|
| 3030 |
+
|
| 3031 |
+
template <class... Types>
|
| 3032 |
+
struct variant_size<variant<Types...>>;
|
| 3033 |
+
|
| 3034 |
+
template <size_t I, class T> struct variant_alternative; // not defined
|
| 3035 |
+
template <size_t I, class T> struct variant_alternative<I, const T>;
|
| 3036 |
+
template <size_t I, class T> struct variant_alternative<I, volatile T>;
|
| 3037 |
+
template <size_t I, class T> struct variant_alternative<I, const volatile T>;
|
| 3038 |
+
template <size_t I, class T>
|
| 3039 |
+
using variant_alternative_t = typename variant_alternative<I, T>::type;
|
| 3040 |
+
|
| 3041 |
+
template <size_t I, class... Types>
|
| 3042 |
+
struct variant_alternative<I, variant<Types...>>;
|
| 3043 |
+
|
| 3044 |
+
inline constexpr size_t variant_npos = -1;
|
| 3045 |
+
|
| 3046 |
+
// [variant.get], value access
|
| 3047 |
+
template <class T, class... Types>
|
| 3048 |
+
constexpr bool holds_alternative(const variant<Types...>&) noexcept;
|
| 3049 |
+
|
| 3050 |
+
template <size_t I, class... Types>
|
| 3051 |
+
constexpr variant_alternative_t<I, variant<Types...>>& get(variant<Types...>&);
|
| 3052 |
+
template <size_t I, class... Types>
|
| 3053 |
+
constexpr variant_alternative_t<I, variant<Types...>>&& get(variant<Types...>&&);
|
| 3054 |
+
template <size_t I, class... Types>
|
| 3055 |
+
constexpr const variant_alternative_t<I, variant<Types...>>& get(const variant<Types...>&);
|
| 3056 |
+
template <size_t I, class... Types>
|
| 3057 |
+
constexpr const variant_alternative_t<I, variant<Types...>>&& get(const variant<Types...>&&);
|
| 3058 |
+
|
| 3059 |
+
template <class T, class... Types>
|
| 3060 |
+
constexpr T& get(variant<Types...>&);
|
| 3061 |
+
template <class T, class... Types>
|
| 3062 |
+
constexpr T&& get(variant<Types...>&&);
|
| 3063 |
+
template <class T, class... Types>
|
| 3064 |
+
constexpr const T& get(const variant<Types...>&);
|
| 3065 |
+
template <class T, class... Types>
|
| 3066 |
+
constexpr const T&& get(const variant<Types...>&&);
|
| 3067 |
+
|
| 3068 |
+
template <size_t I, class... Types>
|
| 3069 |
+
constexpr add_pointer_t<variant_alternative_t<I, variant<Types...>>>
|
| 3070 |
+
get_if(variant<Types...>*) noexcept;
|
| 3071 |
+
template <size_t I, class... Types>
|
| 3072 |
+
constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...>>>
|
| 3073 |
+
get_if(const variant<Types...>*) noexcept;
|
| 3074 |
+
|
| 3075 |
+
template <class T, class... Types>
|
| 3076 |
+
constexpr add_pointer_t<T>
|
| 3077 |
+
get_if(variant<Types...>*) noexcept;
|
| 3078 |
+
template <class T, class... Types>
|
| 3079 |
+
constexpr add_pointer_t<const T>
|
| 3080 |
+
get_if(const variant<Types...>*) noexcept;
|
| 3081 |
+
|
| 3082 |
+
// [variant.relops], relational operators
|
| 3083 |
+
template <class... Types>
|
| 3084 |
+
constexpr bool operator==(const variant<Types...>&, const variant<Types...>&);
|
| 3085 |
+
template <class... Types>
|
| 3086 |
+
constexpr bool operator!=(const variant<Types...>&, const variant<Types...>&);
|
| 3087 |
+
template <class... Types>
|
| 3088 |
+
constexpr bool operator<(const variant<Types...>&, const variant<Types...>&);
|
| 3089 |
+
template <class... Types>
|
| 3090 |
+
constexpr bool operator>(const variant<Types...>&, const variant<Types...>&);
|
| 3091 |
+
template <class... Types>
|
| 3092 |
+
constexpr bool operator<=(const variant<Types...>&, const variant<Types...>&);
|
| 3093 |
+
template <class... Types>
|
| 3094 |
+
constexpr bool operator>=(const variant<Types...>&, const variant<Types...>&);
|
| 3095 |
+
|
| 3096 |
+
// [variant.visit], visitation
|
| 3097 |
+
template <class Visitor, class... Variants>
|
| 3098 |
+
constexpr see below visit(Visitor&&, Variants&&...);
|
| 3099 |
+
|
| 3100 |
+
// [variant.monostate], class monostate
|
| 3101 |
+
struct monostate;
|
| 3102 |
+
|
| 3103 |
+
// [variant.monostate.relops], monostate relational operators
|
| 3104 |
+
constexpr bool operator<(monostate, monostate) noexcept;
|
| 3105 |
+
constexpr bool operator>(monostate, monostate) noexcept;
|
| 3106 |
+
constexpr bool operator<=(monostate, monostate) noexcept;
|
| 3107 |
+
constexpr bool operator>=(monostate, monostate) noexcept;
|
| 3108 |
+
constexpr bool operator==(monostate, monostate) noexcept;
|
| 3109 |
+
constexpr bool operator!=(monostate, monostate) noexcept;
|
| 3110 |
+
|
| 3111 |
+
// [variant.specalg], specialized algorithms
|
| 3112 |
+
template <class... Types>
|
| 3113 |
+
void swap(variant<Types...>&, variant<Types...>&) noexcept(see below);
|
| 3114 |
+
|
| 3115 |
+
// [variant.bad.access], class bad_variant_access
|
| 3116 |
+
class bad_variant_access;
|
| 3117 |
+
|
| 3118 |
+
// [variant.hash], hash support
|
| 3119 |
+
template <class T> struct hash;
|
| 3120 |
+
template <class... Types> struct hash<variant<Types...>>;
|
| 3121 |
+
template <> struct hash<monostate>;
|
| 3122 |
+
|
| 3123 |
+
// [variant.traits], allocator-related traits
|
| 3124 |
+
template <class T, class Alloc> struct uses_allocator;
|
| 3125 |
+
template <class... Types, class Alloc> struct uses_allocator<variant<Types...>, Alloc>;
|
| 3126 |
+
}
|
| 3127 |
+
```
|
| 3128 |
+
|
| 3129 |
+
### Class template `variant` <a id="variant.variant">[[variant.variant]]</a>
|
| 3130 |
+
|
| 3131 |
+
``` cpp
|
| 3132 |
+
namespace std {
|
| 3133 |
+
template <class... Types>
|
| 3134 |
+
class variant {
|
| 3135 |
+
public:
|
| 3136 |
+
// [variant.ctor], constructors
|
| 3137 |
+
constexpr variant() noexcept(see below);
|
| 3138 |
+
variant(const variant&);
|
| 3139 |
+
variant(variant&&) noexcept(see below);
|
| 3140 |
+
|
| 3141 |
+
template <class T>
|
| 3142 |
+
constexpr variant(T&&) noexcept(see below);
|
| 3143 |
+
|
| 3144 |
+
template <class T, class... Args>
|
| 3145 |
+
constexpr explicit variant(in_place_type_t<T>, Args&&...);
|
| 3146 |
+
template <class T, class U, class... Args>
|
| 3147 |
+
constexpr explicit variant(in_place_type_t<T>, initializer_list<U>, Args&&...);
|
| 3148 |
+
|
| 3149 |
+
template <size_t I, class... Args>
|
| 3150 |
+
constexpr explicit variant(in_place_index_t<I>, Args&&...);
|
| 3151 |
+
template <size_t I, class U, class... Args>
|
| 3152 |
+
constexpr explicit variant(in_place_index_t<I>, initializer_list<U>, Args&&...);
|
| 3153 |
+
|
| 3154 |
+
// allocator-extended constructors
|
| 3155 |
+
template <class Alloc>
|
| 3156 |
+
variant(allocator_arg_t, const Alloc&);
|
| 3157 |
+
template <class Alloc>
|
| 3158 |
+
variant(allocator_arg_t, const Alloc&, const variant&);
|
| 3159 |
+
template <class Alloc>
|
| 3160 |
+
variant(allocator_arg_t, const Alloc&, variant&&);
|
| 3161 |
+
template <class Alloc, class T>
|
| 3162 |
+
variant(allocator_arg_t, const Alloc&, T&&);
|
| 3163 |
+
template <class Alloc, class T, class... Args>
|
| 3164 |
+
variant(allocator_arg_t, const Alloc&, in_place_type_t<T>, Args&&...);
|
| 3165 |
+
template <class Alloc, class T, class U, class... Args>
|
| 3166 |
+
variant(allocator_arg_t, const Alloc&, in_place_type_t<T>,
|
| 3167 |
+
initializer_list<U>, Args&&...);
|
| 3168 |
+
template <class Alloc, size_t I, class... Args>
|
| 3169 |
+
variant(allocator_arg_t, const Alloc&, in_place_index_t<I>, Args&&...);
|
| 3170 |
+
template <class Alloc, size_t I, class U, class... Args>
|
| 3171 |
+
variant(allocator_arg_t, const Alloc&, in_place_index_t<I>,
|
| 3172 |
+
initializer_list<U>, Args&&...);
|
| 3173 |
+
|
| 3174 |
+
// [variant.dtor], destructor
|
| 3175 |
+
~variant();
|
| 3176 |
+
|
| 3177 |
+
// [variant.assign], assignment
|
| 3178 |
+
variant& operator=(const variant&);
|
| 3179 |
+
variant& operator=(variant&&) noexcept(see below);
|
| 3180 |
+
|
| 3181 |
+
template <class T> variant& operator=(T&&) noexcept(see below);
|
| 3182 |
+
|
| 3183 |
+
// [variant.mod], modifiers
|
| 3184 |
+
template <class T, class... Args>
|
| 3185 |
+
T& emplace(Args&&...);
|
| 3186 |
+
template <class T, class U, class... Args>
|
| 3187 |
+
T& emplace(initializer_list<U>, Args&&...);
|
| 3188 |
+
template <size_t I, class... Args>
|
| 3189 |
+
variant_alternative_t<I, variant<Types...>>& emplace(Args&&...);
|
| 3190 |
+
template <size_t I, class U, class... Args>
|
| 3191 |
+
variant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U>, Args&&...);
|
| 3192 |
+
|
| 3193 |
+
// [variant.status], value status
|
| 3194 |
+
constexpr bool valueless_by_exception() const noexcept;
|
| 3195 |
+
constexpr size_t index() const noexcept;
|
| 3196 |
+
|
| 3197 |
+
// [variant.swap], swap
|
| 3198 |
+
void swap(variant&) noexcept(see below);
|
| 3199 |
+
};
|
| 3200 |
+
}
|
| 3201 |
+
```
|
| 3202 |
+
|
| 3203 |
+
Any instance of `variant` at any given time either holds a value of one
|
| 3204 |
+
of its alternative types, or it holds no value. When an instance of
|
| 3205 |
+
`variant` holds a value of alternative type `T`, it means that a value
|
| 3206 |
+
of type `T`, referred to as the `variant` object’s *contained value*, is
|
| 3207 |
+
allocated within the storage of the `variant` object. Implementations
|
| 3208 |
+
are not permitted to use additional storage, such as dynamic memory, to
|
| 3209 |
+
allocate the contained value. The contained value shall be allocated in
|
| 3210 |
+
a region of the `variant` storage suitably aligned for all types in
|
| 3211 |
+
`Types...`. It is *implementation-defined* whether over-aligned types
|
| 3212 |
+
are supported.
|
| 3213 |
+
|
| 3214 |
+
All types in `Types...` shall be (possibly cv-qualified) object types
|
| 3215 |
+
that are not arrays.
|
| 3216 |
+
|
| 3217 |
+
A program that instantiates the definition of `variant` with no template
|
| 3218 |
+
arguments is ill-formed.
|
| 3219 |
+
|
| 3220 |
+
#### Constructors <a id="variant.ctor">[[variant.ctor]]</a>
|
| 3221 |
+
|
| 3222 |
+
In the descriptions that follow, let i be in the range \[`0`,
|
| 3223 |
+
`sizeof...(Types)`), and `Tᵢ` be the iᵗʰ type in `Types...`.
|
| 3224 |
+
|
| 3225 |
+
``` cpp
|
| 3226 |
+
constexpr variant() noexcept(see below);
|
| 3227 |
+
```
|
| 3228 |
+
|
| 3229 |
+
*Effects:* Constructs a `variant` holding a value-initialized value of
|
| 3230 |
+
type `T₀`.
|
| 3231 |
+
|
| 3232 |
+
*Postconditions:* `valueless_by_exception()` is `false` and `index()` is
|
| 3233 |
+
`0`.
|
| 3234 |
+
|
| 3235 |
+
*Throws:* Any exception thrown by the value-initialization of `T₀`.
|
| 3236 |
+
|
| 3237 |
+
*Remarks:* This function shall be `constexpr` if and only if the
|
| 3238 |
+
value-initialization of the alternative type `T₀` would satisfy the
|
| 3239 |
+
requirements for a constexpr function. The expression inside `noexcept`
|
| 3240 |
+
is equivalent to `is_nothrow_default_constructible_v<``T₀``>`. This
|
| 3241 |
+
function shall not participate in overload resolution unless
|
| 3242 |
+
`is_default_constructible_v<``T₀``>` is `true`.
|
| 3243 |
+
|
| 3244 |
+
[*Note 1*: See also class `monostate`. — *end note*]
|
| 3245 |
+
|
| 3246 |
+
``` cpp
|
| 3247 |
+
variant(const variant& w);
|
| 3248 |
+
```
|
| 3249 |
+
|
| 3250 |
+
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 3251 |
+
same alternative as `w` and direct-initializes the contained value with
|
| 3252 |
+
`get<j>(w)`, where `j` is `w.index()`. Otherwise, initializes the
|
| 3253 |
+
`variant` to not hold a value.
|
| 3254 |
+
|
| 3255 |
+
*Throws:* Any exception thrown by direct-initializing any `Tᵢ` for all
|
| 3256 |
+
i.
|
| 3257 |
+
|
| 3258 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3259 |
+
unless `is_copy_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 3260 |
+
|
| 3261 |
+
``` cpp
|
| 3262 |
+
variant(variant&& w) noexcept(see below);
|
| 3263 |
+
```
|
| 3264 |
+
|
| 3265 |
+
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 3266 |
+
same alternative as `w` and direct-initializes the contained value with
|
| 3267 |
+
`get<j>(std::move(w))`, where `j` is `w.index()`. Otherwise, initializes
|
| 3268 |
+
the `variant` to not hold a value.
|
| 3269 |
+
|
| 3270 |
+
*Throws:* Any exception thrown by move-constructing any `Tᵢ` for all i.
|
| 3271 |
+
|
| 3272 |
+
*Remarks:* The expression inside `noexcept` is equivalent to the logical
|
| 3273 |
+
AND of `is_nothrow_move_constructible_v<``Tᵢ``>` for all i. This
|
| 3274 |
+
function shall not participate in overload resolution unless
|
| 3275 |
+
`is_move_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 3276 |
+
|
| 3277 |
+
``` cpp
|
| 3278 |
+
template <class T> constexpr variant(T&& t) noexcept(see below);
|
| 3279 |
+
```
|
| 3280 |
+
|
| 3281 |
+
Let `Tⱼ` be a type that is determined as follows: build an imaginary
|
| 3282 |
+
function *FUN*(Tᵢ) for each alternative type `Tᵢ`. The overload
|
| 3283 |
+
*FUN*(Tⱼ) selected by overload resolution for the expression
|
| 3284 |
+
*FUN*(std::forward\<T\>(t)) defines the alternative `Tⱼ` which is the
|
| 3285 |
+
type of the contained value after construction.
|
| 3286 |
+
|
| 3287 |
+
*Effects:* Initializes `*this` to hold the alternative type `Tⱼ` and
|
| 3288 |
+
direct-initializes the contained value as if
|
| 3289 |
+
direct-non-list-initializing it with `std::forward<T>(t)`.
|
| 3290 |
+
|
| 3291 |
+
*Postconditions:* `holds_alternative<``Tⱼ``>(*this)` is `true`.
|
| 3292 |
+
|
| 3293 |
+
*Throws:* Any exception thrown by the initialization of the selected
|
| 3294 |
+
alternative `Tⱼ`.
|
| 3295 |
+
|
| 3296 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3297 |
+
unless `is_same_v<decay_t<T>, variant>` is `false`, unless `decay_t<T>`
|
| 3298 |
+
is neither a specialization of `in_place_type_t` nor a specialization of
|
| 3299 |
+
`in_place_index_t`, unless `is_constructible_v<``Tⱼ``, T>` is `true`,
|
| 3300 |
+
and unless the expression *FUN*(`std::forward<T>(t))` (with *FUN* being
|
| 3301 |
+
the above-mentioned set of imaginary functions) is well formed.
|
| 3302 |
+
|
| 3303 |
+
[*Note 2*:
|
| 3304 |
+
|
| 3305 |
+
``` cpp
|
| 3306 |
+
variant<string, string> v("abc");
|
| 3307 |
+
```
|
| 3308 |
+
|
| 3309 |
+
is ill-formed, as both alternative types have an equally viable
|
| 3310 |
+
constructor for the argument.
|
| 3311 |
+
|
| 3312 |
+
— *end note*]
|
| 3313 |
+
|
| 3314 |
+
The expression inside `noexcept` is equivalent to
|
| 3315 |
+
`is_nothrow_constructible_v<``Tⱼ``, T>`. If `Tⱼ`’s selected constructor
|
| 3316 |
+
is a constexpr constructor, this constructor shall be a constexpr
|
| 3317 |
+
constructor.
|
| 3318 |
+
|
| 3319 |
+
``` cpp
|
| 3320 |
+
template <class T, class... Args> constexpr explicit variant(in_place_type_t<T>, Args&&... args);
|
| 3321 |
+
```
|
| 3322 |
+
|
| 3323 |
+
*Effects:* Initializes the contained value as if
|
| 3324 |
+
direct-non-list-initializing an object of type `T` with the arguments
|
| 3325 |
+
`std::forward<Args>(args)...`.
|
| 3326 |
+
|
| 3327 |
+
*Postconditions:* `holds_alternative<T>(*this)` is `true`.
|
| 3328 |
+
|
| 3329 |
+
*Throws:* Any exception thrown by calling the selected constructor of
|
| 3330 |
+
`T`.
|
| 3331 |
+
|
| 3332 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3333 |
+
unless there is exactly one occurrence of `T` in `Types...` and
|
| 3334 |
+
`is_constructible_v<T, Args...>` is `true`. If `T`’s selected
|
| 3335 |
+
constructor is a constexpr constructor, this constructor shall be a
|
| 3336 |
+
constexpr constructor.
|
| 3337 |
+
|
| 3338 |
+
``` cpp
|
| 3339 |
+
template <class T, class U, class... Args>
|
| 3340 |
+
constexpr explicit variant(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
|
| 3341 |
+
```
|
| 3342 |
+
|
| 3343 |
+
*Effects:* Initializes the contained value as if
|
| 3344 |
+
direct-non-list-initializing an object of type `T` with the arguments
|
| 3345 |
+
`il, std::forward<Args>(args)...`.
|
| 3346 |
+
|
| 3347 |
+
*Postconditions:* `holds_alternative<T>(*this)` is `true`.
|
| 3348 |
+
|
| 3349 |
+
*Throws:* Any exception thrown by calling the selected constructor of
|
| 3350 |
+
`T`.
|
| 3351 |
+
|
| 3352 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3353 |
+
unless there is exactly one occurrence of `T` in `Types...` and
|
| 3354 |
+
`is_constructible_v<T, initializer_list<U>&, Args...>` is `true`. If
|
| 3355 |
+
`T`’s selected constructor is a constexpr constructor, this constructor
|
| 3356 |
+
shall be a constexpr constructor.
|
| 3357 |
+
|
| 3358 |
+
``` cpp
|
| 3359 |
+
template <size_t I, class... Args> constexpr explicit variant(in_place_index_t<I>, Args&&... args);
|
| 3360 |
+
```
|
| 3361 |
+
|
| 3362 |
+
*Effects:* Initializes the contained value as if
|
| 3363 |
+
direct-non-list-initializing an object of type `T_I` with the arguments
|
| 3364 |
+
`std::forward<Args>(args)...`.
|
| 3365 |
+
|
| 3366 |
+
*Postconditions:* `index()` is `I`.
|
| 3367 |
+
|
| 3368 |
+
*Throws:* Any exception thrown by calling the selected constructor of
|
| 3369 |
+
`T_I`.
|
| 3370 |
+
|
| 3371 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3372 |
+
unless
|
| 3373 |
+
|
| 3374 |
+
- `I` is less than `sizeof...(Types)` and
|
| 3375 |
+
- `is_constructible_v<``T_I``, Args...>` is `true`.
|
| 3376 |
+
|
| 3377 |
+
If `T_I`’s selected constructor is a constexpr constructor, this
|
| 3378 |
+
constructor shall be a constexpr constructor.
|
| 3379 |
+
|
| 3380 |
+
``` cpp
|
| 3381 |
+
template <size_t I, class U, class... Args>
|
| 3382 |
+
constexpr explicit variant(in_place_index_t<I>, initializer_list<U> il, Args&&... args);
|
| 3383 |
+
```
|
| 3384 |
+
|
| 3385 |
+
*Effects:* Initializes the contained value as if
|
| 3386 |
+
direct-non-list-initializing an object of type `T_I` with the arguments
|
| 3387 |
+
`il, std::forward<Args>(args)...`.
|
| 3388 |
+
|
| 3389 |
+
*Postconditions:* `index()` is `I`.
|
| 3390 |
+
|
| 3391 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3392 |
+
unless
|
| 3393 |
+
|
| 3394 |
+
- `I` is less than `sizeof...(Types)` and
|
| 3395 |
+
- `is_constructible_v<``T_I``, initializer_list<U>&, Args...>` is
|
| 3396 |
+
`true`.
|
| 3397 |
+
|
| 3398 |
+
If `T_I`’s selected constructor is a constexpr constructor, this
|
| 3399 |
+
constructor shall be a constexpr constructor.
|
| 3400 |
+
|
| 3401 |
+
``` cpp
|
| 3402 |
+
// allocator-extended constructors
|
| 3403 |
+
template <class Alloc>
|
| 3404 |
+
variant(allocator_arg_t, const Alloc& a);
|
| 3405 |
+
template <class Alloc>
|
| 3406 |
+
variant(allocator_arg_t, const Alloc& a, const variant& v);
|
| 3407 |
+
template <class Alloc>
|
| 3408 |
+
variant(allocator_arg_t, const Alloc& a, variant&& v);
|
| 3409 |
+
template <class Alloc, class T>
|
| 3410 |
+
variant(allocator_arg_t, const Alloc& a, T&& t);
|
| 3411 |
+
template <class Alloc, class T, class... Args>
|
| 3412 |
+
variant(allocator_arg_t, const Alloc& a, in_place_type_t<T>, Args&&... args);
|
| 3413 |
+
template <class Alloc, class T, class U, class... Args>
|
| 3414 |
+
variant(allocator_arg_t, const Alloc& a, in_place_type_t<T>,
|
| 3415 |
+
initializer_list<U> il, Args&&... args);
|
| 3416 |
+
template <class Alloc, size_t I, class... Args>
|
| 3417 |
+
variant(allocator_arg_t, const Alloc& a, in_place_index_t<I>, Args&&... args);
|
| 3418 |
+
template <class Alloc, size_t I, class U, class... Args>
|
| 3419 |
+
variant(allocator_arg_t, const Alloc& a, in_place_index_t<I>,
|
| 3420 |
+
initializer_list<U> il, Args&&... args);
|
| 3421 |
+
```
|
| 3422 |
+
|
| 3423 |
+
*Requires:* `Alloc` shall meet the requirements for an
|
| 3424 |
+
Allocator ([[allocator.requirements]]).
|
| 3425 |
+
|
| 3426 |
+
*Effects:* Equivalent to the preceding constructors except that the
|
| 3427 |
+
contained value is constructed with uses-allocator
|
| 3428 |
+
construction ([[allocator.uses.construction]]).
|
| 3429 |
+
|
| 3430 |
+
#### Destructor <a id="variant.dtor">[[variant.dtor]]</a>
|
| 3431 |
+
|
| 3432 |
+
``` cpp
|
| 3433 |
+
~variant();
|
| 3434 |
+
```
|
| 3435 |
+
|
| 3436 |
+
*Effects:* If `valueless_by_exception()` is `false`, destroys the
|
| 3437 |
+
currently contained value.
|
| 3438 |
+
|
| 3439 |
+
*Remarks:* If `is_trivially_destructible_v<``Tᵢ``> == true` for all `Tᵢ`
|
| 3440 |
+
then this destructor shall be a trivial destructor.
|
| 3441 |
+
|
| 3442 |
+
#### Assignment <a id="variant.assign">[[variant.assign]]</a>
|
| 3443 |
+
|
| 3444 |
+
``` cpp
|
| 3445 |
+
variant& operator=(const variant& rhs);
|
| 3446 |
+
```
|
| 3447 |
+
|
| 3448 |
+
Let j be `rhs.index()`.
|
| 3449 |
+
|
| 3450 |
+
*Effects:*
|
| 3451 |
+
|
| 3452 |
+
- If neither `*this` nor `rhs` holds a value, there is no effect.
|
| 3453 |
+
Otherwise,
|
| 3454 |
+
- if `*this` holds a value but `rhs` does not, destroys the value
|
| 3455 |
+
contained in `*this` and sets `*this` to not hold a value. Otherwise,
|
| 3456 |
+
- if `index() == `j, assigns the value contained in `rhs` to the value
|
| 3457 |
+
contained in `*this`. Otherwise,
|
| 3458 |
+
- if either `is_nothrow_copy_constructible_v<``Tⱼ``>` or
|
| 3459 |
+
`!is_nothrow_move_constructible_v<``Tⱼ``>` is `true`, equivalent to
|
| 3460 |
+
`emplace<`j`>(get<`j`>(rhs))`. Otherwise,
|
| 3461 |
+
- equivalent to `operator=(variant(rhs))`.
|
| 3462 |
+
|
| 3463 |
+
*Returns:* `*this`.
|
| 3464 |
+
|
| 3465 |
+
*Postconditions:* `index() == rhs.index()`.
|
| 3466 |
+
|
| 3467 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3468 |
+
unless `is_copy_constructible_v<``Tᵢ``> &&`
|
| 3469 |
+
`is_copy_assignable_v<``Tᵢ``>` is `true` for all i.
|
| 3470 |
+
|
| 3471 |
+
``` cpp
|
| 3472 |
+
variant& operator=(variant&& rhs) noexcept(see below);
|
| 3473 |
+
```
|
| 3474 |
+
|
| 3475 |
+
Let j be `rhs.index()`.
|
| 3476 |
+
|
| 3477 |
+
*Effects:*
|
| 3478 |
+
|
| 3479 |
+
- If neither `*this` nor `rhs` holds a value, there is no effect.
|
| 3480 |
+
Otherwise,
|
| 3481 |
+
- if `*this` holds a value but `rhs` does not, destroys the value
|
| 3482 |
+
contained in `*this` and sets `*this` to not hold a value. Otherwise,
|
| 3483 |
+
- if `index() == `j, assigns `get<`j`>(std::move(rhs))` to the value
|
| 3484 |
+
contained in `*this`. Otherwise,
|
| 3485 |
+
- equivalent to `emplace<`j`>(get<`j`>(std::move(rhs)))`.
|
| 3486 |
+
|
| 3487 |
+
*Returns:* `*this`.
|
| 3488 |
+
|
| 3489 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3490 |
+
unless `is_move_constructible_v<``Tᵢ``> && is_move_assignable_v<``Tᵢ``>`
|
| 3491 |
+
is `true` for all i. The expression inside `noexcept` is equivalent to:
|
| 3492 |
+
`is_nothrow_move_constructible_v<``Tᵢ``> && is_nothrow_move_assignable_v<``Tᵢ``>`
|
| 3493 |
+
for all i.
|
| 3494 |
+
|
| 3495 |
+
- If an exception is thrown during the call to `Tⱼ`’s move construction
|
| 3496 |
+
(with j being `rhs.index())`, the `variant` will hold no value.
|
| 3497 |
+
- If an exception is thrown during the call to `Tⱼ`’s move assignment,
|
| 3498 |
+
the state of the contained value is as defined by the exception safety
|
| 3499 |
+
guarantee of `Tⱼ`’s move assignment; `index()` will be j.
|
| 3500 |
+
|
| 3501 |
+
``` cpp
|
| 3502 |
+
template <class T> variant& operator=(T&& t) noexcept(see below);
|
| 3503 |
+
```
|
| 3504 |
+
|
| 3505 |
+
Let `Tⱼ` be a type that is determined as follows: build an imaginary
|
| 3506 |
+
function *FUN*(Tᵢ) for each alternative type `Tᵢ`. The overload
|
| 3507 |
+
*FUN*(Tⱼ) selected by overload resolution for the expression
|
| 3508 |
+
*FUN*(std::forward\<T\>(t)) defines the alternative `Tⱼ` which is the
|
| 3509 |
+
type of the contained value after assignment.
|
| 3510 |
+
|
| 3511 |
+
*Effects:*
|
| 3512 |
+
|
| 3513 |
+
- If `*this` holds a `Tⱼ`, assigns `std::forward<T>(t)` to the value
|
| 3514 |
+
contained in `*this`. Otherwise,
|
| 3515 |
+
- if `is_nothrow_constructible_v<``Tⱼ``, T> ||`
|
| 3516 |
+
`!is_nothrow_move_constructible_v<``Tⱼ``>` is `true`, equivalent to
|
| 3517 |
+
`emplace<`j`>(std::forward<T>(t))`. Otherwise,
|
| 3518 |
+
- equivalent to `operator=(variant(std::forward<T>(t)))`.
|
| 3519 |
+
|
| 3520 |
+
*Postconditions:* `holds_alternative<``Tⱼ``>(*this)` is `true`, with
|
| 3521 |
+
`Tⱼ` selected by the imaginary function overload resolution described
|
| 3522 |
+
above.
|
| 3523 |
+
|
| 3524 |
+
*Returns:* `*this`.
|
| 3525 |
+
|
| 3526 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3527 |
+
unless `is_same_v<decay_t<T>, variant>` is `false`, unless
|
| 3528 |
+
`is_assignable_v<``Tⱼ``&, T> && is_constructible_v<``Tⱼ``, T>` is
|
| 3529 |
+
`true`, and unless the expression *FUN*(std::forward\<T\>(t)) (with
|
| 3530 |
+
*FUN* being the above-mentioned set of imaginary functions) is well
|
| 3531 |
+
formed.
|
| 3532 |
+
|
| 3533 |
+
[*Note 1*:
|
| 3534 |
+
|
| 3535 |
+
``` cpp
|
| 3536 |
+
variant<string, string> v;
|
| 3537 |
+
v = "abc";
|
| 3538 |
+
```
|
| 3539 |
+
|
| 3540 |
+
is ill-formed, as both alternative types have an equally viable
|
| 3541 |
+
constructor for the argument.
|
| 3542 |
+
|
| 3543 |
+
— *end note*]
|
| 3544 |
+
|
| 3545 |
+
The expression inside `noexcept` is equivalent to:
|
| 3546 |
+
|
| 3547 |
+
``` cpp
|
| 3548 |
+
is_nothrow_assignable_v<Tⱼ&, T> && is_nothrow_constructible_v<Tⱼ, T>
|
| 3549 |
+
```
|
| 3550 |
+
|
| 3551 |
+
- If an exception is thrown during the assignment of
|
| 3552 |
+
`std::forward<T>(t)` to the value contained in `*this`, the state of
|
| 3553 |
+
the contained value and `t` are as defined by the exception safety
|
| 3554 |
+
guarantee of the assignment expression; `valueless_by_exception()`
|
| 3555 |
+
will be `false`.
|
| 3556 |
+
- If an exception is thrown during the initialization of the contained
|
| 3557 |
+
value, the `variant` object might not hold a value.
|
| 3558 |
+
|
| 3559 |
+
#### Modifiers <a id="variant.mod">[[variant.mod]]</a>
|
| 3560 |
+
|
| 3561 |
+
``` cpp
|
| 3562 |
+
template <class T, class... Args> T& emplace(Args&&... args);
|
| 3563 |
+
```
|
| 3564 |
+
|
| 3565 |
+
Let I be the zero-based index of `T` in `Types...`.
|
| 3566 |
+
|
| 3567 |
+
*Effects:* Equivalent to:
|
| 3568 |
+
`return emplace<`I`>(std::forward<Args>(args)...);`
|
| 3569 |
+
|
| 3570 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3571 |
+
unless `is_constructible_v<T, Args...>` is `true`, and `T` occurs
|
| 3572 |
+
exactly once in `Types...`.
|
| 3573 |
+
|
| 3574 |
+
``` cpp
|
| 3575 |
+
template <class T, class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
|
| 3576 |
+
```
|
| 3577 |
+
|
| 3578 |
+
Let I be the zero-based index of `T` in `Types...`.
|
| 3579 |
+
|
| 3580 |
+
*Effects:* Equivalent to:
|
| 3581 |
+
`return emplace<`I`>(il, std::forward<Args>(args)...);`
|
| 3582 |
+
|
| 3583 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3584 |
+
unless `is_constructible_v<T, initializer_list<U>&, Args...>` is `true`,
|
| 3585 |
+
and `T` occurs exactly once in `Types...`.
|
| 3586 |
+
|
| 3587 |
+
``` cpp
|
| 3588 |
+
template <size_t I, class... Args>
|
| 3589 |
+
variant_alternative_t<I, variant<Types...>>& emplace(Args&&... args);
|
| 3590 |
+
```
|
| 3591 |
+
|
| 3592 |
+
*Requires:* `I < sizeof...(Types)`.
|
| 3593 |
+
|
| 3594 |
+
*Effects:* Destroys the currently contained value if
|
| 3595 |
+
`valueless_by_exception()` is `false`. Then initializes the contained
|
| 3596 |
+
value as if direct-non-list-initializing a value of type `T_I` with the
|
| 3597 |
+
arguments `std::forward<Args>(args)...`.
|
| 3598 |
+
|
| 3599 |
+
*Postconditions:* `index()` is `I`.
|
| 3600 |
+
|
| 3601 |
+
*Returns:* A reference to the new contained value.
|
| 3602 |
+
|
| 3603 |
+
*Throws:* Any exception thrown during the initialization of the
|
| 3604 |
+
contained value.
|
| 3605 |
+
|
| 3606 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3607 |
+
unless `is_constructible_v<``T_I``, Args...>` is `true`. If an exception
|
| 3608 |
+
is thrown during the initialization of the contained value, the
|
| 3609 |
+
`variant` might not hold a value.
|
| 3610 |
+
|
| 3611 |
+
``` cpp
|
| 3612 |
+
template <size_t I, class U, class... Args>
|
| 3613 |
+
variant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U> il, Args&&... args);
|
| 3614 |
+
```
|
| 3615 |
+
|
| 3616 |
+
*Requires:* `I < sizeof...(Types)`.
|
| 3617 |
+
|
| 3618 |
+
*Effects:* Destroys the currently contained value if
|
| 3619 |
+
`valueless_by_exception()` is `false`. Then initializes the contained
|
| 3620 |
+
value as if direct-non-list-initializing a value of type `T_I` with the
|
| 3621 |
+
arguments `il, std::forward<Args>(args)...`.
|
| 3622 |
+
|
| 3623 |
+
*Postconditions:* `index()` is `I`.
|
| 3624 |
+
|
| 3625 |
+
*Returns:* A reference to the new contained value.
|
| 3626 |
+
|
| 3627 |
+
*Throws:* Any exception thrown during the initialization of the
|
| 3628 |
+
contained value.
|
| 3629 |
+
|
| 3630 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3631 |
+
unless `is_constructible_v<``T_I``, initializer_list<U>&, Args...>` is
|
| 3632 |
+
`true`. If an exception is thrown during the initialization of the
|
| 3633 |
+
contained value, the `variant` might not hold a value.
|
| 3634 |
+
|
| 3635 |
+
#### Value status <a id="variant.status">[[variant.status]]</a>
|
| 3636 |
+
|
| 3637 |
+
``` cpp
|
| 3638 |
+
constexpr bool valueless_by_exception() const noexcept;
|
| 3639 |
+
```
|
| 3640 |
+
|
| 3641 |
+
*Effects:* Returns `false` if and only if the `variant` holds a value.
|
| 3642 |
+
|
| 3643 |
+
[*Note 1*:
|
| 3644 |
+
|
| 3645 |
+
A `variant` might not hold a value if an exception is thrown during a
|
| 3646 |
+
type-changing assignment or emplacement. The latter means that even a
|
| 3647 |
+
`variant<float, int>` can become `valueless_by_exception()`, for
|
| 3648 |
+
instance by
|
| 3649 |
+
|
| 3650 |
+
``` cpp
|
| 3651 |
+
struct S { operator int() { throw 42; }};
|
| 3652 |
+
variant<float, int> v{12.f};
|
| 3653 |
+
v.emplace<1>(S());
|
| 3654 |
+
```
|
| 3655 |
+
|
| 3656 |
+
— *end note*]
|
| 3657 |
+
|
| 3658 |
+
``` cpp
|
| 3659 |
+
constexpr size_t index() const noexcept;
|
| 3660 |
+
```
|
| 3661 |
+
|
| 3662 |
+
*Effects:* If `valueless_by_exception()` is `true`, returns
|
| 3663 |
+
`variant_npos`. Otherwise, returns the zero-based index of the
|
| 3664 |
+
alternative of the contained value.
|
| 3665 |
+
|
| 3666 |
+
#### Swap <a id="variant.swap">[[variant.swap]]</a>
|
| 3667 |
+
|
| 3668 |
+
``` cpp
|
| 3669 |
+
void swap(variant& rhs) noexcept(see below);
|
| 3670 |
+
```
|
| 3671 |
+
|
| 3672 |
+
*Requires:* Lvalues of type `Tᵢ` shall be
|
| 3673 |
+
swappable ([[swappable.requirements]]) and
|
| 3674 |
+
`is_move_constructible_v<``Tᵢ``>` shall be `true` for all i.
|
| 3675 |
+
|
| 3676 |
+
*Effects:*
|
| 3677 |
+
|
| 3678 |
+
- if `valueless_by_exception() && rhs.valueless_by_exception()` no
|
| 3679 |
+
effect. Otherwise,
|
| 3680 |
+
- if `index() == rhs.index()`, calls
|
| 3681 |
+
`swap(get<`i`>(*this), get<`i`>(rhs))` where i is `index()`.
|
| 3682 |
+
Otherwise,
|
| 3683 |
+
- exchanges values of `rhs` and `*this`.
|
| 3684 |
+
|
| 3685 |
+
*Throws:* If `index() == rhs.index()`, any exception thrown by
|
| 3686 |
+
`swap(get<`i`>(*this), get<`i`>(rhs))` with i being `index()`.
|
| 3687 |
+
Otherwise, any exception thrown by the move constructor of `Tᵢ` or `Tⱼ`
|
| 3688 |
+
with i being `index()` and j being `rhs.index()`.
|
| 3689 |
+
|
| 3690 |
+
*Remarks:* If an exception is thrown during the call to function
|
| 3691 |
+
`swap(get<`i`>(*this), get<`i`>(rhs))`, the states of the contained
|
| 3692 |
+
values of `*this` and of `rhs` are determined by the exception safety
|
| 3693 |
+
guarantee of `swap` for lvalues of `Tᵢ` with i being `index()`. If an
|
| 3694 |
+
exception is thrown during the exchange of the values of `*this` and
|
| 3695 |
+
`rhs`, the states of the values of `*this` and of `rhs` are determined
|
| 3696 |
+
by the exception safety guarantee of `variant`’s move constructor. The
|
| 3697 |
+
expression inside `noexcept` is equivalent to the logical AND of
|
| 3698 |
+
`is_nothrow_move_constructible_v<``Tᵢ``> && is_nothrow_swappable_v<``Tᵢ``>`
|
| 3699 |
+
for all i.
|
| 3700 |
+
|
| 3701 |
+
### `variant` helper classes <a id="variant.helper">[[variant.helper]]</a>
|
| 3702 |
+
|
| 3703 |
+
``` cpp
|
| 3704 |
+
template <class T> struct variant_size;
|
| 3705 |
+
```
|
| 3706 |
+
|
| 3707 |
+
*Remarks:* All specializations of `variant_size` shall meet the
|
| 3708 |
+
`UnaryTypeTrait` requirements ([[meta.rqmts]]) with a base
|
| 3709 |
+
characteristic of `integral_constant<size_t, N>` for some `N`.
|
| 3710 |
+
|
| 3711 |
+
``` cpp
|
| 3712 |
+
template <class T> class variant_size<const T>;
|
| 3713 |
+
template <class T> class variant_size<volatile T>;
|
| 3714 |
+
template <class T> class variant_size<const volatile T>;
|
| 3715 |
+
```
|
| 3716 |
+
|
| 3717 |
+
Let `VS` denote `variant_size<T>` of the cv-unqualified type `T`. Then
|
| 3718 |
+
each of the three templates shall meet the `UnaryTypeTrait`
|
| 3719 |
+
requirements ([[meta.rqmts]]) with a base characteristic of
|
| 3720 |
+
`integral_constant<size_t, VS::value>`.
|
| 3721 |
+
|
| 3722 |
+
``` cpp
|
| 3723 |
+
template <class... Types>
|
| 3724 |
+
struct variant_size<variant<Types...>> : integral_constant<size_t, sizeof...(Types)> { };
|
| 3725 |
+
```
|
| 3726 |
+
|
| 3727 |
+
``` cpp
|
| 3728 |
+
template <size_t I, class T> class variant_alternative<I, const T>;
|
| 3729 |
+
template <size_t I, class T> class variant_alternative<I, volatile T>;
|
| 3730 |
+
template <size_t I, class T> class variant_alternative<I, const volatile T>;
|
| 3731 |
+
```
|
| 3732 |
+
|
| 3733 |
+
Let `VA` denote `variant_alternative<I, T>` of the cv-unqualified type
|
| 3734 |
+
`T`. Then each of the three templates shall meet the
|
| 3735 |
+
`TransformationTrait` requirements ([[meta.rqmts]]) with a member
|
| 3736 |
+
typedef `type` that names the following type:
|
| 3737 |
+
|
| 3738 |
+
- for the first specialization, `add_const_t<VA::type>`,
|
| 3739 |
+
- for the second specialization, `add_volatile_t<VA::type>`, and
|
| 3740 |
+
- for the third specialization, `add_cv_t<VA::type>`.
|
| 3741 |
+
|
| 3742 |
+
``` cpp
|
| 3743 |
+
variant_alternative<I, variant<Types...>>::type
|
| 3744 |
+
```
|
| 3745 |
+
|
| 3746 |
+
*Requires:* `I < sizeof...(Types)`.
|
| 3747 |
+
|
| 3748 |
+
*Value:* The type `T_I`.
|
| 3749 |
+
|
| 3750 |
+
### Value access <a id="variant.get">[[variant.get]]</a>
|
| 3751 |
+
|
| 3752 |
+
``` cpp
|
| 3753 |
+
template <class T, class... Types>
|
| 3754 |
+
constexpr bool holds_alternative(const variant<Types...>& v) noexcept;
|
| 3755 |
+
```
|
| 3756 |
+
|
| 3757 |
+
*Requires:* The type `T` occurs exactly once in `Types...`. Otherwise,
|
| 3758 |
+
the program is ill-formed.
|
| 3759 |
+
|
| 3760 |
+
*Returns:* `true` if `index()` is equal to the zero-based index of `T`
|
| 3761 |
+
in `Types...`.
|
| 3762 |
+
|
| 3763 |
+
``` cpp
|
| 3764 |
+
template <size_t I, class... Types>
|
| 3765 |
+
constexpr variant_alternative_t<I, variant<Types...>>& get(variant<Types...>& v);
|
| 3766 |
+
template <size_t I, class... Types>
|
| 3767 |
+
constexpr variant_alternative_t<I, variant<Types...>>&& get(variant<Types...>&& v);
|
| 3768 |
+
template <size_t I, class... Types>
|
| 3769 |
+
constexpr const variant_alternative_t<I, variant<Types...>>& get(const variant<Types...>& v);
|
| 3770 |
+
template <size_t I, class... Types>
|
| 3771 |
+
constexpr const variant_alternative_t<I, variant<Types...>>&& get(const variant<Types...>&& v);
|
| 3772 |
+
```
|
| 3773 |
+
|
| 3774 |
+
*Requires:* `I < sizeof...(Types)`. Otherwise the program is ill-formed.
|
| 3775 |
+
|
| 3776 |
+
*Effects:* If `v.index()` is `I`, returns a reference to the object
|
| 3777 |
+
stored in the `variant`. Otherwise, throws an exception of type
|
| 3778 |
+
`bad_variant_access`.
|
| 3779 |
+
|
| 3780 |
+
``` cpp
|
| 3781 |
+
template <class T, class... Types> constexpr T& get(variant<Types...>& v);
|
| 3782 |
+
template <class T, class... Types> constexpr T&& get(variant<Types...>&& v);
|
| 3783 |
+
template <class T, class... Types> constexpr const T& get(const variant<Types...>& v);
|
| 3784 |
+
template <class T, class... Types> constexpr const T&& get(const variant<Types...>&& v);
|
| 3785 |
+
```
|
| 3786 |
+
|
| 3787 |
+
*Requires:* The type `T` occurs exactly once in `Types...`. Otherwise,
|
| 3788 |
+
the program is ill-formed.
|
| 3789 |
+
|
| 3790 |
+
*Effects:* If `v` holds a value of type `T`, returns a reference to that
|
| 3791 |
+
value. Otherwise, throws an exception of type `bad_variant_access`.
|
| 3792 |
+
|
| 3793 |
+
``` cpp
|
| 3794 |
+
template <size_t I, class... Types>
|
| 3795 |
+
constexpr add_pointer_t<variant_alternative_t<I, variant<Types...>>>
|
| 3796 |
+
get_if(variant<Types...>* v) noexcept;
|
| 3797 |
+
template <size_t I, class... Types>
|
| 3798 |
+
constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...>>>
|
| 3799 |
+
get_if(const variant<Types...>* v) noexcept;
|
| 3800 |
+
```
|
| 3801 |
+
|
| 3802 |
+
*Requires:* `I < sizeof...(Types)`. Otherwise the program is ill-formed.
|
| 3803 |
+
|
| 3804 |
+
*Returns:* A pointer to the value stored in the `variant`, if
|
| 3805 |
+
`v != nullptr` and `v->index() == I`. Otherwise, returns `nullptr`.
|
| 3806 |
+
|
| 3807 |
+
``` cpp
|
| 3808 |
+
template <class T, class... Types>
|
| 3809 |
+
constexpr add_pointer_t<T>
|
| 3810 |
+
get_if(variant<Types...>* v) noexcept;
|
| 3811 |
+
template <class T, class... Types>
|
| 3812 |
+
constexpr add_pointer_t<const T>
|
| 3813 |
+
get_if(const variant<Types...>* v) noexcept;
|
| 3814 |
+
```
|
| 3815 |
+
|
| 3816 |
+
*Requires:* The type `T` occurs exactly once in `Types...`. Otherwise,
|
| 3817 |
+
the program is ill-formed.
|
| 3818 |
+
|
| 3819 |
+
*Effects:* Equivalent to: `return get_if<`i`>(v);` with i being the
|
| 3820 |
+
zero-based index of `T` in `Types...`.
|
| 3821 |
+
|
| 3822 |
+
### Relational operators <a id="variant.relops">[[variant.relops]]</a>
|
| 3823 |
+
|
| 3824 |
+
``` cpp
|
| 3825 |
+
template <class... Types>
|
| 3826 |
+
constexpr bool operator==(const variant<Types...>& v, const variant<Types...>& w);
|
| 3827 |
+
```
|
| 3828 |
+
|
| 3829 |
+
*Requires:* `get<`i`>(v) == get<`i`>(w)` is a valid expression returning
|
| 3830 |
+
a type that is convertible to `bool`, for all i.
|
| 3831 |
+
|
| 3832 |
+
*Returns:* If `v.index() != w.index()`, `false`; otherwise if
|
| 3833 |
+
`v.valueless_by_exception()`, `true`; otherwise
|
| 3834 |
+
`get<`i`>(v) == get<`i`>(w)` with i being `v.index()`.
|
| 3835 |
|
| 3836 |
``` cpp
|
| 3837 |
+
template <class... Types>
|
| 3838 |
+
constexpr bool operator!=(const variant<Types...>& v, const variant<Types...>& w);
|
| 3839 |
+
```
|
|
|
|
| 3840 |
|
| 3841 |
+
*Requires:* `get<`i`>(v) != get<`i`>(w)` is a valid expression returning
|
| 3842 |
+
a type that is convertible to `bool`, for all i.
|
| 3843 |
+
|
| 3844 |
+
*Returns:* If `v.index() != w.index()`, `true`; otherwise if
|
| 3845 |
+
`v.valueless_by_exception()`, `false`; otherwise
|
| 3846 |
+
`get<`i`>(v) != get<`i`>(w)` with i being `v.index()`.
|
| 3847 |
+
|
| 3848 |
+
``` cpp
|
| 3849 |
+
template <class... Types>
|
| 3850 |
+
constexpr bool operator<(const variant<Types...>& v, const variant<Types...>& w);
|
| 3851 |
```
|
| 3852 |
|
| 3853 |
+
*Requires:* `get<`i`>(v) < get<`i`>(w)` is a valid expression returning
|
| 3854 |
+
a type that is convertible to `bool`, for all i.
|
| 3855 |
|
| 3856 |
+
*Returns:* If `w.valueless_by_exception()`, `false`; otherwise if
|
| 3857 |
+
`v.valueless_by_exception()`, `true`; otherwise, if
|
| 3858 |
+
`v.index() < w.index()`, `true`; otherwise if `v.index() > w.index()`,
|
| 3859 |
+
`false`; otherwise `get<`i`>(v) < get<`i`>(w)` with i being `v.index()`.
|
| 3860 |
|
| 3861 |
``` cpp
|
| 3862 |
+
template <class... Types>
|
| 3863 |
+
constexpr bool operator>(const variant<Types...>& v, const variant<Types...>& w);
|
| 3864 |
+
```
|
| 3865 |
+
|
| 3866 |
+
*Requires:* `get<`i`>(v) > get<`i`>(w)` is a valid expression returning
|
| 3867 |
+
a type that is convertible to `bool`, for all i.
|
| 3868 |
+
|
| 3869 |
+
*Returns:* If `v.valueless_by_exception()`, `false`; otherwise if
|
| 3870 |
+
`w.valueless_by_exception()`, `true`; otherwise, if
|
| 3871 |
+
`v.index() > w.index()`, `true`; otherwise if `v.index() < w.index()`,
|
| 3872 |
+
`false`; otherwise `get<`i`>(v) > get<`i`>(w)` with i being `v.index()`.
|
| 3873 |
+
|
| 3874 |
+
``` cpp
|
| 3875 |
+
template <class... Types>
|
| 3876 |
+
constexpr bool operator<=(const variant<Types...>& v, const variant<Types...>& w);
|
| 3877 |
+
```
|
| 3878 |
+
|
| 3879 |
+
*Requires:* `get<`i`>(v) <= get<`i`>(w)` is a valid expression returning
|
| 3880 |
+
a type that is convertible to `bool`, for all i.
|
| 3881 |
+
|
| 3882 |
+
*Returns:* If `v.valueless_by_exception()`, `true`; otherwise if
|
| 3883 |
+
`w.valueless_by_exception()`, `false`; otherwise, if
|
| 3884 |
+
`v.index() < w.index()`, `true`; otherwise if `v.index() > w.index()`,
|
| 3885 |
+
`false`; otherwise `get<`i`>(v) <= get<`i`>(w)` with i being
|
| 3886 |
+
`v.index()`.
|
| 3887 |
+
|
| 3888 |
+
``` cpp
|
| 3889 |
+
template <class... Types>
|
| 3890 |
+
constexpr bool operator>=(const variant<Types...>& v, const variant<Types...>& w);
|
| 3891 |
+
```
|
| 3892 |
+
|
| 3893 |
+
*Requires:* `get<`i`>(v) >= get<`i`>(w)` is a valid expression returning
|
| 3894 |
+
a type that is convertible to `bool`, for all i.
|
| 3895 |
+
|
| 3896 |
+
*Returns:* If `w.valueless_by_exception()`, `true`; otherwise if
|
| 3897 |
+
`v.valueless_by_exception()`, `false`; otherwise, if
|
| 3898 |
+
`v.index() > w.index()`, `true`; otherwise if `v.index() < w.index()`,
|
| 3899 |
+
`false`; otherwise `get<`i`>(v) >= get<`i`>(w)` with i being
|
| 3900 |
+
`v.index()`.
|
| 3901 |
+
|
| 3902 |
+
### Visitation <a id="variant.visit">[[variant.visit]]</a>
|
| 3903 |
+
|
| 3904 |
+
``` cpp
|
| 3905 |
+
template <class Visitor, class... Variants>
|
| 3906 |
+
constexpr see below visit(Visitor&& vis, Variants&&... vars);
|
| 3907 |
+
```
|
| 3908 |
+
|
| 3909 |
+
*Requires:* The expression in the *Effects:* element shall be a valid
|
| 3910 |
+
expression of the same type and value category, for all combinations of
|
| 3911 |
+
alternative types of all variants. Otherwise, the program is ill-formed.
|
| 3912 |
+
|
| 3913 |
+
*Effects:* Let `is...` be `vars.index()...`. Returns
|
| 3914 |
+
*INVOKE*(forward\<Visitor\>(vis), get\<is\>(
|
| 3915 |
+
`forward<Variants>(vars))...);`.
|
| 3916 |
+
|
| 3917 |
+
*Remarks:* The return type is the common type of all possible *`INVOKE`*
|
| 3918 |
+
expressions of the *Effects:* element.
|
| 3919 |
+
|
| 3920 |
+
*Throws:* `bad_variant_access` if any `variant` in `vars` is
|
| 3921 |
+
`valueless_by_exception()`.
|
| 3922 |
+
|
| 3923 |
+
*Complexity:* For `sizeof...(Variants) <= 1`, the invocation of the
|
| 3924 |
+
callable object is implemented in constant time, i.e. it does not depend
|
| 3925 |
+
on `sizeof...(Types).` For `sizeof...(Variants) > 1`, the invocation of
|
| 3926 |
+
the callable object has no complexity requirements.
|
| 3927 |
+
|
| 3928 |
+
### Class `monostate` <a id="variant.monostate">[[variant.monostate]]</a>
|
| 3929 |
+
|
| 3930 |
+
``` cpp
|
| 3931 |
+
struct monostate{};
|
| 3932 |
+
```
|
| 3933 |
+
|
| 3934 |
+
The class `monostate` can serve as a first alternative type for a
|
| 3935 |
+
`variant` to make the `variant` type default constructible.
|
| 3936 |
+
|
| 3937 |
+
### `monostate` relational operators <a id="variant.monostate.relops">[[variant.monostate.relops]]</a>
|
| 3938 |
+
|
| 3939 |
+
``` cpp
|
| 3940 |
+
constexpr bool operator<(monostate, monostate) noexcept { return false; }
|
| 3941 |
+
constexpr bool operator>(monostate, monostate) noexcept { return false; }
|
| 3942 |
+
constexpr bool operator<=(monostate, monostate) noexcept { return true; }
|
| 3943 |
+
constexpr bool operator>=(monostate, monostate) noexcept { return true; }
|
| 3944 |
+
constexpr bool operator==(monostate, monostate) noexcept { return true; }
|
| 3945 |
+
constexpr bool operator!=(monostate, monostate) noexcept { return false; }
|
| 3946 |
+
```
|
| 3947 |
+
|
| 3948 |
+
[*Note 1*: `monostate` objects have only a single state; they thus
|
| 3949 |
+
always compare equal. — *end note*]
|
| 3950 |
+
|
| 3951 |
+
### Specialized algorithms <a id="variant.specalg">[[variant.specalg]]</a>
|
| 3952 |
+
|
| 3953 |
+
``` cpp
|
| 3954 |
+
template <class... Types>
|
| 3955 |
+
void swap(variant<Types...>& v, variant<Types...>& w) noexcept(see below);
|
| 3956 |
+
```
|
| 3957 |
+
|
| 3958 |
+
*Effects:* Equivalent to `v.swap(w)`.
|
| 3959 |
+
|
| 3960 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 3961 |
+
unless `is_move_constructible_v<``Tᵢ``> && is_swappable_v<``Tᵢ``>` is
|
| 3962 |
+
`true` for all i. The expression inside `noexcept` is equivalent to
|
| 3963 |
+
`noexcept(v.swap(w))`.
|
| 3964 |
+
|
| 3965 |
+
### Class `bad_variant_access` <a id="variant.bad.access">[[variant.bad.access]]</a>
|
| 3966 |
+
|
| 3967 |
+
``` cpp
|
| 3968 |
+
class bad_variant_access : public exception {
|
| 3969 |
+
public:
|
| 3970 |
+
bad_variant_access() noexcept;
|
| 3971 |
+
const char* what() const noexcept override;
|
| 3972 |
};
|
| 3973 |
+
```
|
| 3974 |
+
|
| 3975 |
+
Objects of type `bad_variant_access` are thrown to report invalid
|
| 3976 |
+
accesses to the value of a `variant` object.
|
| 3977 |
+
|
| 3978 |
+
``` cpp
|
| 3979 |
+
bad_variant_access() noexcept;
|
| 3980 |
+
```
|
| 3981 |
+
|
| 3982 |
+
Constructs a `bad_variant_access` object.
|
| 3983 |
+
|
| 3984 |
+
``` cpp
|
| 3985 |
+
const char* what() const noexcept override;
|
| 3986 |
+
```
|
| 3987 |
+
|
| 3988 |
+
*Returns:* An *implementation-defined* NTBS.
|
| 3989 |
+
|
| 3990 |
+
### Hash support <a id="variant.hash">[[variant.hash]]</a>
|
| 3991 |
+
|
| 3992 |
+
``` cpp
|
| 3993 |
+
template <class... Types> struct hash<variant<Types...>>;
|
| 3994 |
+
```
|
| 3995 |
+
|
| 3996 |
+
The specialization `hash<variant<Types...>>` is
|
| 3997 |
+
enabled ([[unord.hash]]) if and only if every specialization in
|
| 3998 |
+
`hash<remove_const_t<Types>>...` is enabled. The member functions are
|
| 3999 |
+
not guaranteed to be `noexcept`.
|
| 4000 |
+
|
| 4001 |
+
``` cpp
|
| 4002 |
+
template <> struct hash<monostate>;
|
| 4003 |
+
```
|
| 4004 |
+
|
| 4005 |
+
The specialization is enabled ([[unord.hash]]).
|
| 4006 |
+
|
| 4007 |
+
### Allocator-related traits <a id="variant.traits">[[variant.traits]]</a>
|
| 4008 |
+
|
| 4009 |
+
``` cpp
|
| 4010 |
+
template <class... Types, class Alloc>
|
| 4011 |
+
struct uses_allocator<variant<Types...>, Alloc> : true_type { };
|
| 4012 |
+
```
|
| 4013 |
+
|
| 4014 |
+
*Requires:* `Alloc` shall be an Allocator ([[allocator.requirements]]).
|
| 4015 |
+
|
| 4016 |
+
[*Note 1*: Specialization of this trait informs other library
|
| 4017 |
+
components that variant can be constructed with an allocator, even
|
| 4018 |
+
though it does not have a nested `allocator_type`. — *end note*]
|
| 4019 |
+
|
| 4020 |
+
## Storage for any type <a id="any">[[any]]</a>
|
| 4021 |
+
|
| 4022 |
+
This section describes components that C++programs may use to perform
|
| 4023 |
+
operations on objects of a discriminated type.
|
| 4024 |
+
|
| 4025 |
+
[*Note 1*: The discriminated type may contain values of different types
|
| 4026 |
+
but does not attempt conversion between them, i.e. `5` is held strictly
|
| 4027 |
+
as an `int` and is not implicitly convertible either to `"5"` or to
|
| 4028 |
+
`5.0`. This indifference to interpretation but awareness of type
|
| 4029 |
+
effectively allows safe, generic containers of single values, with no
|
| 4030 |
+
scope for surprises from ambiguous conversions. — *end note*]
|
| 4031 |
+
|
| 4032 |
+
### Header `<any>` synopsis <a id="any.synop">[[any.synop]]</a>
|
| 4033 |
+
|
| 4034 |
+
``` cpp
|
| 4035 |
+
namespace std {
|
| 4036 |
+
// [any.bad_any_cast], class bad_any_cast
|
| 4037 |
+
class bad_any_cast;
|
| 4038 |
+
|
| 4039 |
+
// [any.class], class any
|
| 4040 |
+
class any;
|
| 4041 |
+
|
| 4042 |
+
// [any.nonmembers], non-member functions
|
| 4043 |
+
void swap(any& x, any& y) noexcept;
|
| 4044 |
+
|
| 4045 |
+
template <class T, class... Args>
|
| 4046 |
+
any make_any(Args&& ...args);
|
| 4047 |
+
template <class T, class U, class... Args>
|
| 4048 |
+
any make_any(initializer_list<U> il, Args&& ...args);
|
| 4049 |
+
|
| 4050 |
+
template<class T>
|
| 4051 |
+
T any_cast(const any& operand);
|
| 4052 |
+
template<class T>
|
| 4053 |
+
T any_cast(any& operand);
|
| 4054 |
+
template<class T>
|
| 4055 |
+
T any_cast(any&& operand);
|
| 4056 |
+
|
| 4057 |
+
template<class T>
|
| 4058 |
+
const T* any_cast(const any* operand) noexcept;
|
| 4059 |
+
template<class T>
|
| 4060 |
+
T* any_cast(any* operand) noexcept;
|
| 4061 |
}
|
| 4062 |
```
|
| 4063 |
|
| 4064 |
+
### Class `bad_any_cast` <a id="any.bad_any_cast">[[any.bad_any_cast]]</a>
|
| 4065 |
+
|
| 4066 |
+
``` cpp
|
| 4067 |
+
class bad_any_cast : public bad_cast {
|
| 4068 |
+
public:
|
| 4069 |
+
const char* what() const noexcept override;
|
| 4070 |
+
};
|
| 4071 |
+
```
|
| 4072 |
+
|
| 4073 |
+
Objects of type `bad_any_cast` are thrown by a failed `any_cast` (
|
| 4074 |
+
[[any.nonmembers]]).
|
| 4075 |
+
|
| 4076 |
+
``` cpp
|
| 4077 |
+
const char* what() const noexcept override;
|
| 4078 |
+
```
|
| 4079 |
+
|
| 4080 |
+
*Returns:* An *implementation-defined* NTBS.
|
| 4081 |
+
|
| 4082 |
+
*Remarks:* The message may be a null-terminated multibyte
|
| 4083 |
+
string ([[multibyte.strings]]), suitable for conversion and display as
|
| 4084 |
+
a wstring ([[string.classes]], [[locale.codecvt]]).
|
| 4085 |
+
|
| 4086 |
+
### Class `any` <a id="any.class">[[any.class]]</a>
|
| 4087 |
+
|
| 4088 |
+
``` cpp
|
| 4089 |
+
class any {
|
| 4090 |
+
public:
|
| 4091 |
+
// [any.cons], construction and destruction
|
| 4092 |
+
constexpr any() noexcept;
|
| 4093 |
+
|
| 4094 |
+
any(const any& other);
|
| 4095 |
+
any(any&& other) noexcept;
|
| 4096 |
+
|
| 4097 |
+
template <class T> any(T&& value);
|
| 4098 |
+
|
| 4099 |
+
template <class T, class... Args>
|
| 4100 |
+
explicit any(in_place_type_t<T>, Args&&...);
|
| 4101 |
+
template <class T, class U, class... Args>
|
| 4102 |
+
explicit any(in_place_type_t<T>, initializer_list<U>, Args&&...);
|
| 4103 |
+
|
| 4104 |
+
~any();
|
| 4105 |
+
|
| 4106 |
+
// [any.assign], assignments
|
| 4107 |
+
any& operator=(const any& rhs);
|
| 4108 |
+
any& operator=(any&& rhs) noexcept;
|
| 4109 |
+
|
| 4110 |
+
template <class T> any& operator=(T&& rhs);
|
| 4111 |
+
|
| 4112 |
+
// [any.modifiers], modifiers
|
| 4113 |
+
template <class T, class... Args>
|
| 4114 |
+
decay_t<T>& emplace(Args&& ...);
|
| 4115 |
+
template <class T, class U, class... Args>
|
| 4116 |
+
decay_t<T>& emplace(initializer_list<U>, Args&&...);
|
| 4117 |
+
void reset() noexcept;
|
| 4118 |
+
void swap(any& rhs) noexcept;
|
| 4119 |
+
|
| 4120 |
+
// [any.observers], observers
|
| 4121 |
+
bool has_value() const noexcept;
|
| 4122 |
+
const type_info& type() const noexcept;
|
| 4123 |
+
};
|
| 4124 |
+
```
|
| 4125 |
+
|
| 4126 |
+
An object of class `any` stores an instance of any type that satisfies
|
| 4127 |
+
the constructor requirements or it has no value, and this is referred to
|
| 4128 |
+
as the *state* of the class `any` object. The stored instance is called
|
| 4129 |
+
the *contained value*, Two states are equivalent if either they both
|
| 4130 |
+
have no value, or both have a value and the contained values are
|
| 4131 |
+
equivalent.
|
| 4132 |
+
|
| 4133 |
+
The non-member `any_cast` functions provide type-safe access to the
|
| 4134 |
+
contained value.
|
| 4135 |
+
|
| 4136 |
+
Implementations should avoid the use of dynamically allocated memory for
|
| 4137 |
+
a small contained value.
|
| 4138 |
+
|
| 4139 |
+
[*Example 1*: where the object constructed is holding only an
|
| 4140 |
+
`int`. — *end example*]
|
| 4141 |
+
|
| 4142 |
+
Such small-object optimization shall only be applied to types `T` for
|
| 4143 |
+
which `is_nothrow_move_constructible_v<T>` is `true`.
|
| 4144 |
+
|
| 4145 |
+
#### Construction and destruction <a id="any.cons">[[any.cons]]</a>
|
| 4146 |
+
|
| 4147 |
+
``` cpp
|
| 4148 |
+
constexpr any() noexcept;
|
| 4149 |
+
```
|
| 4150 |
+
|
| 4151 |
+
*Postconditions:* `has_value()` is `false`.
|
| 4152 |
+
|
| 4153 |
+
``` cpp
|
| 4154 |
+
any(const any& other);
|
| 4155 |
+
```
|
| 4156 |
+
|
| 4157 |
+
*Effects:* If `other.has_value()` is `false`, constructs an object that
|
| 4158 |
+
has no value. Otherwise, equivalent to
|
| 4159 |
+
`any(in_place<T>, any_cast<const T&>(other))` where `T` is the type of
|
| 4160 |
+
the contained object.
|
| 4161 |
+
|
| 4162 |
+
*Throws:* Any exceptions arising from calling the selected constructor
|
| 4163 |
+
for the contained value.
|
| 4164 |
+
|
| 4165 |
+
``` cpp
|
| 4166 |
+
any(any&& other) noexcept;
|
| 4167 |
+
```
|
| 4168 |
+
|
| 4169 |
+
*Effects:* If `other.has_value()` is `false`, constructs an object that
|
| 4170 |
+
has no value. Otherwise, constructs an object of type `any` that
|
| 4171 |
+
contains either the contained object of `other`, or contains an object
|
| 4172 |
+
of the same type constructed from the contained object of `other`
|
| 4173 |
+
considering that contained object as an rvalue.
|
| 4174 |
+
|
| 4175 |
+
*Postconditions:* `other` is left in a valid but otherwise unspecified
|
| 4176 |
+
state.
|
| 4177 |
+
|
| 4178 |
+
``` cpp
|
| 4179 |
+
template<class T>
|
| 4180 |
+
any(T&& value);
|
| 4181 |
+
```
|
| 4182 |
+
|
| 4183 |
+
Let `VT` be `decay_t<T>`.
|
| 4184 |
+
|
| 4185 |
+
*Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
|
| 4186 |
+
|
| 4187 |
+
*Effects:* Constructs an object of type `any` that contains an object of
|
| 4188 |
+
type `VT` direct-initialized with `std::forward<T>(value)`.
|
| 4189 |
+
|
| 4190 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 4191 |
+
unless `VT` is not the same type as `any`, `VT` is not a specialization
|
| 4192 |
+
of `in_place_type_t`, and `is_copy_constructible_v<VT>` is `true`.
|
| 4193 |
+
|
| 4194 |
+
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 4195 |
+
|
| 4196 |
+
``` cpp
|
| 4197 |
+
template <class T, class... Args>
|
| 4198 |
+
explicit any(in_place_type_t<T>, Args&&... args);
|
| 4199 |
+
```
|
| 4200 |
+
|
| 4201 |
+
Let `VT` be `decay_t<T>`.
|
| 4202 |
+
|
| 4203 |
+
*Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
|
| 4204 |
+
|
| 4205 |
+
*Effects:* Initializes the contained value as if
|
| 4206 |
+
direct-non-list-initializing an object of type `VT` with the arguments
|
| 4207 |
+
`std::forward<Args>(args)...`.
|
| 4208 |
+
|
| 4209 |
+
*Postconditions:* `*this` contains a value of type `VT`.
|
| 4210 |
+
|
| 4211 |
+
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 4212 |
+
|
| 4213 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 4214 |
+
unless `is_copy_constructible_v<VT>` is `true` and
|
| 4215 |
+
`is_constructible_v<VT, Args...>` is `true`.
|
| 4216 |
+
|
| 4217 |
+
``` cpp
|
| 4218 |
+
template <class T, class U, class... Args>
|
| 4219 |
+
explicit any(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
|
| 4220 |
+
```
|
| 4221 |
+
|
| 4222 |
+
Let `VT` be `decay_t<T>`.
|
| 4223 |
+
|
| 4224 |
+
*Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
|
| 4225 |
+
|
| 4226 |
+
*Effects:* Initializes the contained value as if
|
| 4227 |
+
direct-non-list-initializing an object of type `VT` with the arguments
|
| 4228 |
+
`il, std::forward<Args>(args)...`.
|
| 4229 |
+
|
| 4230 |
+
*Postconditions:* `*this` contains a value.
|
| 4231 |
+
|
| 4232 |
+
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 4233 |
+
|
| 4234 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 4235 |
+
unless `is_copy_constructible_v<VT>` is `true` and
|
| 4236 |
+
`is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
|
| 4237 |
+
|
| 4238 |
+
``` cpp
|
| 4239 |
+
~any();
|
| 4240 |
+
```
|
| 4241 |
+
|
| 4242 |
+
*Effects:* As if by `reset()`.
|
| 4243 |
+
|
| 4244 |
+
#### Assignment <a id="any.assign">[[any.assign]]</a>
|
| 4245 |
+
|
| 4246 |
+
``` cpp
|
| 4247 |
+
any& operator=(const any& rhs);
|
| 4248 |
+
```
|
| 4249 |
+
|
| 4250 |
+
*Effects:* As if by `any(rhs).swap(*this)`. No effects if an exception
|
| 4251 |
+
is thrown.
|
| 4252 |
+
|
| 4253 |
+
*Returns:* `*this`.
|
| 4254 |
+
|
| 4255 |
+
*Throws:* Any exceptions arising from the copy constructor for the
|
| 4256 |
+
contained value.
|
| 4257 |
+
|
| 4258 |
+
``` cpp
|
| 4259 |
+
any& operator=(any&& rhs) noexcept;
|
| 4260 |
+
```
|
| 4261 |
+
|
| 4262 |
+
*Effects:* As if by `any(std::move(rhs)).swap(*this)`.
|
| 4263 |
+
|
| 4264 |
+
*Returns:* `*this`.
|
| 4265 |
+
|
| 4266 |
+
*Postconditions:* The state of `*this` is equivalent to the original
|
| 4267 |
+
state of `rhs` and `rhs` is left in a valid but otherwise unspecified
|
| 4268 |
+
state.
|
| 4269 |
+
|
| 4270 |
+
``` cpp
|
| 4271 |
+
template<class T>
|
| 4272 |
+
any& operator=(T&& rhs);
|
| 4273 |
+
```
|
| 4274 |
+
|
| 4275 |
+
Let `VT` be `decay_t<T>`.
|
| 4276 |
+
|
| 4277 |
+
*Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
|
| 4278 |
+
|
| 4279 |
+
*Effects:* Constructs an object `tmp` of type `any` that contains an
|
| 4280 |
+
object of type `VT` direct-initialized with `std::forward<T>(rhs)`, and
|
| 4281 |
+
`tmp.swap(*this)`. No effects if an exception is thrown.
|
| 4282 |
+
|
| 4283 |
+
*Returns:* `*this`.
|
| 4284 |
+
|
| 4285 |
+
*Remarks:* This operator shall not participate in overload resolution
|
| 4286 |
+
unless `VT` is not the same type as `any` and
|
| 4287 |
+
`is_copy_constructible_v<VT>` is `true`.
|
| 4288 |
+
|
| 4289 |
+
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 4290 |
+
|
| 4291 |
+
#### Modifiers <a id="any.modifiers">[[any.modifiers]]</a>
|
| 4292 |
+
|
| 4293 |
+
``` cpp
|
| 4294 |
+
template <class T, class... Args>
|
| 4295 |
+
decay_t<T>& emplace(Args&&... args);
|
| 4296 |
+
```
|
| 4297 |
+
|
| 4298 |
+
Let `VT` be `decay_t<T>`.
|
| 4299 |
+
|
| 4300 |
+
*Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
|
| 4301 |
+
|
| 4302 |
+
*Effects:* Calls `reset()`. Then initializes the contained value as if
|
| 4303 |
+
direct-non-list-initializing an object of type `VT` with the arguments
|
| 4304 |
+
`std::forward<Args>(args)...`.
|
| 4305 |
+
|
| 4306 |
+
*Postconditions:* `*this` contains a value.
|
| 4307 |
+
|
| 4308 |
+
*Returns:* A reference to the new contained value.
|
| 4309 |
+
|
| 4310 |
+
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 4311 |
+
|
| 4312 |
+
*Remarks:* If an exception is thrown during the call to `VT`’s
|
| 4313 |
+
constructor, `*this` does not contain a value, and any previously
|
| 4314 |
+
contained value has been destroyed. This function shall not participate
|
| 4315 |
+
in overload resolution unless `is_copy_constructible_v<VT>` is `true`
|
| 4316 |
+
and `is_constructible_v<VT, Args...>` is `true`.
|
| 4317 |
+
|
| 4318 |
+
``` cpp
|
| 4319 |
+
template <class T, class U, class... Args>
|
| 4320 |
+
decay_t<T>& emplace(initializer_list<U> il, Args&&... args);
|
| 4321 |
+
```
|
| 4322 |
+
|
| 4323 |
+
Let `VT` be `decay_t<T>`.
|
| 4324 |
+
|
| 4325 |
+
*Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
|
| 4326 |
+
|
| 4327 |
+
*Effects:* Calls `reset()`. Then initializes the contained value as if
|
| 4328 |
+
direct-non-list-initializing an object of type `VT` with the arguments
|
| 4329 |
+
`il, std::forward<Args>(args)...`.
|
| 4330 |
+
|
| 4331 |
+
*Postconditions:* `*this` contains a value.
|
| 4332 |
+
|
| 4333 |
+
*Returns:* A reference to the new contained value.
|
| 4334 |
+
|
| 4335 |
+
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 4336 |
+
|
| 4337 |
+
*Remarks:* If an exception is thrown during the call to `VT`’s
|
| 4338 |
+
constructor, `*this` does not contain a value, and any previously
|
| 4339 |
+
contained value has been destroyed. The function shall not participate
|
| 4340 |
+
in overload resolution unless `is_copy_constructible_v<VT>` is `true`
|
| 4341 |
+
and `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
|
| 4342 |
+
|
| 4343 |
+
``` cpp
|
| 4344 |
+
void reset() noexcept;
|
| 4345 |
+
```
|
| 4346 |
+
|
| 4347 |
+
*Effects:* If `has_value()` is `true`, destroys the contained value.
|
| 4348 |
+
|
| 4349 |
+
*Postconditions:* `has_value()` is `false`.
|
| 4350 |
+
|
| 4351 |
+
``` cpp
|
| 4352 |
+
void swap(any& rhs) noexcept;
|
| 4353 |
+
```
|
| 4354 |
+
|
| 4355 |
+
*Effects:* Exchanges the states of `*this` and `rhs`.
|
| 4356 |
+
|
| 4357 |
+
#### Observers <a id="any.observers">[[any.observers]]</a>
|
| 4358 |
+
|
| 4359 |
+
``` cpp
|
| 4360 |
+
bool has_value() const noexcept;
|
| 4361 |
+
```
|
| 4362 |
+
|
| 4363 |
+
*Returns:* `true` if `*this` contains an object, otherwise `false`.
|
| 4364 |
+
|
| 4365 |
+
``` cpp
|
| 4366 |
+
const type_info& type() const noexcept;
|
| 4367 |
+
```
|
| 4368 |
+
|
| 4369 |
+
*Returns:* `typeid(T)` if `*this` has a contained value of type `T`,
|
| 4370 |
+
otherwise `typeid(void)`.
|
| 4371 |
+
|
| 4372 |
+
[*Note 1*: Useful for querying against types known either at compile
|
| 4373 |
+
time or only at runtime. — *end note*]
|
| 4374 |
+
|
| 4375 |
+
### Non-member functions <a id="any.nonmembers">[[any.nonmembers]]</a>
|
| 4376 |
+
|
| 4377 |
+
``` cpp
|
| 4378 |
+
void swap(any& x, any& y) noexcept;
|
| 4379 |
+
```
|
| 4380 |
+
|
| 4381 |
+
*Effects:* As if by `x.swap(y)`.
|
| 4382 |
+
|
| 4383 |
+
``` cpp
|
| 4384 |
+
template <class T, class... Args>
|
| 4385 |
+
any make_any(Args&& ...args);
|
| 4386 |
+
```
|
| 4387 |
+
|
| 4388 |
+
*Effects:* Equivalent to:
|
| 4389 |
+
`return any(in_place_type<T>, std::forward<Args>(args)...);`
|
| 4390 |
+
|
| 4391 |
+
``` cpp
|
| 4392 |
+
template <class T, class U, class... Args>
|
| 4393 |
+
any make_any(initializer_list<U> il, Args&& ...args);
|
| 4394 |
+
```
|
| 4395 |
+
|
| 4396 |
+
*Effects:* Equivalent to:
|
| 4397 |
+
`return any(in_place_type<T>, il, std::forward<Args>(args)...);`
|
| 4398 |
+
|
| 4399 |
+
``` cpp
|
| 4400 |
+
template<class T>
|
| 4401 |
+
T any_cast(const any& operand);
|
| 4402 |
+
template<class T>
|
| 4403 |
+
T any_cast(any& operand);
|
| 4404 |
+
template<class T>
|
| 4405 |
+
T any_cast(any&& operand);
|
| 4406 |
+
```
|
| 4407 |
+
|
| 4408 |
+
Let `U` be the type `remove_cv_t<remove_reference_t<ValueType>>`.
|
| 4409 |
+
|
| 4410 |
+
*Requires:* For the first overload,
|
| 4411 |
+
`is_constructible_v<ValueType, const U&>` is `true`. For the second
|
| 4412 |
+
overload, `is_constructible_v<ValueType, U&>` is `true`. For the third
|
| 4413 |
+
overload, `is_constructible_v<ValueType, U>` is `true`. Otherwise the
|
| 4414 |
+
program is ill-formed.
|
| 4415 |
+
|
| 4416 |
+
*Returns:* For the first and second overload,
|
| 4417 |
+
`static_cast<ValueType>(*any_cast<U>(&operand))`. For the third
|
| 4418 |
+
overload, `static_cast<ValueType>(std::move(*any_cast<U>(&operand)))`.
|
| 4419 |
+
|
| 4420 |
+
*Throws:* `bad_any_cast` if
|
| 4421 |
+
`operand.type() != typeid(remove_reference_t<T>)`.
|
| 4422 |
+
|
| 4423 |
+
[*Example 1*:
|
| 4424 |
+
|
| 4425 |
+
``` cpp
|
| 4426 |
+
any x(5); // x holds int
|
| 4427 |
+
assert(any_cast<int>(x) == 5); // cast to value
|
| 4428 |
+
any_cast<int&>(x) = 10; // cast to reference
|
| 4429 |
+
assert(any_cast<int>(x) == 10);
|
| 4430 |
+
|
| 4431 |
+
x = "Meow"; // x holds const char*
|
| 4432 |
+
assert(strcmp(any_cast<const char*>(x), "Meow") == 0);
|
| 4433 |
+
any_cast<const char*&>(x) = "Harry";
|
| 4434 |
+
assert(strcmp(any_cast<const char*>(x), "Harry") == 0);
|
| 4435 |
+
|
| 4436 |
+
x = string("Meow"); // x holds string
|
| 4437 |
+
string s, s2("Jane");
|
| 4438 |
+
s = move(any_cast<string&>(x)); // move from any
|
| 4439 |
+
assert(s == "Meow");
|
| 4440 |
+
any_cast<string&>(x) = move(s2); // move to any
|
| 4441 |
+
assert(any_cast<const string&>(x) == "Jane");
|
| 4442 |
+
|
| 4443 |
+
string cat("Meow");
|
| 4444 |
+
const any y(cat); // const y holds string
|
| 4445 |
+
assert(any_cast<const string&>(y) == cat);
|
| 4446 |
+
|
| 4447 |
+
any_cast<string&>(y); // error; cannot
|
| 4448 |
+
// any_cast away const
|
| 4449 |
+
```
|
| 4450 |
+
|
| 4451 |
+
— *end example*]
|
| 4452 |
+
|
| 4453 |
+
``` cpp
|
| 4454 |
+
template<class T>
|
| 4455 |
+
const T* any_cast(const any* operand) noexcept;
|
| 4456 |
+
template<class T>
|
| 4457 |
+
T* any_cast(any* operand) noexcept;
|
| 4458 |
+
```
|
| 4459 |
+
|
| 4460 |
+
*Returns:* If `operand != nullptr && operand->type() == typeid(T)`, a
|
| 4461 |
+
pointer to the object contained by `operand`; otherwise, `nullptr`.
|
| 4462 |
|
| 4463 |
+
[*Example 2*:
|
| 4464 |
|
| 4465 |
``` cpp
|
| 4466 |
+
bool is_string(const any& operand) {
|
| 4467 |
+
return any_cast<string>(&operand) != nullptr;
|
| 4468 |
+
}
|
| 4469 |
```
|
| 4470 |
|
| 4471 |
+
— *end example*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4472 |
|
| 4473 |
+
## Bitsets <a id="bitset">[[bitset]]</a>
|
| 4474 |
|
| 4475 |
+
### Header `<bitset>` synopsis <a id="bitset.syn">[[bitset.syn]]</a>
|
| 4476 |
|
| 4477 |
``` cpp
|
| 4478 |
#include <string>
|
| 4479 |
+
#include <iosfwd> // for istream ([istream.syn]), ostream ([ostream.syn]), see [iosfwd.syn]
|
| 4480 |
+
|
| 4481 |
namespace std {
|
| 4482 |
template <size_t N> class bitset;
|
| 4483 |
|
| 4484 |
+
// [bitset.operators], bitset operators
|
| 4485 |
template <size_t N>
|
| 4486 |
bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept;
|
| 4487 |
template <size_t N>
|
| 4488 |
bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept;
|
| 4489 |
template <size_t N>
|
|
|
|
| 4499 |
|
| 4500 |
The header `<bitset>` defines a class template and several related
|
| 4501 |
functions for representing and manipulating fixed-size sequences of
|
| 4502 |
bits.
|
| 4503 |
|
| 4504 |
+
### Class template `bitset` <a id="template.bitset">[[template.bitset]]</a>
|
| 4505 |
+
|
| 4506 |
``` cpp
|
| 4507 |
namespace std {
|
| 4508 |
template<size_t N> class bitset {
|
| 4509 |
public:
|
| 4510 |
// bit reference:
|
|
|
|
| 4518 |
bool operator~() const noexcept; // flips the bit
|
| 4519 |
operator bool() const noexcept; // for x = b[i];
|
| 4520 |
reference& flip() noexcept; // for b[i].flip();
|
| 4521 |
};
|
| 4522 |
|
| 4523 |
+
// [bitset.cons], constructors
|
| 4524 |
constexpr bitset() noexcept;
|
| 4525 |
constexpr bitset(unsigned long long val) noexcept;
|
| 4526 |
template<class charT, class traits, class Allocator>
|
| 4527 |
explicit bitset(
|
| 4528 |
const basic_string<charT, traits, Allocator>& str,
|
| 4529 |
typename basic_string<charT, traits, Allocator>::size_type pos = 0,
|
| 4530 |
typename basic_string<charT, traits, Allocator>::size_type n =
|
| 4531 |
basic_string<charT, traits, Allocator>::npos,
|
| 4532 |
+
charT zero = charT('0'),
|
| 4533 |
+
charT one = charT('1'));
|
| 4534 |
template <class charT>
|
| 4535 |
explicit bitset(
|
| 4536 |
const charT* str,
|
| 4537 |
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
|
| 4538 |
+
charT zero = charT('0'),
|
| 4539 |
+
charT one = charT('1'));
|
| 4540 |
|
| 4541 |
+
// [bitset.members], bitset operations
|
| 4542 |
bitset<N>& operator&=(const bitset<N>& rhs) noexcept;
|
| 4543 |
bitset<N>& operator|=(const bitset<N>& rhs) noexcept;
|
| 4544 |
bitset<N>& operator^=(const bitset<N>& rhs) noexcept;
|
| 4545 |
bitset<N>& operator<<=(size_t pos) noexcept;
|
| 4546 |
bitset<N>& operator>>=(size_t pos) noexcept;
|
|
|
|
| 4561 |
template <class charT = char,
|
| 4562 |
class traits = char_traits<charT>,
|
| 4563 |
class Allocator = allocator<charT>>
|
| 4564 |
basic_string<charT, traits, Allocator>
|
| 4565 |
to_string(charT zero = charT('0'), charT one = charT('1')) const;
|
| 4566 |
+
|
| 4567 |
size_t count() const noexcept;
|
| 4568 |
constexpr size_t size() const noexcept;
|
| 4569 |
bool operator==(const bitset<N>& rhs) const noexcept;
|
| 4570 |
bool operator!=(const bitset<N>& rhs) const noexcept;
|
| 4571 |
bool test(size_t pos) const;
|
|
|
|
| 4574 |
bool none() const noexcept;
|
| 4575 |
bitset<N> operator<<(size_t pos) const noexcept;
|
| 4576 |
bitset<N> operator>>(size_t pos) const noexcept;
|
| 4577 |
};
|
| 4578 |
|
| 4579 |
+
// [bitset.hash], hash support
|
| 4580 |
template <class T> struct hash;
|
| 4581 |
template <size_t N> struct hash<bitset<N>>;
|
| 4582 |
}
|
| 4583 |
```
|
| 4584 |
|
|
|
|
| 4601 |
- an *out-of-range* error is associated with exceptions of type
|
| 4602 |
`out_of_range` ([[out.of.range]]);
|
| 4603 |
- an *overflow* error is associated with exceptions of type
|
| 4604 |
`overflow_error` ([[overflow.error]]).
|
| 4605 |
|
| 4606 |
+
#### `bitset` constructors <a id="bitset.cons">[[bitset.cons]]</a>
|
| 4607 |
|
| 4608 |
``` cpp
|
| 4609 |
constexpr bitset() noexcept;
|
| 4610 |
```
|
| 4611 |
|
|
|
|
| 4630 |
typename basic_string<charT, traits, Allocator>::size_type n =
|
| 4631 |
basic_string<charT, traits, Allocator>::npos,
|
| 4632 |
charT zero = charT('0'), charT one = charT('1'));
|
| 4633 |
```
|
| 4634 |
|
| 4635 |
+
*Throws:* `out_of_range` if `pos > str.size()` or `invalid_argument` if
|
| 4636 |
+
an invalid character is found (see below).
|
|
|
|
| 4637 |
|
| 4638 |
*Effects:* Determines the effective length `rlen` of the initializing
|
| 4639 |
string as the smaller of `n` and `str.size() - pos`.
|
| 4640 |
|
| 4641 |
The function then throws
|
|
|
|
| 4663 |
const charT* str,
|
| 4664 |
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
|
| 4665 |
charT zero = charT('0'), charT one = charT('1'));
|
| 4666 |
```
|
| 4667 |
|
| 4668 |
+
*Effects:* Constructs an object of class `bitset<N>` as if by:
|
| 4669 |
|
| 4670 |
``` cpp
|
| 4671 |
bitset(
|
| 4672 |
n == basic_string<charT>::npos
|
| 4673 |
? basic_string<charT>(str)
|
| 4674 |
: basic_string<charT>(str, n),
|
| 4675 |
0, n, zero, one)
|
| 4676 |
```
|
| 4677 |
|
| 4678 |
+
#### `bitset` members <a id="bitset.members">[[bitset.members]]</a>
|
| 4679 |
|
| 4680 |
``` cpp
|
| 4681 |
bitset<N>& operator&=(const bitset<N>& rhs) noexcept;
|
| 4682 |
```
|
| 4683 |
|
|
|
|
| 4740 |
|
| 4741 |
``` cpp
|
| 4742 |
bitset<N>& set(size_t pos, bool val = true);
|
| 4743 |
```
|
| 4744 |
|
|
|
|
|
|
|
| 4745 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 4746 |
position.
|
| 4747 |
|
| 4748 |
*Effects:* Stores a new value in the bit at position `pos` in `*this`.
|
| 4749 |
If `val` is nonzero, the stored value is one, otherwise it is zero.
|
|
|
|
| 4760 |
|
| 4761 |
``` cpp
|
| 4762 |
bitset<N>& reset(size_t pos);
|
| 4763 |
```
|
| 4764 |
|
|
|
|
|
|
|
| 4765 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 4766 |
position.
|
| 4767 |
|
| 4768 |
*Effects:* Resets the bit at position `pos` in `*this`.
|
| 4769 |
|
|
|
|
| 4788 |
|
| 4789 |
``` cpp
|
| 4790 |
bitset<N>& flip(size_t pos);
|
| 4791 |
```
|
| 4792 |
|
|
|
|
|
|
|
| 4793 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 4794 |
position.
|
| 4795 |
|
| 4796 |
*Effects:* Toggles the bit at position `pos` in `*this`.
|
| 4797 |
|
|
|
|
| 4862 |
|
| 4863 |
``` cpp
|
| 4864 |
bool test(size_t pos) const;
|
| 4865 |
```
|
| 4866 |
|
|
|
|
|
|
|
| 4867 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 4868 |
position.
|
| 4869 |
|
| 4870 |
*Returns:* `true` if the bit at position `pos` in `*this` has the value
|
| 4871 |
one.
|
| 4872 |
|
| 4873 |
``` cpp
|
| 4874 |
bool all() const noexcept;
|
| 4875 |
```
|
| 4876 |
|
| 4877 |
+
*Returns:* `count() == size()`.
|
| 4878 |
|
| 4879 |
``` cpp
|
| 4880 |
bool any() const noexcept;
|
| 4881 |
```
|
| 4882 |
|
| 4883 |
+
*Returns:* `count() != 0`.
|
| 4884 |
|
| 4885 |
``` cpp
|
| 4886 |
bool none() const noexcept;
|
| 4887 |
```
|
| 4888 |
|
| 4889 |
+
*Returns:* `count() == 0`.
|
| 4890 |
|
| 4891 |
``` cpp
|
| 4892 |
bitset<N> operator<<(size_t pos) const noexcept;
|
| 4893 |
```
|
| 4894 |
|
|
|
|
| 4921 |
`(*this)[pos] == this->test(pos)`, and such that `(*this)[pos] = val` is
|
| 4922 |
equivalent to `this->set(pos, val)`.
|
| 4923 |
|
| 4924 |
*Throws:* Nothing.
|
| 4925 |
|
| 4926 |
+
*Remarks:* For the purpose of determining the presence of a data
|
| 4927 |
race ([[intro.multithread]]), any access or update through the
|
| 4928 |
resulting reference potentially accesses or modifies, respectively, the
|
| 4929 |
entire underlying bitset.
|
| 4930 |
|
| 4931 |
### `bitset` hash support <a id="bitset.hash">[[bitset.hash]]</a>
|
| 4932 |
|
| 4933 |
``` cpp
|
| 4934 |
template <size_t N> struct hash<bitset<N>>;
|
| 4935 |
```
|
| 4936 |
|
| 4937 |
+
The specialization is enabled ([[unord.hash]]).
|
|
|
|
| 4938 |
|
| 4939 |
### `bitset` operators <a id="bitset.operators">[[bitset.operators]]</a>
|
| 4940 |
|
| 4941 |
``` cpp
|
| 4942 |
bitset<N> operator&(const bitset<N>& lhs, const bitset<N>& rhs) noexcept;
|
|
|
|
| 5000 |
## Memory <a id="memory">[[memory]]</a>
|
| 5001 |
|
| 5002 |
### In general <a id="memory.general">[[memory.general]]</a>
|
| 5003 |
|
| 5004 |
This subclause describes the contents of the header `<memory>` (
|
| 5005 |
+
[[memory.syn]]) and some of the contents of the header `<cstdlib>` (
|
| 5006 |
+
[[cstdlib.syn]]).
|
| 5007 |
|
| 5008 |
### Header `<memory>` synopsis <a id="memory.syn">[[memory.syn]]</a>
|
| 5009 |
|
| 5010 |
The header `<memory>` defines several types and function templates that
|
| 5011 |
describe properties of pointers and pointer-like types, manage memory
|
| 5012 |
+
for containers and other template types, destroy objects, and construct
|
| 5013 |
+
multiple objects in uninitialized memory buffers ([[pointer.traits]]–
|
| 5014 |
[[specialized.algorithms]]). The header also defines the templates
|
| 5015 |
`unique_ptr`, `shared_ptr`, `weak_ptr`, and various function templates
|
| 5016 |
that operate on objects of these types ([[smartptr]]).
|
| 5017 |
|
| 5018 |
``` cpp
|
|
|
|
| 5028 |
void declare_no_pointers(char* p, size_t n);
|
| 5029 |
void undeclare_no_pointers(char* p, size_t n);
|
| 5030 |
pointer_safety get_pointer_safety() noexcept;
|
| 5031 |
|
| 5032 |
// [ptr.align], pointer alignment function
|
| 5033 |
+
void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
|
|
|
|
| 5034 |
|
| 5035 |
// [allocator.tag], allocator argument tag
|
| 5036 |
+
struct allocator_arg_t { explicit allocator_arg_t() = default; };
|
| 5037 |
+
inline constexpr allocator_arg_t allocator_arg{};
|
| 5038 |
|
| 5039 |
// [allocator.uses], uses_allocator
|
| 5040 |
template <class T, class Alloc> struct uses_allocator;
|
| 5041 |
|
| 5042 |
// [allocator.traits], allocator traits
|
| 5043 |
template <class Alloc> struct allocator_traits;
|
| 5044 |
|
| 5045 |
+
// [default.allocator], the default allocator
|
| 5046 |
template <class T> class allocator;
|
|
|
|
| 5047 |
template <class T, class U>
|
| 5048 |
bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
|
| 5049 |
template <class T, class U>
|
| 5050 |
bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
|
| 5051 |
|
| 5052 |
+
// [specialized.algorithms], specialized algorithms
|
| 5053 |
+
template <class T> constexpr T* addressof(T& r) noexcept;
|
| 5054 |
+
template <class T> const T* addressof(const T&&) = delete;
|
| 5055 |
+
template <class ForwardIterator>
|
| 5056 |
+
void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
|
| 5057 |
+
template <class ExecutionPolicy, class ForwardIterator>
|
| 5058 |
+
void uninitialized_default_construct(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5059 |
+
ForwardIterator first, ForwardIterator last);
|
| 5060 |
+
template <class ForwardIterator, class Size>
|
| 5061 |
+
ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
|
| 5062 |
+
template <class ExecutionPolicy, class ForwardIterator, class Size>
|
| 5063 |
+
ForwardIterator uninitialized_default_construct_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5064 |
+
ForwardIterator first, Size n);
|
| 5065 |
+
template <class ForwardIterator>
|
| 5066 |
+
void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
|
| 5067 |
+
template <class ExecutionPolicy, class ForwardIterator>
|
| 5068 |
+
void uninitialized_value_construct(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5069 |
+
ForwardIterator first, ForwardIterator last);
|
| 5070 |
+
template <class ForwardIterator, class Size>
|
| 5071 |
+
ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
|
| 5072 |
+
template <class ExecutionPolicy, class ForwardIterator, class Size>
|
| 5073 |
+
ForwardIterator uninitialized_value_construct_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5074 |
+
ForwardIterator first, Size n);
|
| 5075 |
template <class InputIterator, class ForwardIterator>
|
| 5076 |
ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
|
| 5077 |
ForwardIterator result);
|
| 5078 |
+
template <class ExecutionPolicy, class InputIterator, class ForwardIterator>
|
| 5079 |
+
ForwardIterator uninitialized_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5080 |
+
InputIterator first, InputIterator last,
|
| 5081 |
+
ForwardIterator result);
|
| 5082 |
template <class InputIterator, class Size, class ForwardIterator>
|
| 5083 |
ForwardIterator uninitialized_copy_n(InputIterator first, Size n,
|
| 5084 |
ForwardIterator result);
|
| 5085 |
+
template <class ExecutionPolicy, class InputIterator, class Size, class ForwardIterator>
|
| 5086 |
+
ForwardIterator uninitialized_copy_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5087 |
+
InputIterator first, Size n,
|
| 5088 |
+
ForwardIterator result);
|
| 5089 |
+
template <class InputIterator, class ForwardIterator>
|
| 5090 |
+
ForwardIterator uninitialized_move(InputIterator first, InputIterator last,
|
| 5091 |
+
ForwardIterator result);
|
| 5092 |
+
template <class ExecutionPolicy, class InputIterator, class ForwardIterator>
|
| 5093 |
+
ForwardIterator uninitialized_move(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5094 |
+
InputIterator first, InputIterator last,
|
| 5095 |
+
ForwardIterator result);
|
| 5096 |
+
template <class InputIterator, class Size, class ForwardIterator>
|
| 5097 |
+
pair<InputIterator, ForwardIterator>
|
| 5098 |
+
uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
|
| 5099 |
+
template <class ExecutionPolicy, class InputIterator, class Size, class ForwardIterator>
|
| 5100 |
+
pair<InputIterator, ForwardIterator>
|
| 5101 |
+
uninitialized_move_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5102 |
+
InputIterator first, Size n, ForwardIterator result);
|
| 5103 |
template <class ForwardIterator, class T>
|
| 5104 |
void uninitialized_fill(ForwardIterator first, ForwardIterator last,
|
| 5105 |
const T& x);
|
| 5106 |
+
template <class ExecutionPolicy, class ForwardIterator, class T>
|
| 5107 |
+
void uninitialized_fill(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5108 |
+
ForwardIterator first, ForwardIterator last,
|
| 5109 |
+
const T& x);
|
| 5110 |
template <class ForwardIterator, class Size, class T>
|
| 5111 |
ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
|
| 5112 |
+
template <class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 5113 |
+
ForwardIterator uninitialized_fill_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5114 |
+
ForwardIterator first, Size n, const T& x);
|
| 5115 |
+
template <class T>
|
| 5116 |
+
void destroy_at(T* location);
|
| 5117 |
+
template <class ForwardIterator>
|
| 5118 |
+
void destroy(ForwardIterator first, ForwardIterator last);
|
| 5119 |
+
template <class ExecutionPolicy, class ForwardIterator>
|
| 5120 |
+
void destroy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5121 |
+
ForwardIterator first, ForwardIterator last);
|
| 5122 |
+
template <class ForwardIterator, class Size>
|
| 5123 |
+
ForwardIterator destroy_n(ForwardIterator first, Size n);
|
| 5124 |
+
template <class ExecutionPolicy, class ForwardIterator, class Size>
|
| 5125 |
+
ForwardIterator destroy_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5126 |
+
ForwardIterator first, Size n);
|
| 5127 |
|
| 5128 |
+
// [unique.ptr], class template unique_ptr
|
| 5129 |
template <class T> struct default_delete;
|
| 5130 |
template <class T> struct default_delete<T[]>;
|
| 5131 |
template <class T, class D = default_delete<T>> class unique_ptr;
|
| 5132 |
template <class T, class D> class unique_ptr<T[], D>;
|
| 5133 |
|
|
|
|
| 5173 |
template <class T, class D>
|
| 5174 |
bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
|
| 5175 |
template <class T, class D>
|
| 5176 |
bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
|
| 5177 |
|
| 5178 |
+
// [util.smartptr.weak.bad], class bad_weak_ptr
|
| 5179 |
class bad_weak_ptr;
|
| 5180 |
|
| 5181 |
+
// [util.smartptr.shared], class template shared_ptr
|
| 5182 |
template<class T> class shared_ptr;
|
| 5183 |
|
| 5184 |
// [util.smartptr.shared.create], shared_ptr creation
|
| 5185 |
+
template<class T, class... Args>
|
| 5186 |
+
shared_ptr<T> make_shared(Args&&... args);
|
| 5187 |
template<class T, class A, class... Args>
|
| 5188 |
shared_ptr<T> allocate_shared(const A& a, Args&&... args);
|
| 5189 |
|
| 5190 |
+
// [util.smartptr.shared.cmp], shared_ptr comparisons
|
| 5191 |
template<class T, class U>
|
| 5192 |
+
bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 5193 |
template<class T, class U>
|
| 5194 |
+
bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 5195 |
template<class T, class U>
|
| 5196 |
+
bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 5197 |
template<class T, class U>
|
| 5198 |
+
bool operator>(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 5199 |
template<class T, class U>
|
| 5200 |
+
bool operator<=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 5201 |
template<class T, class U>
|
| 5202 |
+
bool operator>=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 5203 |
|
| 5204 |
template <class T>
|
| 5205 |
bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
|
| 5206 |
template <class T>
|
| 5207 |
bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
|
|
|
|
| 5224 |
template <class T>
|
| 5225 |
bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
|
| 5226 |
template <class T>
|
| 5227 |
bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
|
| 5228 |
|
| 5229 |
+
// [util.smartptr.shared.spec], shared_ptr specialized algorithms
|
| 5230 |
+
template<class T>
|
| 5231 |
+
void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
|
| 5232 |
|
| 5233 |
+
// [util.smartptr.shared.cast], shared_ptr casts
|
| 5234 |
template<class T, class U>
|
| 5235 |
+
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 5236 |
template<class T, class U>
|
| 5237 |
+
shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 5238 |
template<class T, class U>
|
| 5239 |
+
shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 5240 |
|
| 5241 |
+
// [util.smartptr.getdeleter], shared_ptr get_deleter
|
| 5242 |
+
template<class D, class T>
|
| 5243 |
+
D* get_deleter(const shared_ptr<T>& p) noexcept;
|
| 5244 |
|
| 5245 |
+
// [util.smartptr.shared.io], shared_ptr I/O
|
| 5246 |
template<class E, class T, class Y>
|
| 5247 |
+
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, const shared_ptr<Y>& p);
|
| 5248 |
|
| 5249 |
+
// [util.smartptr.weak], class template weak_ptr
|
| 5250 |
template<class T> class weak_ptr;
|
| 5251 |
|
| 5252 |
+
// [util.smartptr.weak.spec], weak_ptr specialized algorithms
|
| 5253 |
template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
| 5254 |
|
| 5255 |
+
// [util.smartptr.ownerless], class template owner_less
|
| 5256 |
+
template<class T = void> struct owner_less;
|
| 5257 |
|
| 5258 |
+
// [util.smartptr.enab], class template enable_shared_from_this
|
| 5259 |
template<class T> class enable_shared_from_this;
|
| 5260 |
|
| 5261 |
+
// [util.smartptr.shared.atomic], shared_ptr atomic access
|
| 5262 |
template<class T>
|
| 5263 |
bool atomic_is_lock_free(const shared_ptr<T>* p);
|
| 5264 |
|
| 5265 |
template<class T>
|
| 5266 |
shared_ptr<T> atomic_load(const shared_ptr<T>* p);
|
|
|
|
| 5273 |
void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
|
| 5274 |
|
| 5275 |
template<class T>
|
| 5276 |
shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
|
| 5277 |
template<class T>
|
| 5278 |
+
shared_ptr<T> atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
|
|
|
|
| 5279 |
|
| 5280 |
template<class T>
|
| 5281 |
bool atomic_compare_exchange_weak(
|
| 5282 |
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
|
| 5283 |
template<class T>
|
|
|
|
| 5290 |
template<class T>
|
| 5291 |
bool atomic_compare_exchange_strong_explicit(
|
| 5292 |
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
|
| 5293 |
memory_order success, memory_order failure);
|
| 5294 |
|
| 5295 |
+
// [util.smartptr.hash], hash support
|
| 5296 |
template <class T> struct hash;
|
| 5297 |
template <class T, class D> struct hash<unique_ptr<T, D>>;
|
| 5298 |
template <class T> struct hash<shared_ptr<T>>;
|
| 5299 |
|
| 5300 |
+
// [allocator.uses.trait], uses_allocator
|
| 5301 |
+
template <class T, class Alloc>
|
| 5302 |
+
inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
|
| 5303 |
}
|
| 5304 |
```
|
| 5305 |
|
| 5306 |
### Pointer traits <a id="pointer.traits">[[pointer.traits]]</a>
|
| 5307 |
|
|
|
|
| 5309 |
certain attributes of pointer-like types.
|
| 5310 |
|
| 5311 |
``` cpp
|
| 5312 |
namespace std {
|
| 5313 |
template <class Ptr> struct pointer_traits {
|
| 5314 |
+
using pointer = Ptr;
|
| 5315 |
+
using element_type = see below;
|
| 5316 |
+
using difference_type = see below;
|
| 5317 |
|
| 5318 |
template <class U> using rebind = see below;
|
| 5319 |
|
| 5320 |
static pointer pointer_to(see below r);
|
| 5321 |
};
|
| 5322 |
|
| 5323 |
template <class T> struct pointer_traits<T*> {
|
| 5324 |
+
using pointer = T*;
|
| 5325 |
+
using element_type = T;
|
| 5326 |
+
using difference_type = ptrdiff_t;
|
| 5327 |
|
| 5328 |
template <class U> using rebind = U*;
|
| 5329 |
|
| 5330 |
static pointer pointer_to(see below r) noexcept;
|
| 5331 |
};
|
|
|
|
| 5333 |
```
|
| 5334 |
|
| 5335 |
#### Pointer traits member types <a id="pointer.traits.types">[[pointer.traits.types]]</a>
|
| 5336 |
|
| 5337 |
``` cpp
|
| 5338 |
+
using element_type = see below;
|
| 5339 |
```
|
| 5340 |
|
| 5341 |
+
*Type:* `Ptr::element_type` if the *qualified-id* `Ptr::element_type` is
|
| 5342 |
+
valid and denotes a type ([[temp.deduct]]); otherwise, `T` if `Ptr` is
|
| 5343 |
+
a class template instantiation of the form `SomePointer<T, Args>`, where
|
| 5344 |
+
`Args` is zero or more type arguments; otherwise, the specialization is
|
| 5345 |
+
ill-formed.
|
| 5346 |
|
| 5347 |
``` cpp
|
| 5348 |
+
using difference_type = see below;
|
| 5349 |
```
|
| 5350 |
|
| 5351 |
+
*Type:* `Ptr::difference_type` if the *qualified-id*
|
| 5352 |
+
`Ptr::difference_type` is valid and denotes a type ([[temp.deduct]]);
|
| 5353 |
+
otherwise, `ptrdiff_t`.
|
| 5354 |
|
| 5355 |
``` cpp
|
| 5356 |
template <class U> using rebind = see below;
|
| 5357 |
```
|
| 5358 |
|
| 5359 |
+
*Alias template:* `Ptr::rebind<U>` if the *qualified-id*
|
| 5360 |
+
`Ptr::rebind<U>` is valid and denotes a type ([[temp.deduct]]);
|
| 5361 |
+
otherwise, `SomePointer<U, Args>` if `Ptr` is a class template
|
| 5362 |
+
instantiation of the form `SomePointer<T, Args>`, where `Args` is zero
|
| 5363 |
+
or more type arguments; otherwise, the instantiation of `rebind` is
|
| 5364 |
+
ill-formed.
|
| 5365 |
|
| 5366 |
#### Pointer traits member functions <a id="pointer.traits.functions">[[pointer.traits.functions]]</a>
|
| 5367 |
|
| 5368 |
``` cpp
|
| 5369 |
static pointer pointer_traits::pointer_to(see below r);
|
| 5370 |
static pointer pointer_traits<T*>::pointer_to(see below r) noexcept;
|
| 5371 |
```
|
| 5372 |
|
| 5373 |
+
*Remarks:* If `element_type` is cv `void`, the type of `r` is
|
| 5374 |
unspecified; otherwise, it is `element_type&`.
|
| 5375 |
|
| 5376 |
*Returns:* The first member function returns a pointer to `r` obtained
|
| 5377 |
by calling `Ptr::pointer_to(r)` through which indirection is valid; an
|
| 5378 |
instantiation of this function is ill-formed if `Ptr` does not have a
|
| 5379 |
matching `pointer_to` static member function. The second member function
|
| 5380 |
+
returns `addressof(r)`.
|
| 5381 |
|
| 5382 |
### Pointer safety <a id="util.dynamic.safety">[[util.dynamic.safety]]</a>
|
| 5383 |
|
| 5384 |
A complete object is *declared reachable* while the number of calls to
|
| 5385 |
`declare_reachable` with an argument referencing the object exceeds the
|
|
|
|
| 5394 |
pointer ([[basic.stc.dynamic.safety]]) or a null pointer value.
|
| 5395 |
|
| 5396 |
*Effects:* If `p` is not null, the complete object referenced by `p` is
|
| 5397 |
subsequently declared reachable ([[basic.stc.dynamic.safety]]).
|
| 5398 |
|
| 5399 |
+
*Throws:* May throw `bad_alloc` if the system cannot allocate additional
|
| 5400 |
+
memory that may be required to track objects declared reachable.
|
|
|
|
| 5401 |
|
| 5402 |
``` cpp
|
| 5403 |
template <class T> T* undeclare_reachable(T* p);
|
| 5404 |
```
|
| 5405 |
|
|
|
|
| 5411 |
*Returns:* A safely derived copy of `p` which shall compare equal to
|
| 5412 |
`p`.
|
| 5413 |
|
| 5414 |
*Throws:* Nothing.
|
| 5415 |
|
| 5416 |
+
[*Note 1*: It is expected that calls to `declare_reachable(p)` will
|
| 5417 |
+
consume a small amount of memory in addition to that occupied by the
|
| 5418 |
+
referenced object until the matching call to `undeclare_reachable(p)` is
|
| 5419 |
+
encountered. Long running programs should arrange that calls are
|
| 5420 |
+
matched. — *end note*]
|
| 5421 |
|
| 5422 |
``` cpp
|
| 5423 |
void declare_no_pointers(char* p, size_t n);
|
| 5424 |
```
|
| 5425 |
|
| 5426 |
*Requires:* No bytes in the specified range are currently registered
|
| 5427 |
with `declare_no_pointers()`. If the specified range is in an allocated
|
| 5428 |
object, then it must be entirely within a single allocated object. The
|
| 5429 |
object must be live until the corresponding `undeclare_no_pointers()`
|
| 5430 |
+
call.
|
| 5431 |
+
|
| 5432 |
+
[*Note 2*: In a garbage-collecting implementation, the fact that a
|
| 5433 |
+
region in an object is registered with `declare_no_pointers()` should
|
| 5434 |
+
not prevent the object from being collected. — *end note*]
|
| 5435 |
|
| 5436 |
*Effects:* The `n` bytes starting at `p` no longer contain traceable
|
| 5437 |
pointer locations, independent of their type. Hence indirection through
|
| 5438 |
a pointer located there is undefined if the object it points to was
|
| 5439 |
created by global `operator new` and not previously declared reachable.
|
| 5440 |
+
|
| 5441 |
+
[*Note 3*: This may be used to inform a garbage collector or leak
|
| 5442 |
+
detector that this region of memory need not be traced. — *end note*]
|
| 5443 |
|
| 5444 |
*Throws:* Nothing.
|
| 5445 |
|
| 5446 |
+
[*Note 4*: Under some conditions implementations may need to allocate
|
| 5447 |
+
memory. However, the request can be ignored if memory allocation
|
| 5448 |
+
fails. — *end note*]
|
| 5449 |
|
| 5450 |
``` cpp
|
| 5451 |
void undeclare_no_pointers(char* p, size_t n);
|
| 5452 |
```
|
| 5453 |
|
|
|
|
| 5463 |
``` cpp
|
| 5464 |
pointer_safety get_pointer_safety() noexcept;
|
| 5465 |
```
|
| 5466 |
|
| 5467 |
*Returns:* `pointer_safety::strict` if the implementation has strict
|
| 5468 |
+
pointer safety ([[basic.stc.dynamic.safety]]). It is
|
| 5469 |
+
*implementation-defined* whether `get_pointer_safety` returns
|
| 5470 |
+
`pointer_safety::relaxed` or `pointer_safety::preferred` if the
|
| 5471 |
+
implementation has relaxed pointer safety.[^1]
|
| 5472 |
|
| 5473 |
### Align <a id="ptr.align">[[ptr.align]]</a>
|
| 5474 |
|
| 5475 |
``` cpp
|
| 5476 |
+
void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
|
|
|
|
| 5477 |
```
|
| 5478 |
|
| 5479 |
*Effects:* If it is possible to fit `size` bytes of storage aligned by
|
| 5480 |
`alignment` into the buffer pointed to by `ptr` with length `space`, the
|
| 5481 |
+
function updates `ptr` to represent the first possible address of such
|
| 5482 |
storage and decreases `space` by the number of bytes used for alignment.
|
| 5483 |
Otherwise, the function does nothing.
|
| 5484 |
|
| 5485 |
*Requires:*
|
| 5486 |
|
| 5487 |
+
- `alignment` shall be a power of two
|
| 5488 |
+
- `ptr` shall represent the address of contiguous storage of at least
|
| 5489 |
+
`space` bytes
|
| 5490 |
|
| 5491 |
*Returns:* A null pointer if the requested aligned buffer would not fit
|
| 5492 |
into the available space, otherwise the adjusted value of `ptr`.
|
| 5493 |
|
| 5494 |
+
[*Note 1*: The function updates its `ptr` and `space` arguments so that
|
| 5495 |
+
it can be called repeatedly with possibly different `alignment` and
|
| 5496 |
+
`size` arguments for the same buffer. — *end note*]
|
| 5497 |
|
| 5498 |
### Allocator argument tag <a id="allocator.tag">[[allocator.tag]]</a>
|
| 5499 |
|
| 5500 |
``` cpp
|
| 5501 |
namespace std {
|
| 5502 |
+
struct allocator_arg_t { explicit allocator_arg_t() = default; };
|
| 5503 |
+
inline constexpr allocator_arg_t allocator_arg{};
|
| 5504 |
}
|
| 5505 |
```
|
| 5506 |
|
| 5507 |
The `allocator_arg_t` struct is an empty structure type used as a unique
|
| 5508 |
type to disambiguate constructor and function overloading. Specifically,
|
|
|
|
| 5517 |
|
| 5518 |
``` cpp
|
| 5519 |
template <class T, class Alloc> struct uses_allocator;
|
| 5520 |
```
|
| 5521 |
|
| 5522 |
+
*Remarks:* Automatically detects whether `T` has a nested
|
| 5523 |
+
`allocator_type` that is convertible from `Alloc`. Meets the
|
| 5524 |
+
`BinaryTypeTrait` requirements ([[meta.rqmts]]). The implementation
|
| 5525 |
+
shall provide a definition that is derived from `true_type` if the
|
| 5526 |
+
*qualified-id* `T::allocator_type` is valid and denotes a
|
| 5527 |
+
type ([[temp.deduct]]) and
|
| 5528 |
+
`is_convertible_v<Alloc, T::allocator_type> != false`, otherwise it
|
| 5529 |
shall be derived from `false_type`. A program may specialize this
|
| 5530 |
template to derive from `true_type` for a user-defined type `T` that
|
| 5531 |
does not have a nested `allocator_type` but nonetheless can be
|
| 5532 |
constructed with an allocator where either:
|
| 5533 |
|
| 5534 |
- the first argument of a constructor has type `allocator_arg_t` and the
|
| 5535 |
second argument has type `Alloc` or
|
| 5536 |
- the last argument of a constructor has type `Alloc`.
|
| 5537 |
|
| 5538 |
+
#### Uses-allocator construction <a id="allocator.uses.construction">[[allocator.uses.construction]]</a>
|
| 5539 |
|
| 5540 |
*Uses-allocator construction* with allocator `Alloc` refers to the
|
| 5541 |
construction of an object `obj` of type `T`, using constructor arguments
|
| 5542 |
`v1, v2, ..., vN` of types `V1, V2, ..., VN`, respectively, and an
|
| 5543 |
allocator `alloc` of type `Alloc`, according to the following rules:
|
| 5544 |
|
| 5545 |
+
- if `uses_allocator_v<T, Alloc>` is `false` and
|
| 5546 |
+
`is_constructible_v<T, V1, V2, ..., VN>` is `true`, then `obj` is
|
| 5547 |
initialized as `obj(v1, v2, ..., vN)`;
|
| 5548 |
+
- otherwise, if `uses_allocator_v<T, Alloc>` is `true` and
|
| 5549 |
+
`is_constructible_v<T, allocator_arg_t, Alloc,` `V1, V2, ..., VN>` is
|
| 5550 |
+
`true`, then `obj` is initialized as `obj(allocator_arg, alloc, v1,
|
|
|
|
| 5551 |
v2, ..., vN)`;
|
| 5552 |
+
- otherwise, if `uses_allocator_v<T, Alloc>` is `true` and
|
| 5553 |
+
`is_constructible_v<T, V1, V2, ..., VN, Alloc>` is `true`, then `obj`
|
| 5554 |
+
is initialized as `obj(v1, v2, ..., vN, alloc)`;
|
| 5555 |
- otherwise, the request for uses-allocator construction is ill-formed.
|
| 5556 |
+
\[*Note 1*: An error will result if `uses_allocator_v<T, Alloc>` is
|
| 5557 |
+
`true` but the specific constructor does not take an allocator. This
|
| 5558 |
definition prevents a silent failure to pass the allocator to an
|
| 5559 |
+
element. — *end note*]
|
| 5560 |
|
| 5561 |
### Allocator traits <a id="allocator.traits">[[allocator.traits]]</a>
|
| 5562 |
|
| 5563 |
The class template `allocator_traits` supplies a uniform interface to
|
| 5564 |
all allocator types. An allocator cannot be a non-class type, however,
|
| 5565 |
+
even if `allocator_traits` supplies the entire required interface.
|
| 5566 |
+
|
| 5567 |
+
[*Note 1*: Thus, it is always possible to create a derived class from
|
| 5568 |
+
an allocator. — *end note*]
|
| 5569 |
|
| 5570 |
``` cpp
|
| 5571 |
namespace std {
|
| 5572 |
template <class Alloc> struct allocator_traits {
|
| 5573 |
+
using allocator_type = Alloc;
|
| 5574 |
|
| 5575 |
+
using value_type = typename Alloc::value_type;
|
| 5576 |
|
| 5577 |
+
using pointer = see below;
|
| 5578 |
+
using const_pointer = see below;
|
| 5579 |
+
using void_pointer = see below;
|
| 5580 |
+
using const_void_pointer = see below;
|
| 5581 |
|
| 5582 |
+
using difference_type = see below;
|
| 5583 |
+
using size_type = see below;
|
| 5584 |
|
| 5585 |
+
using propagate_on_container_copy_assignment = see below;
|
| 5586 |
+
using propagate_on_container_move_assignment = see below;
|
| 5587 |
+
using propagate_on_container_swap = see below;
|
| 5588 |
+
using is_always_equal = see below;
|
| 5589 |
|
| 5590 |
template <class T> using rebind_alloc = see below;
|
| 5591 |
template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
|
| 5592 |
|
| 5593 |
static pointer allocate(Alloc& a, size_type n);
|
|
|
|
| 5609 |
```
|
| 5610 |
|
| 5611 |
#### Allocator traits member types <a id="allocator.traits.types">[[allocator.traits.types]]</a>
|
| 5612 |
|
| 5613 |
``` cpp
|
| 5614 |
+
using pointer = see below;
|
| 5615 |
```
|
| 5616 |
|
| 5617 |
+
*Type:* `Alloc::pointer` if the *qualified-id* `Alloc::pointer` is valid
|
| 5618 |
+
and denotes a type ([[temp.deduct]]); otherwise, `value_type*`.
|
| 5619 |
|
| 5620 |
``` cpp
|
| 5621 |
+
using const_pointer = see below;
|
| 5622 |
```
|
| 5623 |
|
| 5624 |
+
*Type:* `Alloc::const_pointer` if the *qualified-id*
|
| 5625 |
+
`Alloc::const_pointer` is valid and denotes a type ([[temp.deduct]]);
|
| 5626 |
+
otherwise, `pointer_traits<pointer>::rebind<const value_type>`.
|
| 5627 |
|
| 5628 |
``` cpp
|
| 5629 |
+
using void_pointer = see below;
|
| 5630 |
```
|
| 5631 |
|
| 5632 |
+
*Type:* `Alloc::void_pointer` if the *qualified-id*
|
| 5633 |
+
`Alloc::void_pointer` is valid and denotes a type ([[temp.deduct]]);
|
| 5634 |
+
otherwise, `pointer_traits<pointer>::rebind<void>`.
|
| 5635 |
|
| 5636 |
``` cpp
|
| 5637 |
+
using const_void_pointer = see below;
|
| 5638 |
```
|
| 5639 |
|
| 5640 |
+
*Type:* `Alloc::const_void_pointer` if the *qualified-id*
|
| 5641 |
+
`Alloc::const_void_pointer` is valid and denotes a
|
| 5642 |
+
type ([[temp.deduct]]); otherwise,
|
| 5643 |
`pointer_traits<pointer>::rebind<const void>`.
|
| 5644 |
|
| 5645 |
``` cpp
|
| 5646 |
+
using difference_type = see below;
|
| 5647 |
```
|
| 5648 |
|
| 5649 |
+
*Type:* `Alloc::difference_type` if the *qualified-id*
|
| 5650 |
+
`Alloc::difference_type` is valid and denotes a type ([[temp.deduct]]);
|
| 5651 |
+
otherwise, `pointer_traits<pointer>::difference_type`.
|
| 5652 |
|
| 5653 |
``` cpp
|
| 5654 |
+
using size_type = see below;
|
| 5655 |
```
|
| 5656 |
|
| 5657 |
+
*Type:* `Alloc::size_type` if the *qualified-id* `Alloc::size_type` is
|
| 5658 |
+
valid and denotes a type ([[temp.deduct]]); otherwise,
|
| 5659 |
`make_unsigned_t<difference_type>`.
|
| 5660 |
|
| 5661 |
``` cpp
|
| 5662 |
+
using propagate_on_container_copy_assignment = see below;
|
| 5663 |
```
|
| 5664 |
|
| 5665 |
+
*Type:* `Alloc::propagate_on_container_copy_assignment` if the
|
| 5666 |
+
*qualified-id* `Alloc::propagate_on_container_copy_assignment` is valid
|
| 5667 |
+
and denotes a type ([[temp.deduct]]); otherwise `false_type`.
|
| 5668 |
|
| 5669 |
``` cpp
|
| 5670 |
+
using propagate_on_container_move_assignment = see below;
|
| 5671 |
```
|
| 5672 |
|
| 5673 |
+
*Type:* `Alloc::propagate_on_container_move_assignment` if the
|
| 5674 |
+
*qualified-id* `Alloc::propagate_on_container_move_assignment` is valid
|
| 5675 |
+
and denotes a type ([[temp.deduct]]); otherwise `false_type`.
|
| 5676 |
|
| 5677 |
``` cpp
|
| 5678 |
+
using propagate_on_container_swap = see below;
|
| 5679 |
```
|
| 5680 |
|
| 5681 |
+
*Type:* `Alloc::propagate_on_container_swap` if the *qualified-id*
|
| 5682 |
+
`Alloc::propagate_on_container_swap` is valid and denotes a
|
| 5683 |
+
type ([[temp.deduct]]); otherwise `false_type`.
|
| 5684 |
+
|
| 5685 |
+
``` cpp
|
| 5686 |
+
using is_always_equal = see below;
|
| 5687 |
+
```
|
| 5688 |
+
|
| 5689 |
+
*Type:* `Alloc::is_always_equal` if the *qualified-id*
|
| 5690 |
+
`Alloc::is_always_equal` is valid and denotes a type ([[temp.deduct]]);
|
| 5691 |
+
otherwise `is_empty<Alloc>::type`.
|
| 5692 |
|
| 5693 |
``` cpp
|
| 5694 |
template <class T> using rebind_alloc = see below;
|
| 5695 |
```
|
| 5696 |
|
| 5697 |
+
*Alias template:* `Alloc::rebind<T>::other` if the *qualified-id*
|
| 5698 |
+
`Alloc::rebind<T>::other` is valid and denotes a
|
| 5699 |
+
type ([[temp.deduct]]); otherwise, `Alloc<T, Args>` if `Alloc` is a
|
| 5700 |
+
class template instantiation of the form `Alloc<U, Args>`, where `Args`
|
| 5701 |
+
is zero or more type arguments; otherwise, the instantiation of
|
| 5702 |
+
`rebind_alloc` is ill-formed.
|
| 5703 |
|
| 5704 |
#### Allocator traits static member functions <a id="allocator.traits.members">[[allocator.traits.members]]</a>
|
| 5705 |
|
| 5706 |
``` cpp
|
| 5707 |
static pointer allocate(Alloc& a, size_type n);
|
|
|
|
| 5718 |
|
| 5719 |
``` cpp
|
| 5720 |
static void deallocate(Alloc& a, pointer p, size_type n);
|
| 5721 |
```
|
| 5722 |
|
| 5723 |
+
*Effects:* Calls `a.deallocate(p, n)`.
|
| 5724 |
|
| 5725 |
*Throws:* Nothing.
|
| 5726 |
|
| 5727 |
``` cpp
|
| 5728 |
template <class T, class... Args>
|
| 5729 |
static void construct(Alloc& a, T* p, Args&&... args);
|
| 5730 |
```
|
| 5731 |
|
| 5732 |
+
*Effects:* Calls `a.construct(p, std::forward<Args>(args)...)` if that
|
| 5733 |
call is well-formed; otherwise, invokes
|
| 5734 |
`::new (static_cast<void*>(p)) T(std::forward<Args>(args)...)`.
|
| 5735 |
|
| 5736 |
``` cpp
|
| 5737 |
template <class T>
|
| 5738 |
static void destroy(Alloc& a, T* p);
|
| 5739 |
```
|
| 5740 |
|
| 5741 |
+
*Effects:* Calls `a.destroy(p)` if that call is well-formed; otherwise,
|
| 5742 |
invokes `p->~T()`.
|
| 5743 |
|
| 5744 |
``` cpp
|
| 5745 |
static size_type max_size(const Alloc& a) noexcept;
|
| 5746 |
```
|
| 5747 |
|
| 5748 |
*Returns:* `a.max_size()` if that expression is well-formed; otherwise,
|
| 5749 |
+
`numeric_limits<size_type>::max()/sizeof(value_type)`.
|
| 5750 |
|
| 5751 |
``` cpp
|
| 5752 |
static Alloc select_on_container_copy_construction(const Alloc& rhs);
|
| 5753 |
```
|
| 5754 |
|
| 5755 |
*Returns:* `rhs.select_on_container_copy_construction()` if that
|
| 5756 |
expression is well-formed; otherwise, `rhs`.
|
| 5757 |
|
| 5758 |
### The default allocator <a id="default.allocator">[[default.allocator]]</a>
|
| 5759 |
|
| 5760 |
+
All specializations of the default allocator satisfy the allocator
|
| 5761 |
+
completeness requirements ([[allocator.requirements.completeness]]).
|
| 5762 |
+
|
| 5763 |
``` cpp
|
| 5764 |
namespace std {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5765 |
template <class T> class allocator {
|
| 5766 |
public:
|
| 5767 |
+
using value_type = T;
|
| 5768 |
+
using propagate_on_container_move_assignment = true_type;
|
| 5769 |
+
using is_always_equal = true_type;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5770 |
|
| 5771 |
allocator() noexcept;
|
| 5772 |
allocator(const allocator&) noexcept;
|
| 5773 |
template <class U> allocator(const allocator<U>&) noexcept;
|
| 5774 |
~allocator();
|
| 5775 |
|
| 5776 |
+
T* allocate(size_t n);
|
| 5777 |
+
void deallocate(T* p, size_t n);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5778 |
};
|
| 5779 |
}
|
| 5780 |
```
|
| 5781 |
|
| 5782 |
#### `allocator` members <a id="allocator.members">[[allocator.members]]</a>
|
|
|
|
| 5787 |
to these functions that allocate or deallocate a particular unit of
|
| 5788 |
storage shall occur in a single total order, and each such deallocation
|
| 5789 |
call shall happen before the next allocation (if any) in this order.
|
| 5790 |
|
| 5791 |
``` cpp
|
| 5792 |
+
T* allocate(size_t n);
|
| 5793 |
```
|
| 5794 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5795 |
*Returns:* A pointer to the initial element of an array of storage of
|
| 5796 |
size `n` `* sizeof(T)`, aligned appropriately for objects of type `T`.
|
|
|
|
|
|
|
| 5797 |
|
| 5798 |
+
*Remarks:* the storage is obtained by calling
|
| 5799 |
+
`::operator new` ([[new.delete]]), but it is unspecified when or how
|
| 5800 |
+
often this function is called.
|
|
|
|
|
|
|
| 5801 |
|
| 5802 |
*Throws:* `bad_alloc` if the storage cannot be obtained.
|
| 5803 |
|
| 5804 |
``` cpp
|
| 5805 |
+
void deallocate(T* p, size_t n);
|
| 5806 |
```
|
| 5807 |
|
| 5808 |
*Requires:* `p` shall be a pointer value obtained from `allocate()`. `n`
|
| 5809 |
shall equal the value passed as the first argument to the invocation of
|
| 5810 |
allocate which returned `p`.
|
| 5811 |
|
| 5812 |
*Effects:* Deallocates the storage referenced by `p` .
|
| 5813 |
|
| 5814 |
+
*Remarks:* Uses `::operator delete` ([[new.delete]]), but it is
|
|
|
|
| 5815 |
unspecified when this function is called.
|
| 5816 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5817 |
#### `allocator` globals <a id="allocator.globals">[[allocator.globals]]</a>
|
| 5818 |
|
| 5819 |
``` cpp
|
| 5820 |
+
template <class T, class U>
|
| 5821 |
+
bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
|
| 5822 |
```
|
| 5823 |
|
| 5824 |
*Returns:* `true`.
|
| 5825 |
|
| 5826 |
``` cpp
|
| 5827 |
+
template <class T, class U>
|
| 5828 |
+
bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
|
| 5829 |
```
|
| 5830 |
|
| 5831 |
*Returns:* `false`.
|
| 5832 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5833 |
### Specialized algorithms <a id="specialized.algorithms">[[specialized.algorithms]]</a>
|
| 5834 |
|
| 5835 |
+
Throughout this subclause, the names of template parameters are used to
|
| 5836 |
+
express type requirements.
|
| 5837 |
+
|
| 5838 |
+
- If an algorithm’s template parameter is named `InputIterator`, the
|
| 5839 |
+
template argument shall satisfy the requirements of an input
|
| 5840 |
+
iterator ([[input.iterators]]).
|
| 5841 |
+
- If an algorithm’s template parameter is named `ForwardIterator`, the
|
| 5842 |
+
template argument shall satisfy the requirements of a forward
|
| 5843 |
+
iterator ([[forward.iterators]]), and is required to have the
|
| 5844 |
property that no exceptions are thrown from increment, assignment,
|
| 5845 |
+
comparison, or indirection through valid iterators.
|
| 5846 |
+
|
| 5847 |
+
Unless otherwise specified, if an exception is thrown in the following
|
| 5848 |
+
algorithms there are no effects.
|
| 5849 |
|
| 5850 |
#### `addressof` <a id="specialized.addressof">[[specialized.addressof]]</a>
|
| 5851 |
|
| 5852 |
``` cpp
|
| 5853 |
+
template <class T> constexpr T* addressof(T& r) noexcept;
|
| 5854 |
```
|
| 5855 |
|
| 5856 |
*Returns:* The actual address of the object or function referenced by
|
| 5857 |
`r`, even in the presence of an overloaded `operator&`.
|
| 5858 |
|
| 5859 |
+
*Remarks:* An expression `addressof(E)` is a constant
|
| 5860 |
+
subexpression ([[defns.const.subexpr]]) if `E` is an lvalue constant
|
| 5861 |
+
subexpression.
|
| 5862 |
+
|
| 5863 |
+
#### `uninitialized_default_construct` <a id="uninitialized.construct.default">[[uninitialized.construct.default]]</a>
|
| 5864 |
+
|
| 5865 |
+
``` cpp
|
| 5866 |
+
template <class ForwardIterator>
|
| 5867 |
+
void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
|
| 5868 |
+
```
|
| 5869 |
+
|
| 5870 |
+
*Effects:* Equivalent to:
|
| 5871 |
+
|
| 5872 |
+
``` cpp
|
| 5873 |
+
for (; first != last; ++first)
|
| 5874 |
+
::new (static_cast<void*>(addressof(*first)))
|
| 5875 |
+
typename iterator_traits<ForwardIterator>::value_type;
|
| 5876 |
+
```
|
| 5877 |
+
|
| 5878 |
+
``` cpp
|
| 5879 |
+
template <class ForwardIterator, class Size>
|
| 5880 |
+
ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
|
| 5881 |
+
```
|
| 5882 |
+
|
| 5883 |
+
*Effects:* Equivalent to:
|
| 5884 |
+
|
| 5885 |
+
``` cpp
|
| 5886 |
+
for (; n>0; (void)++first, --n)
|
| 5887 |
+
::new (static_cast<void*>(addressof(*first)))
|
| 5888 |
+
typename iterator_traits<ForwardIterator>::value_type;
|
| 5889 |
+
return first;
|
| 5890 |
+
```
|
| 5891 |
+
|
| 5892 |
+
#### `uninitialized_value_construct` <a id="uninitialized.construct.value">[[uninitialized.construct.value]]</a>
|
| 5893 |
+
|
| 5894 |
+
``` cpp
|
| 5895 |
+
template <class ForwardIterator>
|
| 5896 |
+
void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
|
| 5897 |
+
```
|
| 5898 |
+
|
| 5899 |
+
*Effects:* Equivalent to:
|
| 5900 |
+
|
| 5901 |
+
``` cpp
|
| 5902 |
+
for (; first != last; ++first)
|
| 5903 |
+
::new (static_cast<void*>(addressof(*first)))
|
| 5904 |
+
typename iterator_traits<ForwardIterator>::value_type();
|
| 5905 |
+
```
|
| 5906 |
+
|
| 5907 |
+
``` cpp
|
| 5908 |
+
template <class ForwardIterator, class Size>
|
| 5909 |
+
ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
|
| 5910 |
+
```
|
| 5911 |
+
|
| 5912 |
+
*Effects:* Equivalent to:
|
| 5913 |
+
|
| 5914 |
+
``` cpp
|
| 5915 |
+
for (; n>0; (void)++first, --n)
|
| 5916 |
+
::new (static_cast<void*>(addressof(*first)))
|
| 5917 |
+
typename iterator_traits<ForwardIterator>::value_type();
|
| 5918 |
+
return first;
|
| 5919 |
+
```
|
| 5920 |
+
|
| 5921 |
#### `uninitialized_copy` <a id="uninitialized.copy">[[uninitialized.copy]]</a>
|
| 5922 |
|
| 5923 |
``` cpp
|
| 5924 |
template <class InputIterator, class ForwardIterator>
|
| 5925 |
ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
|
| 5926 |
ForwardIterator result);
|
| 5927 |
```
|
| 5928 |
|
| 5929 |
+
*Effects:* As if by:
|
| 5930 |
|
| 5931 |
``` cpp
|
| 5932 |
+
for (; first != last; ++result, (void) ++first)
|
| 5933 |
+
::new (static_cast<void*>(addressof(*result)))
|
| 5934 |
typename iterator_traits<ForwardIterator>::value_type(*first);
|
| 5935 |
```
|
| 5936 |
|
| 5937 |
+
*Returns:* `result`.
|
| 5938 |
|
| 5939 |
``` cpp
|
| 5940 |
template <class InputIterator, class Size, class ForwardIterator>
|
| 5941 |
ForwardIterator uninitialized_copy_n(InputIterator first, Size n,
|
| 5942 |
ForwardIterator result);
|
| 5943 |
```
|
| 5944 |
|
| 5945 |
+
*Effects:* As if by:
|
| 5946 |
|
| 5947 |
``` cpp
|
| 5948 |
+
for ( ; n > 0; ++result, (void) ++first, --n) {
|
| 5949 |
+
::new (static_cast<void*>(addressof(*result)))
|
| 5950 |
typename iterator_traits<ForwardIterator>::value_type(*first);
|
| 5951 |
}
|
| 5952 |
```
|
| 5953 |
|
| 5954 |
+
*Returns:* `result`.
|
| 5955 |
+
|
| 5956 |
+
#### `uninitialized_move` <a id="uninitialized.move">[[uninitialized.move]]</a>
|
| 5957 |
+
|
| 5958 |
+
``` cpp
|
| 5959 |
+
template <class InputIterator, class ForwardIterator>
|
| 5960 |
+
ForwardIterator uninitialized_move(InputIterator first, InputIterator last,
|
| 5961 |
+
ForwardIterator result);
|
| 5962 |
+
```
|
| 5963 |
+
|
| 5964 |
+
*Effects:* Equivalent to:
|
| 5965 |
+
|
| 5966 |
+
``` cpp
|
| 5967 |
+
for (; first != last; (void)++result, ++first)
|
| 5968 |
+
::new (static_cast<void*>(addressof(*result)))
|
| 5969 |
+
typename iterator_traits<ForwardIterator>::value_type(std::move(*first));
|
| 5970 |
+
return result;
|
| 5971 |
+
```
|
| 5972 |
+
|
| 5973 |
+
*Remarks:* If an exception is thrown, some objects in the range
|
| 5974 |
+
\[`first`, `last`) are left in a valid but unspecified state.
|
| 5975 |
+
|
| 5976 |
+
``` cpp
|
| 5977 |
+
template <class InputIterator, class Size, class ForwardIterator>
|
| 5978 |
+
pair<InputIterator, ForwardIterator>
|
| 5979 |
+
uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
|
| 5980 |
+
```
|
| 5981 |
+
|
| 5982 |
+
*Effects:* Equivalent to:
|
| 5983 |
+
|
| 5984 |
+
``` cpp
|
| 5985 |
+
for (; n > 0; ++result, (void) ++first, --n)
|
| 5986 |
+
::new (static_cast<void*>(addressof(*result)))
|
| 5987 |
+
typename iterator_traits<ForwardIterator>::value_type(std::move(*first));
|
| 5988 |
+
return {first,result};
|
| 5989 |
+
```
|
| 5990 |
+
|
| 5991 |
+
*Remarks:* If an exception is thrown, some objects in the range
|
| 5992 |
+
\[`first`, `std::next(first,n)`) are left in a valid but unspecified
|
| 5993 |
+
state.
|
| 5994 |
|
| 5995 |
#### `uninitialized_fill` <a id="uninitialized.fill">[[uninitialized.fill]]</a>
|
| 5996 |
|
| 5997 |
``` cpp
|
| 5998 |
template <class ForwardIterator, class T>
|
| 5999 |
void uninitialized_fill(ForwardIterator first, ForwardIterator last,
|
| 6000 |
const T& x);
|
| 6001 |
```
|
| 6002 |
|
| 6003 |
+
*Effects:* As if by:
|
| 6004 |
|
| 6005 |
``` cpp
|
| 6006 |
for (; first != last; ++first)
|
| 6007 |
+
::new (static_cast<void*>(addressof(*first)))
|
| 6008 |
typename iterator_traits<ForwardIterator>::value_type(x);
|
| 6009 |
```
|
| 6010 |
|
|
|
|
|
|
|
| 6011 |
``` cpp
|
| 6012 |
template <class ForwardIterator, class Size, class T>
|
| 6013 |
ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
|
| 6014 |
```
|
| 6015 |
|
| 6016 |
+
*Effects:* As if by:
|
| 6017 |
|
| 6018 |
``` cpp
|
| 6019 |
for (; n--; ++first)
|
| 6020 |
+
::new (static_cast<void*>(addressof(*first)))
|
| 6021 |
typename iterator_traits<ForwardIterator>::value_type(x);
|
| 6022 |
return first;
|
| 6023 |
```
|
| 6024 |
|
| 6025 |
+
#### `destroy` <a id="specialized.destroy">[[specialized.destroy]]</a>
|
| 6026 |
|
| 6027 |
+
``` cpp
|
| 6028 |
+
template <class T>
|
| 6029 |
+
void destroy_at(T* location);
|
| 6030 |
+
```
|
| 6031 |
|
| 6032 |
+
*Effects:* Equivalent to:
|
|
|
|
| 6033 |
|
| 6034 |
+
``` cpp
|
| 6035 |
+
location->~T();
|
| 6036 |
+
```
|
| 6037 |
|
| 6038 |
+
``` cpp
|
| 6039 |
+
template <class ForwardIterator>
|
| 6040 |
+
void destroy(ForwardIterator first, ForwardIterator last);
|
| 6041 |
+
```
|
| 6042 |
|
| 6043 |
+
*Effects:* Equivalent to:
|
| 6044 |
|
| 6045 |
+
``` cpp
|
| 6046 |
+
for (; first!=last; ++first)
|
| 6047 |
+
destroy_at(addressof(*first));
|
| 6048 |
+
```
|
| 6049 |
+
|
| 6050 |
+
``` cpp
|
| 6051 |
+
template <class ForwardIterator, class Size>
|
| 6052 |
+
ForwardIterator destroy_n(ForwardIterator first, Size n);
|
| 6053 |
+
```
|
| 6054 |
+
|
| 6055 |
+
*Effects:* Equivalent to:
|
| 6056 |
+
|
| 6057 |
+
``` cpp
|
| 6058 |
+
for (; n > 0; (void)++first, --n)
|
| 6059 |
+
destroy_at(addressof(*first));
|
| 6060 |
+
return first;
|
| 6061 |
+
```
|
| 6062 |
+
|
| 6063 |
+
### C library memory allocation <a id="c.malloc">[[c.malloc]]</a>
|
| 6064 |
+
|
| 6065 |
+
[*Note 1*: The header `<cstdlib>` ([[cstdlib.syn]]) declares the
|
| 6066 |
+
functions described in this subclause. — *end note*]
|
| 6067 |
+
|
| 6068 |
+
``` cpp
|
| 6069 |
+
void* aligned_alloc(size_t alignment, size_t size);
|
| 6070 |
+
void* calloc(size_t nmemb, size_t size);
|
| 6071 |
+
void* malloc(size_t size);
|
| 6072 |
+
void* realloc(void* ptr, size_t size);
|
| 6073 |
+
```
|
| 6074 |
+
|
| 6075 |
+
*Effects:* These functions have the semantics specified in the C
|
| 6076 |
+
standard library.
|
| 6077 |
+
|
| 6078 |
+
*Remarks:* These functions do not attempt to allocate storage by calling
|
| 6079 |
+
`::operator new()` ([[support.dynamic]]).
|
| 6080 |
+
|
| 6081 |
+
Storage allocated directly with these functions is implicitly declared
|
| 6082 |
+
reachable (see [[basic.stc.dynamic.safety]]) on allocation, ceases to
|
| 6083 |
+
be declared reachable on deallocation, and need not cease to be declared
|
| 6084 |
+
reachable as the result of an `undeclare_reachable()` call.
|
| 6085 |
+
|
| 6086 |
+
[*Note 1*: This allows existing C libraries to remain unaffected by
|
| 6087 |
+
restrictions on pointers that are not safely derived, at the expense of
|
| 6088 |
+
providing far fewer garbage collection and leak detection options for
|
| 6089 |
+
`malloc()`-allocated objects. It also allows `malloc()` to be
|
| 6090 |
+
implemented with a separate allocation arena, bypassing the normal
|
| 6091 |
`declare_reachable()` implementation. The above functions should never
|
| 6092 |
intentionally be used as a replacement for `declare_reachable()`, and
|
| 6093 |
newly written code is strongly encouraged to treat memory allocated with
|
| 6094 |
+
these functions as though it were allocated with
|
| 6095 |
+
`operator new`. — *end note*]
|
| 6096 |
|
| 6097 |
+
``` cpp
|
| 6098 |
+
void free(void* ptr);
|
| 6099 |
+
```
|
| 6100 |
|
| 6101 |
+
*Effects:* This function has the semantics specified in the C standard
|
| 6102 |
+
library.
|
| 6103 |
|
| 6104 |
+
*Remarks:* This function does not attempt to deallocate storage by
|
| 6105 |
+
calling `::operator delete()`.
|
| 6106 |
+
|
| 6107 |
+
ISO C 7.22.3.
|
| 6108 |
|
| 6109 |
## Smart pointers <a id="smartptr">[[smartptr]]</a>
|
| 6110 |
|
| 6111 |
### Class template `unique_ptr` <a id="unique.ptr">[[unique.ptr]]</a>
|
| 6112 |
|
|
|
|
| 6135 |
- if the pre-transfer *u.d* maintained state, such state has been
|
| 6136 |
transferred to *u2.d*.
|
| 6137 |
|
| 6138 |
As in the case of a reset, *u2* must properly dispose of its
|
| 6139 |
pre-transfer owned object via the pre-transfer associated deleter before
|
| 6140 |
+
the ownership transfer is considered complete.
|
| 6141 |
+
|
| 6142 |
+
[*Note 1*: A deleter’s state need never be copied, only moved or
|
| 6143 |
+
swapped as ownership is transferred. — *end note*]
|
| 6144 |
|
| 6145 |
Each object of a type `U` instantiated from the `unique_ptr` template
|
| 6146 |
specified in this subclause has the strict ownership semantics,
|
| 6147 |
specified above, of a unique pointer. In partial satisfaction of these
|
| 6148 |
semantics, each such `U` is `MoveConstructible` and `MoveAssignable`,
|
| 6149 |
but is not `CopyConstructible` nor `CopyAssignable`. The template
|
| 6150 |
parameter `T` of `unique_ptr` may be an incomplete type.
|
| 6151 |
|
| 6152 |
+
[*Note 2*: The uses of `unique_ptr` include providing exception safety
|
| 6153 |
+
for dynamically allocated memory, passing ownership of dynamically
|
| 6154 |
+
allocated memory to a function, and returning dynamically allocated
|
| 6155 |
+
memory from a function. — *end note*]
|
| 6156 |
|
| 6157 |
``` cpp
|
| 6158 |
namespace std {
|
| 6159 |
template<class T> struct default_delete;
|
| 6160 |
template<class T> struct default_delete<T[]>;
|
|
|
|
| 6243 |
|
| 6244 |
``` cpp
|
| 6245 |
void operator()(T* ptr) const;
|
| 6246 |
```
|
| 6247 |
|
| 6248 |
+
*Effects:* Calls `delete` on `ptr`.
|
| 6249 |
|
| 6250 |
*Remarks:* If `T` is an incomplete type, the program is ill-formed.
|
| 6251 |
|
| 6252 |
##### `default_delete<T[]>` <a id="unique.ptr.dltr.dflt1">[[unique.ptr.dltr.dflt1]]</a>
|
| 6253 |
|
| 6254 |
``` cpp
|
| 6255 |
namespace std {
|
| 6256 |
template <class T> struct default_delete<T[]> {
|
| 6257 |
constexpr default_delete() noexcept = default;
|
| 6258 |
+
template <class U> default_delete(const default_delete<U[]>&) noexcept;
|
| 6259 |
+
template <class U> void operator()(U* ptr) const;
|
| 6260 |
};
|
| 6261 |
}
|
| 6262 |
```
|
| 6263 |
|
| 6264 |
``` cpp
|
| 6265 |
+
template <class U> default_delete(const default_delete<U[]>& other) noexcept;
|
| 6266 |
```
|
| 6267 |
|
| 6268 |
+
*Effects:* constructs a `default_delete` object from another
|
| 6269 |
+
`default_delete<U[]>` object.
|
| 6270 |
|
| 6271 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 6272 |
+
unless `U(*)[]` is convertible to `T(*)[]`.
|
| 6273 |
+
|
| 6274 |
+
``` cpp
|
| 6275 |
+
template <class U> void operator()(U* ptr) const;
|
| 6276 |
+
```
|
| 6277 |
+
|
| 6278 |
+
*Effects:* Calls `delete[]` on `ptr`.
|
| 6279 |
+
|
| 6280 |
+
*Remarks:* If `U` is an incomplete type, the program is ill-formed. This
|
| 6281 |
+
function shall not participate in overload resolution unless `U(*)[]` is
|
| 6282 |
+
convertible to `T(*)[]`.
|
| 6283 |
|
| 6284 |
#### `unique_ptr` for single objects <a id="unique.ptr.single">[[unique.ptr.single]]</a>
|
| 6285 |
|
| 6286 |
``` cpp
|
| 6287 |
namespace std {
|
| 6288 |
template <class T, class D = default_delete<T>> class unique_ptr {
|
| 6289 |
public:
|
| 6290 |
+
using pointer = see below;
|
| 6291 |
+
using element_type = T;
|
| 6292 |
+
using deleter_type = D;
|
| 6293 |
|
| 6294 |
// [unique.ptr.single.ctor], constructors
|
| 6295 |
constexpr unique_ptr() noexcept;
|
| 6296 |
explicit unique_ptr(pointer p) noexcept;
|
| 6297 |
unique_ptr(pointer p, see below d1) noexcept;
|
| 6298 |
unique_ptr(pointer p, see below d2) noexcept;
|
| 6299 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 6300 |
+
constexpr unique_ptr(nullptr_t) noexcept;
|
|
|
|
| 6301 |
template <class U, class E>
|
| 6302 |
unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
|
|
|
|
|
|
| 6303 |
|
| 6304 |
// [unique.ptr.single.dtor], destructor
|
| 6305 |
~unique_ptr();
|
| 6306 |
|
| 6307 |
// [unique.ptr.single.asgn], assignment
|
|
|
|
| 6315 |
pointer get() const noexcept;
|
| 6316 |
deleter_type& get_deleter() noexcept;
|
| 6317 |
const deleter_type& get_deleter() const noexcept;
|
| 6318 |
explicit operator bool() const noexcept;
|
| 6319 |
|
| 6320 |
+
// [unique.ptr.single.modifiers], modifiers
|
| 6321 |
pointer release() noexcept;
|
| 6322 |
void reset(pointer p = pointer()) noexcept;
|
| 6323 |
void swap(unique_ptr& u) noexcept;
|
| 6324 |
|
| 6325 |
// disable copy from lvalue
|
|
|
|
| 6329 |
}
|
| 6330 |
```
|
| 6331 |
|
| 6332 |
The default type for the template parameter `D` is `default_delete`. A
|
| 6333 |
client-supplied template argument `D` shall be a function object type (
|
| 6334 |
+
[[function.objects]]), lvalue reference to function, or lvalue reference
|
| 6335 |
to function object type for which, given a value `d` of type `D` and a
|
| 6336 |
value `ptr` of type `unique_ptr<T, D>::pointer`, the expression `d(ptr)`
|
| 6337 |
is valid and has the effect of disposing of the pointer as appropriate
|
| 6338 |
for that deleter.
|
| 6339 |
|
| 6340 |
If the deleter’s type `D` is not a reference type, `D` shall satisfy the
|
| 6341 |
+
requirements of `Destructible` (Table [[tab:destructible]]).
|
| 6342 |
|
| 6343 |
+
If the *qualified-id* `remove_reference_t<D>::pointer` is valid and
|
| 6344 |
+
denotes a type ([[temp.deduct]]), then `unique_ptr<T,
|
| 6345 |
D>::pointer` shall be a synonym for `remove_reference_t<D>::pointer`.
|
| 6346 |
+
Otherwise `unique_ptr<T, D>::pointer` shall be a synonym for
|
| 6347 |
+
`element_type*`. The type `unique_ptr<T,
|
| 6348 |
D>::pointer` shall satisfy the requirements of `NullablePointer` (
|
| 6349 |
[[nullablepointer.requirements]]).
|
| 6350 |
|
| 6351 |
+
[*Example 1*: Given an allocator type `X` ([[allocator.requirements]])
|
| 6352 |
+
and letting `A` be a synonym for `allocator_traits<X>`, the types
|
| 6353 |
+
`A::pointer`, `A::const_pointer`, `A::void_pointer`, and
|
| 6354 |
+
`A::const_void_pointer` may be used as
|
| 6355 |
+
`unique_ptr<T, D>::pointer`. — *end example*]
|
| 6356 |
|
| 6357 |
##### `unique_ptr` constructors <a id="unique.ptr.single.ctor">[[unique.ptr.single.ctor]]</a>
|
| 6358 |
|
| 6359 |
``` cpp
|
| 6360 |
constexpr unique_ptr() noexcept;
|
| 6361 |
+
constexpr unique_ptr(nullptr_t) noexcept;
|
| 6362 |
```
|
| 6363 |
|
| 6364 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 6365 |
+
(Table [[tab:defaultconstructible]]), and that construction shall not
|
| 6366 |
+
throw an exception.
|
| 6367 |
|
| 6368 |
*Effects:* Constructs a `unique_ptr` object that owns nothing,
|
| 6369 |
value-initializing the stored pointer and the stored deleter.
|
| 6370 |
|
| 6371 |
*Postconditions:* `get() == nullptr`. `get_deleter()` returns a
|
| 6372 |
reference to the stored deleter.
|
| 6373 |
|
| 6374 |
+
*Remarks:* If `is_pointer_v<deleter_type>` is `true` or
|
| 6375 |
+
`is_default_constructible_v<deleter_type>` is `false`, this constructor
|
| 6376 |
+
shall not participate in overload resolution.
|
| 6377 |
|
| 6378 |
``` cpp
|
| 6379 |
explicit unique_ptr(pointer p) noexcept;
|
| 6380 |
```
|
| 6381 |
|
| 6382 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 6383 |
+
(Table [[tab:defaultconstructible]]), and that construction shall not
|
| 6384 |
+
throw an exception.
|
| 6385 |
|
| 6386 |
*Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
|
| 6387 |
stored pointer with `p` and value-initializing the stored deleter.
|
| 6388 |
|
| 6389 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 6390 |
the stored deleter.
|
| 6391 |
|
| 6392 |
+
*Remarks:* If `is_pointer_v<deleter_type>` is `true` or
|
| 6393 |
+
`is_default_constructible_v<deleter_type>` is `false`, this constructor
|
| 6394 |
+
shall not participate in overload resolution. If class template argument
|
| 6395 |
+
deduction ([[over.match.class.deduct]]) would select the function
|
| 6396 |
+
template corresponding to this constructor, then the program is
|
| 6397 |
+
ill-formed.
|
| 6398 |
|
| 6399 |
``` cpp
|
| 6400 |
unique_ptr(pointer p, see below d1) noexcept;
|
| 6401 |
unique_ptr(pointer p, see below d2) noexcept;
|
| 6402 |
```
|
| 6403 |
|
| 6404 |
The signature of these constructors depends upon whether `D` is a
|
| 6405 |
+
reference type. If `D` is a non-reference type `A`, then the signatures
|
| 6406 |
are:
|
| 6407 |
|
| 6408 |
``` cpp
|
| 6409 |
+
unique_ptr(pointer p, const A& d) noexcept;
|
| 6410 |
+
unique_ptr(pointer p, A&& d) noexcept;
|
| 6411 |
```
|
| 6412 |
|
| 6413 |
+
If `D` is an lvalue reference type `A&`, then the signatures are:
|
| 6414 |
|
| 6415 |
``` cpp
|
| 6416 |
+
unique_ptr(pointer p, A& d) noexcept;
|
| 6417 |
+
unique_ptr(pointer p, A&& d) = delete;
|
| 6418 |
```
|
| 6419 |
|
| 6420 |
+
If `D` is an lvalue reference type `const A&`, then the signatures are:
|
| 6421 |
|
| 6422 |
``` cpp
|
| 6423 |
+
unique_ptr(pointer p, const A& d) noexcept;
|
| 6424 |
+
unique_ptr(pointer p, const A&& d) = delete;
|
| 6425 |
```
|
| 6426 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6427 |
*Effects:* Constructs a `unique_ptr` object which owns `p`, initializing
|
| 6428 |
+
the stored pointer with `p` and initializing the deleter from
|
| 6429 |
+
`std::forward<decltype(d)>(d)`.
|
| 6430 |
+
|
| 6431 |
+
*Remarks:* These constructors shall not participate in overload
|
| 6432 |
+
resolution unless `is_constructible_v<D, decltype(d)>` is `true`.
|
| 6433 |
|
| 6434 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 6435 |
the stored deleter. If `D` is a reference type then `get_deleter()`
|
| 6436 |
returns a reference to the lvalue `d`.
|
| 6437 |
|
| 6438 |
+
*Remarks:* If class template argument
|
| 6439 |
+
deduction ([[over.match.class.deduct]]) would select a function
|
| 6440 |
+
template corresponding to either of these constructors, then the program
|
| 6441 |
+
is ill-formed.
|
| 6442 |
+
|
| 6443 |
+
[*Example 1*:
|
| 6444 |
+
|
| 6445 |
``` cpp
|
| 6446 |
D d;
|
| 6447 |
unique_ptr<int, D> p1(new int, D()); // D must be MoveConstructible
|
| 6448 |
unique_ptr<int, D> p2(new int, d); // D must be CopyConstructible
|
| 6449 |
unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d
|
| 6450 |
unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined
|
| 6451 |
// with reference deleter type
|
| 6452 |
```
|
| 6453 |
|
| 6454 |
+
— *end example*]
|
| 6455 |
+
|
| 6456 |
``` cpp
|
| 6457 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 6458 |
```
|
| 6459 |
|
| 6460 |
*Requires:* If `D` is not a reference type, `D` shall satisfy the
|
| 6461 |
+
requirements of `MoveConstructible` (Table [[tab:moveconstructible]]).
|
| 6462 |
Construction of the deleter from an rvalue of type `D` shall not throw
|
| 6463 |
an exception.
|
| 6464 |
|
| 6465 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 6466 |
to `*this`. If `D` is a reference type, this deleter is copy constructed
|
| 6467 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 6468 |
+
`u`’s deleter.
|
| 6469 |
+
|
| 6470 |
+
[*Note 1*: The deleter constructor can be implemented with
|
| 6471 |
+
`std::forward<D>`. — *end note*]
|
| 6472 |
|
| 6473 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 6474 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 6475 |
that was constructed from `u.get_deleter()`. If `D` is a reference type
|
| 6476 |
then `get_deleter()` and `u.get_deleter()` both reference the same
|
|
|
|
| 6495 |
is not a reference type and `E` is implicitly convertible to `D`.
|
| 6496 |
|
| 6497 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 6498 |
to `*this`. If `E` is a reference type, this deleter is copy constructed
|
| 6499 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 6500 |
+
`u`’s deleter.
|
| 6501 |
+
|
| 6502 |
+
[*Note 2*: The deleter constructor can be implemented with
|
| 6503 |
+
`std::forward<E>`. — *end note*]
|
| 6504 |
|
| 6505 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 6506 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 6507 |
that was constructed from `u.get_deleter()`.
|
| 6508 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6509 |
##### `unique_ptr` destructor <a id="unique.ptr.single.dtor">[[unique.ptr.single.dtor]]</a>
|
| 6510 |
|
| 6511 |
``` cpp
|
| 6512 |
~unique_ptr();
|
| 6513 |
```
|
| 6514 |
|
| 6515 |
*Requires:* The expression `get_deleter()(get())` shall be well formed,
|
| 6516 |
+
shall have well-defined behavior, and shall not throw exceptions.
|
| 6517 |
+
|
| 6518 |
+
[*Note 3*: The use of `default_delete` requires `T` to be a complete
|
| 6519 |
+
type. — *end note*]
|
| 6520 |
|
| 6521 |
*Effects:* If `get() == nullptr` there are no effects. Otherwise
|
| 6522 |
`get_deleter()(get())`.
|
| 6523 |
|
| 6524 |
##### `unique_ptr` assignment <a id="unique.ptr.single.asgn">[[unique.ptr.single.asgn]]</a>
|
|
|
|
| 6526 |
``` cpp
|
| 6527 |
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
| 6528 |
```
|
| 6529 |
|
| 6530 |
*Requires:* If `D` is not a reference type, `D` shall satisfy the
|
| 6531 |
+
requirements of `MoveAssignable` (Table [[tab:moveassignable]]) and
|
| 6532 |
assignment of the deleter from an rvalue of type `D` shall not throw an
|
| 6533 |
exception. Otherwise, `D` is a reference type; `remove_reference_t<D>`
|
| 6534 |
shall satisfy the `CopyAssignable` requirements and assignment of the
|
| 6535 |
deleter from an lvalue of type `D` shall not throw an exception.
|
| 6536 |
|
|
|
|
| 6551 |
throw an exception.
|
| 6552 |
|
| 6553 |
*Remarks:* This operator shall not participate in overload resolution
|
| 6554 |
unless:
|
| 6555 |
|
| 6556 |
+
- `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
|
| 6557 |
+
and
|
| 6558 |
+
- `U` is not an array type, and
|
| 6559 |
+
- `is_assignable_v<D&, E&&>` is `true`.
|
| 6560 |
|
| 6561 |
*Effects:* Transfers ownership from `u` to `*this` as if by calling
|
| 6562 |
`reset(u.release())` followed by
|
| 6563 |
`get_deleter() = std::forward<E>(u.get_deleter())`.
|
| 6564 |
|
|
|
|
| 6566 |
|
| 6567 |
``` cpp
|
| 6568 |
unique_ptr& operator=(nullptr_t) noexcept;
|
| 6569 |
```
|
| 6570 |
|
| 6571 |
+
*Effects:* As if by `reset()`.
|
| 6572 |
|
| 6573 |
+
*Postconditions:* `get() == nullptr`.
|
| 6574 |
|
| 6575 |
*Returns:* `*this`.
|
| 6576 |
|
| 6577 |
##### `unique_ptr` observers <a id="unique.ptr.single.observers">[[unique.ptr.single.observers]]</a>
|
| 6578 |
|
|
|
|
| 6590 |
|
| 6591 |
*Requires:* `get() != nullptr`.
|
| 6592 |
|
| 6593 |
*Returns:* `get()`.
|
| 6594 |
|
| 6595 |
+
[*Note 4*: The use of this function typically requires that `T` be a
|
| 6596 |
+
complete type. — *end note*]
|
| 6597 |
|
| 6598 |
``` cpp
|
| 6599 |
pointer get() const noexcept;
|
| 6600 |
```
|
| 6601 |
|
|
|
|
| 6618 |
|
| 6619 |
``` cpp
|
| 6620 |
pointer release() noexcept;
|
| 6621 |
```
|
| 6622 |
|
| 6623 |
+
*Postconditions:* `get() == nullptr`.
|
| 6624 |
|
| 6625 |
*Returns:* The value `get()` had at the start of the call to `release`.
|
| 6626 |
|
| 6627 |
``` cpp
|
| 6628 |
void reset(pointer p = pointer()) noexcept;
|
| 6629 |
```
|
| 6630 |
|
| 6631 |
*Requires:* The expression `get_deleter()(get())` shall be well formed,
|
| 6632 |
shall have well-defined behavior, and shall not throw exceptions.
|
| 6633 |
|
| 6634 |
+
*Effects:* Assigns `p` to the stored pointer, and then if and only if
|
| 6635 |
+
the old value of the stored pointer, `old_p`, was not equal to
|
| 6636 |
+
`nullptr`, calls `get_deleter()(old_p)`.
|
|
|
|
| 6637 |
|
| 6638 |
+
[*Note 5*: The order of these operations is significant because the
|
| 6639 |
+
call to `get_deleter()` may destroy `*this`. — *end note*]
|
| 6640 |
+
|
| 6641 |
+
*Postconditions:* `get() == p`.
|
| 6642 |
+
|
| 6643 |
+
[*Note 6*: The postcondition does not hold if the call to
|
| 6644 |
+
`get_deleter()` destroys `*this` since `this->get()` is no longer a
|
| 6645 |
+
valid expression. — *end note*]
|
| 6646 |
|
| 6647 |
``` cpp
|
| 6648 |
void swap(unique_ptr& u) noexcept;
|
| 6649 |
```
|
| 6650 |
|
|
|
|
| 6659 |
|
| 6660 |
``` cpp
|
| 6661 |
namespace std {
|
| 6662 |
template <class T, class D> class unique_ptr<T[], D> {
|
| 6663 |
public:
|
| 6664 |
+
using pointer = see below;
|
| 6665 |
+
using element_type = T;
|
| 6666 |
+
using deleter_type = D;
|
| 6667 |
|
| 6668 |
// [unique.ptr.runtime.ctor], constructors
|
| 6669 |
constexpr unique_ptr() noexcept;
|
| 6670 |
+
template <class U> explicit unique_ptr(U p) noexcept;
|
| 6671 |
+
template <class U> unique_ptr(U p, see below d) noexcept;
|
| 6672 |
+
template <class U> unique_ptr(U p, see below d) noexcept;
|
| 6673 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 6674 |
+
template <class U, class E>
|
| 6675 |
+
unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
| 6676 |
+
constexpr unique_ptr(nullptr_t) noexcept;
|
| 6677 |
|
| 6678 |
// destructor
|
| 6679 |
~unique_ptr();
|
| 6680 |
|
| 6681 |
// assignment
|
| 6682 |
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
| 6683 |
+
template <class U, class E>
|
| 6684 |
+
unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
|
| 6685 |
unique_ptr& operator=(nullptr_t) noexcept;
|
| 6686 |
|
| 6687 |
// [unique.ptr.runtime.observers], observers
|
| 6688 |
T& operator[](size_t i) const;
|
| 6689 |
pointer get() const noexcept;
|
| 6690 |
deleter_type& get_deleter() noexcept;
|
| 6691 |
const deleter_type& get_deleter() const noexcept;
|
| 6692 |
explicit operator bool() const noexcept;
|
| 6693 |
|
| 6694 |
+
// [unique.ptr.runtime.modifiers], modifiers
|
| 6695 |
pointer release() noexcept;
|
| 6696 |
+
template <class U> void reset(U p) noexcept;
|
| 6697 |
+
void reset(nullptr_t = nullptr) noexcept;
|
|
|
|
| 6698 |
void swap(unique_ptr& u) noexcept;
|
| 6699 |
|
| 6700 |
// disable copy from lvalue
|
| 6701 |
unique_ptr(const unique_ptr&) = delete;
|
| 6702 |
unique_ptr& operator=(const unique_ptr&) = delete;
|
|
|
|
| 6705 |
```
|
| 6706 |
|
| 6707 |
A specialization for array types is provided with a slightly altered
|
| 6708 |
interface.
|
| 6709 |
|
| 6710 |
+
- Conversions between different types of `unique_ptr<T[], D>` that would
|
| 6711 |
+
be disallowed for the corresponding pointer-to-array types, and
|
| 6712 |
+
conversions to or from the non-array forms of `unique_ptr`, produce an
|
| 6713 |
+
ill-formed program.
|
| 6714 |
- Pointers to types derived from `T` are rejected by the constructors,
|
| 6715 |
and by `reset`.
|
| 6716 |
- The observers `operator*` and `operator->` are not provided.
|
| 6717 |
- The indexing observer `operator[]` is provided.
|
| 6718 |
- The default deleter will call `delete[]`.
|
| 6719 |
|
| 6720 |
+
Descriptions are provided below only for members that differ from the
|
| 6721 |
+
primary template.
|
| 6722 |
|
| 6723 |
The template argument `T` shall be a complete type.
|
| 6724 |
|
| 6725 |
##### `unique_ptr` constructors <a id="unique.ptr.runtime.ctor">[[unique.ptr.runtime.ctor]]</a>
|
| 6726 |
|
| 6727 |
``` cpp
|
| 6728 |
+
template <class U> explicit unique_ptr(U p) noexcept;
|
|
|
|
|
|
|
| 6729 |
```
|
| 6730 |
|
| 6731 |
+
This constructor behaves the same as the constructor in the primary
|
| 6732 |
+
template that takes a single parameter of type `pointer` except that it
|
| 6733 |
+
additionally shall not participate in overload resolution unless
|
| 6734 |
+
|
| 6735 |
+
- `U` is the same type as `pointer`, or
|
| 6736 |
+
- `pointer` is the same type as `element_type*`, `U` is a pointer type
|
| 6737 |
+
`V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
|
| 6738 |
+
|
| 6739 |
+
``` cpp
|
| 6740 |
+
template <class U> unique_ptr(U p, see below d) noexcept;
|
| 6741 |
+
template <class U> unique_ptr(U p, see below d) noexcept;
|
| 6742 |
+
```
|
| 6743 |
+
|
| 6744 |
+
These constructors behave the same as the constructors in the primary
|
| 6745 |
+
template that take a parameter of type `pointer` and a second parameter
|
| 6746 |
+
except that they shall not participate in overload resolution unless
|
| 6747 |
+
either
|
| 6748 |
+
|
| 6749 |
+
- `U` is the same type as `pointer`,
|
| 6750 |
+
- `U` is `nullptr_t`, or
|
| 6751 |
+
- `pointer` is the same type as `element_type*`, `U` is a pointer type
|
| 6752 |
+
`V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
|
| 6753 |
+
|
| 6754 |
+
``` cpp
|
| 6755 |
+
template <class U, class E>
|
| 6756 |
+
unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
| 6757 |
+
```
|
| 6758 |
+
|
| 6759 |
+
This constructor behaves the same as in the primary template, except
|
| 6760 |
+
that it shall not participate in overload resolution unless all of the
|
| 6761 |
+
following conditions hold, where `UP` is `unique_ptr<U, E>`:
|
| 6762 |
+
|
| 6763 |
+
- `U` is an array type, and
|
| 6764 |
+
- `pointer` is the same type as `element_type*`, and
|
| 6765 |
+
- `UP::pointer` is the same type as `UP::element_type*`, and
|
| 6766 |
+
- `UP::element_type(*)[]` is convertible to `element_type(*)[]`, and
|
| 6767 |
+
- either `D` is a reference type and `E` is the same type as `D`, or `D`
|
| 6768 |
+
is not a reference type and `E` is implicitly convertible to `D`.
|
| 6769 |
+
|
| 6770 |
+
[*Note 1*: This replaces the overload-resolution specification of the
|
| 6771 |
+
primary template — *end note*]
|
| 6772 |
+
|
| 6773 |
+
##### `unique_ptr` assignment <a id="unique.ptr.runtime.asgn">[[unique.ptr.runtime.asgn]]</a>
|
| 6774 |
+
|
| 6775 |
+
``` cpp
|
| 6776 |
+
template <class U, class E>
|
| 6777 |
+
unique_ptr& operator=(unique_ptr<U, E>&& u)noexcept;
|
| 6778 |
+
```
|
| 6779 |
+
|
| 6780 |
+
This operator behaves the same as in the primary template, except that
|
| 6781 |
+
it shall not participate in overload resolution unless all of the
|
| 6782 |
+
following conditions hold, where `UP` is `unique_ptr<U, E>`:
|
| 6783 |
+
|
| 6784 |
+
- `U` is an array type, and
|
| 6785 |
+
- `pointer` is the same type as `element_type*`, and
|
| 6786 |
+
- `UP::pointer` is the same type as `UP::element_type*`, and
|
| 6787 |
+
- `UP::element_type(*)[]` is convertible to `element_type(*)[]`, and
|
| 6788 |
+
- `is_assignable_v<D&, E&&>` is `true`.
|
| 6789 |
+
|
| 6790 |
+
[*Note 2*: This replaces the overload-resolution specification of the
|
| 6791 |
+
primary template — *end note*]
|
| 6792 |
|
| 6793 |
##### `unique_ptr` observers <a id="unique.ptr.runtime.observers">[[unique.ptr.runtime.observers]]</a>
|
| 6794 |
|
| 6795 |
``` cpp
|
| 6796 |
T& operator[](size_t i) const;
|
|
|
|
| 6802 |
*Returns:* `get()[i]`.
|
| 6803 |
|
| 6804 |
##### `unique_ptr` modifiers <a id="unique.ptr.runtime.modifiers">[[unique.ptr.runtime.modifiers]]</a>
|
| 6805 |
|
| 6806 |
``` cpp
|
| 6807 |
+
void reset(nullptr_t p = nullptr) noexcept;
|
| 6808 |
```
|
| 6809 |
|
| 6810 |
*Effects:* Equivalent to `reset(pointer())`.
|
| 6811 |
|
| 6812 |
+
``` cpp
|
| 6813 |
+
template <class U> void reset(U p) noexcept;
|
| 6814 |
+
```
|
| 6815 |
+
|
| 6816 |
+
This function behaves the same as the `reset` member of the primary
|
| 6817 |
+
template, except that it shall not participate in overload resolution
|
| 6818 |
+
unless either
|
| 6819 |
+
|
| 6820 |
+
- `U` is the same type as `pointer`, or
|
| 6821 |
+
- `pointer` is the same type as `element_type*`, `U` is a pointer type
|
| 6822 |
+
`V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
|
| 6823 |
+
|
| 6824 |
#### `unique_ptr` creation <a id="unique.ptr.create">[[unique.ptr.create]]</a>
|
| 6825 |
|
| 6826 |
``` cpp
|
| 6827 |
template <class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
|
| 6828 |
```
|
|
|
|
| 6852 |
|
| 6853 |
``` cpp
|
| 6854 |
template <class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
|
| 6855 |
```
|
| 6856 |
|
| 6857 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 6858 |
+
unless `is_swappable_v<D>` is `true`.
|
| 6859 |
+
|
| 6860 |
*Effects:* Calls `x.swap(y)`.
|
| 6861 |
|
| 6862 |
``` cpp
|
| 6863 |
template <class T1, class D1, class T2, class D2>
|
| 6864 |
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
|
|
| 6876 |
``` cpp
|
| 6877 |
template <class T1, class D1, class T2, class D2>
|
| 6878 |
bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6879 |
```
|
| 6880 |
|
| 6881 |
+
*Requires:* Let *`CT`* denote
|
|
|
|
|
|
|
|
|
|
| 6882 |
|
| 6883 |
+
``` cpp
|
| 6884 |
+
common_type_t<typename unique_ptr<T1, D1>::pointer,
|
| 6885 |
+
typename unique_ptr<T2, D2>::pointer>
|
| 6886 |
+
```
|
| 6887 |
+
|
| 6888 |
+
Then the specialization `less<`*`CT`*`>` shall be a function object
|
| 6889 |
+
type ([[function.objects]]) that induces a strict weak
|
| 6890 |
+
ordering ([[alg.sorting]]) on the pointer values.
|
| 6891 |
+
|
| 6892 |
+
*Returns:* `less<`*`CT`*`>()(x.get(), y.get())`.
|
| 6893 |
|
| 6894 |
*Remarks:* If `unique_ptr<T1, D1>::pointer` is not implicitly
|
| 6895 |
+
convertible to *`CT`* or `unique_ptr<T2, D2>::pointer` is not implicitly
|
| 6896 |
+
convertible to *`CT`*, the program is ill-formed.
|
| 6897 |
|
| 6898 |
``` cpp
|
| 6899 |
template <class T1, class D1, class T2, class D2>
|
| 6900 |
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6901 |
```
|
|
|
|
| 6980 |
*Returns:* The first function template returns `!(x < nullptr)`. The
|
| 6981 |
second function template returns `!(nullptr < x)`.
|
| 6982 |
|
| 6983 |
### Shared-ownership pointers <a id="util.smartptr">[[util.smartptr]]</a>
|
| 6984 |
|
| 6985 |
+
#### Class `bad_weak_ptr` <a id="util.smartptr.weak.bad">[[util.smartptr.weak.bad]]</a>
|
| 6986 |
|
| 6987 |
``` cpp
|
| 6988 |
namespace std {
|
| 6989 |
+
class bad_weak_ptr : public exception {
|
| 6990 |
public:
|
| 6991 |
bad_weak_ptr() noexcept;
|
| 6992 |
};
|
| 6993 |
+
}
|
| 6994 |
```
|
| 6995 |
|
| 6996 |
An exception of type `bad_weak_ptr` is thrown by the `shared_ptr`
|
| 6997 |
constructor taking a `weak_ptr`.
|
| 6998 |
|
| 6999 |
``` cpp
|
| 7000 |
bad_weak_ptr() noexcept;
|
| 7001 |
```
|
| 7002 |
|
| 7003 |
+
*Postconditions:* `what()` returns an *implementation-defined* NTBS.
|
| 7004 |
|
| 7005 |
#### Class template `shared_ptr` <a id="util.smartptr.shared">[[util.smartptr.shared]]</a>
|
| 7006 |
|
| 7007 |
The `shared_ptr` class template stores a pointer, usually obtained via
|
| 7008 |
`new`. `shared_ptr` implements semantics of shared ownership; the last
|
| 7009 |
remaining owner of the pointer is responsible for destroying the object,
|
| 7010 |
or otherwise releasing the resources associated with the stored pointer.
|
| 7011 |
+
A `shared_ptr` is said to be empty if it does not own a pointer.
|
| 7012 |
|
| 7013 |
``` cpp
|
| 7014 |
namespace std {
|
| 7015 |
template<class T> class shared_ptr {
|
| 7016 |
public:
|
| 7017 |
+
using element_type = remove_extent_t<T>;
|
| 7018 |
+
using weak_type = weak_ptr<T>;
|
| 7019 |
|
| 7020 |
+
// [util.smartptr.shared.const], constructors
|
| 7021 |
constexpr shared_ptr() noexcept;
|
| 7022 |
template<class Y> explicit shared_ptr(Y* p);
|
| 7023 |
template<class Y, class D> shared_ptr(Y* p, D d);
|
| 7024 |
template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
|
| 7025 |
template <class D> shared_ptr(nullptr_t p, D d);
|
| 7026 |
template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
|
| 7027 |
+
template<class Y> shared_ptr(const shared_ptr<Y>& r, element_type* p) noexcept;
|
| 7028 |
shared_ptr(const shared_ptr& r) noexcept;
|
| 7029 |
template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
|
| 7030 |
shared_ptr(shared_ptr&& r) noexcept;
|
| 7031 |
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
|
| 7032 |
template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
|
|
|
|
| 7033 |
template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
|
| 7034 |
+
constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() { }
|
| 7035 |
|
| 7036 |
+
// [util.smartptr.shared.dest], destructor
|
| 7037 |
~shared_ptr();
|
| 7038 |
|
| 7039 |
+
// [util.smartptr.shared.assign], assignment
|
| 7040 |
shared_ptr& operator=(const shared_ptr& r) noexcept;
|
| 7041 |
template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 7042 |
shared_ptr& operator=(shared_ptr&& r) noexcept;
|
| 7043 |
template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r) noexcept;
|
|
|
|
| 7044 |
template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
|
| 7045 |
|
| 7046 |
+
// [util.smartptr.shared.mod], modifiers
|
| 7047 |
void swap(shared_ptr& r) noexcept;
|
| 7048 |
void reset() noexcept;
|
| 7049 |
template<class Y> void reset(Y* p);
|
| 7050 |
template<class Y, class D> void reset(Y* p, D d);
|
| 7051 |
template<class Y, class D, class A> void reset(Y* p, D d, A a);
|
| 7052 |
|
| 7053 |
+
// [util.smartptr.shared.obs], observers
|
| 7054 |
+
element_type* get() const noexcept;
|
| 7055 |
T& operator*() const noexcept;
|
| 7056 |
T* operator->() const noexcept;
|
| 7057 |
+
element_type& operator[](ptrdiff_t i) const;
|
| 7058 |
long use_count() const noexcept;
|
|
|
|
| 7059 |
explicit operator bool() const noexcept;
|
| 7060 |
+
template<class U> bool owner_before(const shared_ptr<U>& b) const noexcept;
|
| 7061 |
+
template<class U> bool owner_before(const weak_ptr<U>& b) const noexcept;
|
| 7062 |
};
|
| 7063 |
|
| 7064 |
+
template<class T> shared_ptr(weak_ptr<T>) -> shared_ptr<T>;
|
| 7065 |
+
template<class T, class D> shared_ptr(unique_ptr<T, D>) -> shared_ptr<T>;
|
| 7066 |
+
|
| 7067 |
// [util.smartptr.shared.create], shared_ptr creation
|
| 7068 |
+
template<class T, class... Args>
|
| 7069 |
+
shared_ptr<T> make_shared(Args&&... args);
|
| 7070 |
template<class T, class A, class... Args>
|
| 7071 |
shared_ptr<T> allocate_shared(const A& a, Args&&... args);
|
| 7072 |
|
| 7073 |
+
// [util.smartptr.shared.cmp], shared_ptr comparisons
|
| 7074 |
template<class T, class U>
|
| 7075 |
bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 7076 |
template<class T, class U>
|
| 7077 |
bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 7078 |
template<class T, class U>
|
|
|
|
| 7107 |
template <class T>
|
| 7108 |
bool operator>=(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 7109 |
template <class T>
|
| 7110 |
bool operator>=(nullptr_t, const shared_ptr<T>& b) noexcept;
|
| 7111 |
|
| 7112 |
+
// [util.smartptr.shared.spec], shared_ptr specialized algorithms
|
| 7113 |
+
template<class T>
|
| 7114 |
+
void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
|
| 7115 |
|
| 7116 |
+
// [util.smartptr.shared.cast], shared_ptr casts
|
| 7117 |
template<class T, class U>
|
| 7118 |
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7119 |
template<class T, class U>
|
| 7120 |
shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7121 |
template<class T, class U>
|
| 7122 |
shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7123 |
+
template<class T, class U>
|
| 7124 |
+
shared_ptr<T> reinterpret_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7125 |
|
| 7126 |
+
// [util.smartptr.getdeleter], shared_ptr get_deleter
|
| 7127 |
+
template<class D, class T>
|
| 7128 |
+
D* get_deleter(const shared_ptr<T>& p) noexcept;
|
| 7129 |
|
| 7130 |
+
// [util.smartptr.shared.io], shared_ptr I/O
|
| 7131 |
template<class E, class T, class Y>
|
| 7132 |
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, const shared_ptr<Y>& p);
|
| 7133 |
+
}
|
| 7134 |
```
|
| 7135 |
|
| 7136 |
Specializations of `shared_ptr` shall be `CopyConstructible`,
|
| 7137 |
`CopyAssignable`, and `LessThanComparable`, allowing their use in
|
| 7138 |
standard containers. Specializations of `shared_ptr` shall be
|
| 7139 |
+
contextually convertible to `bool`, allowing their use in boolean
|
| 7140 |
+
expressions and declarations in conditions. The template parameter `T`
|
| 7141 |
+
of `shared_ptr` may be an incomplete type.
|
| 7142 |
+
|
| 7143 |
+
[*Example 1*:
|
| 7144 |
|
| 7145 |
``` cpp
|
| 7146 |
if (shared_ptr<X> px = dynamic_pointer_cast<X>(py)) {
|
| 7147 |
// do something with px
|
| 7148 |
}
|
| 7149 |
```
|
| 7150 |
|
| 7151 |
+
— *end example*]
|
| 7152 |
+
|
| 7153 |
For purposes of determining the presence of a data race, member
|
| 7154 |
functions shall access and modify only the `shared_ptr` and `weak_ptr`
|
| 7155 |
objects themselves and not objects they refer to. Changes in
|
| 7156 |
`use_count()` do not reflect modifications that can introduce data
|
| 7157 |
races.
|
| 7158 |
|
| 7159 |
+
For the purposes of subclause [[util.smartptr]], a pointer type `Y*` is
|
| 7160 |
+
said to be *compatible with* a pointer type `T*` when either `Y*` is
|
| 7161 |
+
convertible to `T*` or `Y` is `U[N]` and `T` is cv `U[]`.
|
| 7162 |
+
|
| 7163 |
##### `shared_ptr` constructors <a id="util.smartptr.shared.const">[[util.smartptr.shared.const]]</a>
|
| 7164 |
|
| 7165 |
+
In the constructor definitions below, enables `shared_from_this` with
|
| 7166 |
+
`p`, for a pointer `p` of type `Y*`, means that if `Y` has an
|
| 7167 |
+
unambiguous and accessible base class that is a specialization of
|
| 7168 |
+
`enable_shared_from_this` ([[util.smartptr.enab]]), then
|
| 7169 |
+
`remove_cv_t<Y>*` shall be implicitly convertible to `T*` and the
|
| 7170 |
+
constructor evaluates the statement:
|
| 7171 |
+
|
| 7172 |
+
``` cpp
|
| 7173 |
+
if (p != nullptr && p->weak_this.expired())
|
| 7174 |
+
p->weak_this = shared_ptr<remove_cv_t<Y>>(*this, const_cast<remove_cv_t<Y>*>(p));
|
| 7175 |
+
```
|
| 7176 |
+
|
| 7177 |
+
The assignment to the `weak_this` member is not atomic and conflicts
|
| 7178 |
+
with any potentially concurrent access to the same object (
|
| 7179 |
+
[[intro.multithread]]).
|
| 7180 |
+
|
| 7181 |
``` cpp
|
| 7182 |
constexpr shared_ptr() noexcept;
|
| 7183 |
```
|
| 7184 |
|
| 7185 |
+
*Effects:* Constructs an empty `shared_ptr` object.
|
| 7186 |
|
| 7187 |
*Postconditions:* `use_count() == 0 && get() == nullptr`.
|
| 7188 |
|
| 7189 |
``` cpp
|
| 7190 |
template<class Y> explicit shared_ptr(Y* p);
|
| 7191 |
```
|
| 7192 |
|
| 7193 |
+
*Requires:* `Y` shall be a complete type. The expression `delete[] p`,
|
| 7194 |
+
when `T` is an array type, or `delete p`, when `T` is not an array type,
|
| 7195 |
+
shall have well-defined behavior, and shall not throw exceptions.
|
| 7196 |
|
| 7197 |
+
*Effects:* When `T` is not an array type, constructs a `shared_ptr`
|
| 7198 |
+
object that owns the pointer `p`. Otherwise, constructs a `shared_ptr`
|
| 7199 |
+
that owns `p` and a deleter of an unspecified type that calls
|
| 7200 |
+
`delete[] p`. When `T` is not an array type, enables `shared_from_this`
|
| 7201 |
+
with `p`. If an exception is thrown, `delete p` is called when `T` is
|
| 7202 |
+
not an array type, `delete[] p` otherwise.
|
| 7203 |
|
| 7204 |
*Postconditions:* `use_count() == 1 && get() == p`.
|
| 7205 |
|
| 7206 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 7207 |
resource other than memory could not be obtained.
|
| 7208 |
|
| 7209 |
+
*Remarks:* When `T` is an array type, this constructor shall not
|
| 7210 |
+
participate in overload resolution unless the expression `delete[] p` is
|
| 7211 |
+
well-formed and either `T` is `U[N]` and `Y(*)[N]` is convertible to
|
| 7212 |
+
`T*`, or `T` is `U[]` and `Y(*)[]` is convertible to `T*`. When `T` is
|
| 7213 |
+
not an array type, this constructor shall not participate in overload
|
| 7214 |
+
resolution unless the expression `delete p` is well-formed and `Y*` is
|
| 7215 |
+
convertible to `T*`.
|
| 7216 |
|
| 7217 |
``` cpp
|
| 7218 |
template<class Y, class D> shared_ptr(Y* p, D d);
|
| 7219 |
template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
|
| 7220 |
template <class D> shared_ptr(nullptr_t p, D d);
|
| 7221 |
template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
|
| 7222 |
```
|
| 7223 |
|
| 7224 |
+
*Requires:* Construction of `d` and a deleter of type `D` initialized
|
| 7225 |
+
with `std::move(d)` shall not throw exceptions. The expression `d(p)`
|
| 7226 |
+
shall have well-defined behavior and shall not throw exceptions. `A`
|
| 7227 |
+
shall be an allocator ([[allocator.requirements]]).
|
|
|
|
|
|
|
| 7228 |
|
| 7229 |
+
*Effects:* Constructs a `shared_ptr` object that owns the object `p` and
|
| 7230 |
+
the deleter `d`. When `T` is not an array type, the first and second
|
| 7231 |
+
constructors enable `shared_from_this` with `p`. The second and fourth
|
| 7232 |
+
constructors shall use a copy of `a` to allocate memory for internal
|
| 7233 |
+
use. If an exception is thrown, `d(p)` is called.
|
| 7234 |
|
| 7235 |
*Postconditions:* `use_count() == 1 && get() == p`.
|
| 7236 |
|
| 7237 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 7238 |
resource other than memory could not be obtained.
|
| 7239 |
|
| 7240 |
+
*Remarks:* When `T` is an array type, this constructor shall not
|
| 7241 |
+
participate in overload resolution unless `is_move_constructible_v<D>`
|
| 7242 |
+
is `true`, the expression `d(p)` is well-formed, and either `T` is
|
| 7243 |
+
`U[N]` and `Y(*)[N]` is convertible to `T*`, or `T` is `U[]` and
|
| 7244 |
+
`Y(*)[]` is convertible to `T*`. When `T` is not an array type, this
|
| 7245 |
+
constructor shall not participate in overload resolution unless
|
| 7246 |
+
`is_move_constructible_v<D>` is `true`, the expression `d(p)` is
|
| 7247 |
+
well-formed, and `Y*` is convertible to `T*`.
|
| 7248 |
|
| 7249 |
``` cpp
|
| 7250 |
+
template<class Y> shared_ptr(const shared_ptr<Y>& r, element_type* p) noexcept;
|
| 7251 |
```
|
| 7252 |
|
| 7253 |
+
*Effects:* Constructs a `shared_ptr` instance that stores `p` and shares
|
| 7254 |
+
ownership with `r`.
|
| 7255 |
|
| 7256 |
+
*Postconditions:* `get() == p && use_count() == r.use_count()`.
|
| 7257 |
|
| 7258 |
+
[*Note 1*: To avoid the possibility of a dangling pointer, the user of
|
| 7259 |
+
this constructor must ensure that `p` remains valid at least until the
|
| 7260 |
+
ownership group of `r` is destroyed. — *end note*]
|
| 7261 |
|
| 7262 |
+
[*Note 2*: This constructor allows creation of an empty `shared_ptr`
|
| 7263 |
+
instance with a non-null stored pointer. — *end note*]
|
| 7264 |
|
| 7265 |
``` cpp
|
| 7266 |
shared_ptr(const shared_ptr& r) noexcept;
|
| 7267 |
template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
|
| 7268 |
```
|
| 7269 |
|
| 7270 |
+
*Remarks:* The second constructor shall not participate in overload
|
| 7271 |
+
resolution unless `Y*` is compatible with `T*`.
|
| 7272 |
|
| 7273 |
+
*Effects:* If `r` is empty, constructs an empty `shared_ptr` object;
|
| 7274 |
+
otherwise, constructs a `shared_ptr` object that shares ownership with
|
| 7275 |
`r`.
|
| 7276 |
|
| 7277 |
*Postconditions:* `get() == r.get() && use_count() == r.use_count()`.
|
| 7278 |
|
| 7279 |
``` cpp
|
| 7280 |
shared_ptr(shared_ptr&& r) noexcept;
|
| 7281 |
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
|
| 7282 |
```
|
| 7283 |
|
| 7284 |
+
*Remarks:* The second constructor shall not participate in overload
|
| 7285 |
+
resolution unless `Y*` is compatible with `T*`.
|
| 7286 |
|
| 7287 |
+
*Effects:* Move constructs a `shared_ptr` instance from `r`.
|
| 7288 |
|
| 7289 |
*Postconditions:* `*this` shall contain the old value of `r`. `r` shall
|
| 7290 |
+
be empty. `r.get() == nullptr`.
|
| 7291 |
|
| 7292 |
``` cpp
|
| 7293 |
template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
|
| 7294 |
```
|
| 7295 |
|
| 7296 |
+
*Effects:* Constructs a `shared_ptr` object that shares ownership with
|
| 7297 |
+
`r` and stores a copy of the pointer stored in `r`. If an exception is
|
| 7298 |
+
thrown, the constructor has no effect.
|
|
|
|
| 7299 |
|
| 7300 |
*Postconditions:* `use_count() == r.use_count()`.
|
| 7301 |
|
| 7302 |
*Throws:* `bad_weak_ptr` when `r.expired()`.
|
| 7303 |
|
| 7304 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 7305 |
+
unless `Y*` is compatible with `T*`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7306 |
|
| 7307 |
``` cpp
|
| 7308 |
template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
|
| 7309 |
```
|
| 7310 |
|
| 7311 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 7312 |
+
unless `Y*` is compatible with `T*` and `unique_ptr<Y, D>::pointer` is
|
| 7313 |
+
convertible to `element_type*`.
|
| 7314 |
|
| 7315 |
+
*Effects:* If `r.get() == nullptr`, equivalent to `shared_ptr()`.
|
| 7316 |
+
Otherwise, if `D` is not a reference type, equivalent to
|
| 7317 |
+
`shared_ptr(r.release(), r.get_deleter())`. Otherwise, equivalent to
|
| 7318 |
+
`shared_ptr(r.release(), ref(r.get_deleter()))`. If an exception is
|
| 7319 |
+
thrown, the constructor has no effect.
|
| 7320 |
|
| 7321 |
##### `shared_ptr` destructor <a id="util.smartptr.shared.dest">[[util.smartptr.shared.dest]]</a>
|
| 7322 |
|
| 7323 |
``` cpp
|
| 7324 |
~shared_ptr();
|
| 7325 |
```
|
| 7326 |
|
| 7327 |
*Effects:*
|
| 7328 |
|
| 7329 |
+
- If `*this` is empty or shares ownership with another `shared_ptr`
|
| 7330 |
instance (`use_count() > 1`), there are no side effects.
|
| 7331 |
+
- Otherwise, if `*this` owns an object `p` and a deleter `d`, `d(p)` is
|
| 7332 |
+
called.
|
| 7333 |
+
- Otherwise, `*this` owns a pointer `p`, and `delete p` is called.
|
| 7334 |
|
| 7335 |
+
[*Note 1*: Since the destruction of `*this` decreases the number of
|
| 7336 |
+
instances that share ownership with `*this` by one, after `*this` has
|
| 7337 |
+
been destroyed all `shared_ptr` instances that shared ownership with
|
| 7338 |
+
`*this` will report a `use_count()` that is one less than its previous
|
| 7339 |
+
value. — *end note*]
|
| 7340 |
|
| 7341 |
##### `shared_ptr` assignment <a id="util.smartptr.shared.assign">[[util.smartptr.shared.assign]]</a>
|
| 7342 |
|
| 7343 |
``` cpp
|
| 7344 |
shared_ptr& operator=(const shared_ptr& r) noexcept;
|
| 7345 |
template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
|
|
|
| 7346 |
```
|
| 7347 |
|
| 7348 |
*Effects:* Equivalent to `shared_ptr(r).swap(*this)`.
|
| 7349 |
|
| 7350 |
*Returns:* `*this`.
|
| 7351 |
|
| 7352 |
+
[*Note 3*:
|
| 7353 |
+
|
| 7354 |
The use count updates caused by the temporary object construction and
|
| 7355 |
destruction are not observable side effects, so the implementation may
|
| 7356 |
meet the effects (and the implied guarantees) via different means,
|
| 7357 |
without creating a temporary. In particular, in the example:
|
| 7358 |
|
|
|
|
| 7363 |
q = p;
|
| 7364 |
```
|
| 7365 |
|
| 7366 |
both assignments may be no-ops.
|
| 7367 |
|
| 7368 |
+
— *end note*]
|
| 7369 |
+
|
| 7370 |
``` cpp
|
| 7371 |
shared_ptr& operator=(shared_ptr&& r) noexcept;
|
| 7372 |
template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r) noexcept;
|
| 7373 |
```
|
| 7374 |
|
|
|
|
| 7380 |
template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
|
| 7381 |
```
|
| 7382 |
|
| 7383 |
*Effects:* Equivalent to `shared_ptr(std::move(r)).swap(*this)`.
|
| 7384 |
|
| 7385 |
+
*Returns:* `*this`.
|
| 7386 |
|
| 7387 |
##### `shared_ptr` modifiers <a id="util.smartptr.shared.mod">[[util.smartptr.shared.mod]]</a>
|
| 7388 |
|
| 7389 |
``` cpp
|
| 7390 |
void swap(shared_ptr& r) noexcept;
|
|
|
|
| 7417 |
*Effects:* Equivalent to `shared_ptr(p, d, a).swap(*this)`.
|
| 7418 |
|
| 7419 |
##### `shared_ptr` observers <a id="util.smartptr.shared.obs">[[util.smartptr.shared.obs]]</a>
|
| 7420 |
|
| 7421 |
``` cpp
|
| 7422 |
+
element_type* get() const noexcept;
|
| 7423 |
```
|
| 7424 |
|
| 7425 |
+
*Returns:* The stored pointer.
|
| 7426 |
|
| 7427 |
``` cpp
|
| 7428 |
T& operator*() const noexcept;
|
| 7429 |
```
|
| 7430 |
|
| 7431 |
*Requires:* `get() != 0`.
|
| 7432 |
|
| 7433 |
*Returns:* `*get()`.
|
| 7434 |
|
| 7435 |
+
*Remarks:* When `T` is an array type or cv `void`, it is unspecified
|
| 7436 |
+
whether this member function is declared. If it is declared, it is
|
| 7437 |
+
unspecified what its return type is, except that the declaration
|
| 7438 |
+
(although not necessarily the definition) of the function shall be well
|
| 7439 |
+
formed.
|
| 7440 |
|
| 7441 |
``` cpp
|
| 7442 |
T* operator->() const noexcept;
|
| 7443 |
```
|
| 7444 |
|
| 7445 |
*Requires:* `get() != 0`.
|
| 7446 |
|
| 7447 |
*Returns:* `get()`.
|
| 7448 |
|
| 7449 |
+
*Remarks:* When `T` is an array type, it is unspecified whether this
|
| 7450 |
+
member function is declared. If it is declared, it is unspecified what
|
| 7451 |
+
its return type is, except that the declaration (although not
|
| 7452 |
+
necessarily the definition) of the function shall be well formed.
|
| 7453 |
+
|
| 7454 |
+
``` cpp
|
| 7455 |
+
element_type& operator[](ptrdiff_t i) const;
|
| 7456 |
+
```
|
| 7457 |
+
|
| 7458 |
+
*Requires:* `get() != 0 && i >= 0`. If `T` is `U[N]`, `i < N`.
|
| 7459 |
+
|
| 7460 |
+
*Returns:* `get()[i]`.
|
| 7461 |
+
|
| 7462 |
+
*Remarks:* When `T` is not an array type, it is unspecified whether this
|
| 7463 |
+
member function is declared. If it is declared, it is unspecified what
|
| 7464 |
+
its return type is, except that the declaration (although not
|
| 7465 |
+
necessarily the definition) of the function shall be well formed.
|
| 7466 |
+
|
| 7467 |
+
*Throws:* Nothing.
|
| 7468 |
+
|
| 7469 |
``` cpp
|
| 7470 |
long use_count() const noexcept;
|
| 7471 |
```
|
| 7472 |
|
| 7473 |
+
*Returns:* The number of `shared_ptr` objects, `*this` included, that
|
| 7474 |
+
share ownership with `*this`, or `0` when `*this` is empty.
|
| 7475 |
|
| 7476 |
+
*Synchronization:* None.
|
| 7477 |
|
| 7478 |
+
[*Note 4*: `get() == nullptr` does not imply a specific return value of
|
| 7479 |
+
`use_count()`. — *end note*]
|
|
|
|
| 7480 |
|
| 7481 |
+
[*Note 5*: `weak_ptr<T>::lock()` can affect the return value of
|
| 7482 |
+
`use_count()`. — *end note*]
|
| 7483 |
|
| 7484 |
+
[*Note 6*: When multiple threads can affect the return value of
|
| 7485 |
+
`use_count()`, the result should be treated as approximate. In
|
| 7486 |
+
particular, `use_count() == 1` does not imply that accesses through a
|
| 7487 |
+
previously destroyed `shared_ptr` have in any sense
|
| 7488 |
+
completed. — *end note*]
|
| 7489 |
|
| 7490 |
``` cpp
|
| 7491 |
explicit operator bool() const noexcept;
|
| 7492 |
```
|
| 7493 |
|
| 7494 |
*Returns:* `get() != 0`.
|
| 7495 |
|
| 7496 |
``` cpp
|
| 7497 |
+
template<class U> bool owner_before(const shared_ptr<U>& b) const noexcept;
|
| 7498 |
+
template<class U> bool owner_before(const weak_ptr<U>& b) const noexcept;
|
| 7499 |
```
|
| 7500 |
|
| 7501 |
*Returns:* An unspecified value such that
|
| 7502 |
|
| 7503 |
- `x.owner_before(y)` defines a strict weak ordering as defined
|
|
|
|
| 7508 |
ownership or are both empty.
|
| 7509 |
|
| 7510 |
##### `shared_ptr` creation <a id="util.smartptr.shared.create">[[util.smartptr.shared.create]]</a>
|
| 7511 |
|
| 7512 |
``` cpp
|
| 7513 |
+
template<class T, class... Args>
|
| 7514 |
+
shared_ptr<T> make_shared(Args&&... args);
|
| 7515 |
template<class T, class A, class... Args>
|
| 7516 |
shared_ptr<T> allocate_shared(const A& a, Args&&... args);
|
| 7517 |
```
|
| 7518 |
|
| 7519 |
*Requires:* The expression `::new (pv) T(std::forward<Args>(args)...)`,
|
| 7520 |
where `pv` has type `void*` and points to storage suitable to hold an
|
| 7521 |
object of type `T`, shall be well formed. `A` shall be an
|
| 7522 |
+
allocator ([[allocator.requirements]]). The copy constructor and
|
| 7523 |
destructor of `A` shall not throw exceptions.
|
| 7524 |
|
| 7525 |
*Effects:* Allocates memory suitable for an object of type `T` and
|
| 7526 |
+
constructs an object in that memory via the placement *new-expression*
|
| 7527 |
`::new (pv) T(std::forward<Args>(args)...)`. The template
|
| 7528 |
`allocate_shared` uses a copy of `a` to allocate memory. If an exception
|
| 7529 |
is thrown, the functions have no effect.
|
| 7530 |
|
| 7531 |
*Returns:* A `shared_ptr` instance that stores and owns the address of
|
| 7532 |
the newly constructed object of type `T`.
|
| 7533 |
|
| 7534 |
+
*Postconditions:* `get() != 0 && use_count() == 1`.
|
| 7535 |
|
| 7536 |
*Throws:* `bad_alloc`, or an exception thrown from `A::allocate` or from
|
| 7537 |
the constructor of `T`.
|
| 7538 |
|
| 7539 |
+
*Remarks:* The `shared_ptr` constructor called by this function enables
|
| 7540 |
+
`shared_from_this` with the address of the newly constructed object of
|
| 7541 |
+
type `T`. Implementations should perform no more than one memory
|
| 7542 |
+
allocation.
|
| 7543 |
|
| 7544 |
+
[*Note 7*: This provides efficiency equivalent to an intrusive smart
|
| 7545 |
+
pointer. — *end note*]
|
| 7546 |
+
|
| 7547 |
+
[*Note 8*: These functions will typically allocate more memory than
|
| 7548 |
+
`sizeof(T)` to allow for internal bookkeeping structures such as the
|
| 7549 |
+
reference counts. — *end note*]
|
| 7550 |
|
| 7551 |
##### `shared_ptr` comparison <a id="util.smartptr.shared.cmp">[[util.smartptr.shared.cmp]]</a>
|
| 7552 |
|
| 7553 |
``` cpp
|
| 7554 |
+
template<class T, class U>
|
| 7555 |
+
bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 7556 |
```
|
| 7557 |
|
| 7558 |
*Returns:* `a.get() == b.get()`.
|
| 7559 |
|
| 7560 |
``` cpp
|
| 7561 |
+
template<class T, class U>
|
| 7562 |
+
bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 7563 |
```
|
| 7564 |
|
| 7565 |
+
*Returns:* `less<>()(a.get(), b.get())`.
|
|
|
|
| 7566 |
|
| 7567 |
+
[*Note 9*: Defining a comparison function allows `shared_ptr` objects
|
| 7568 |
+
to be used as keys in associative containers. — *end note*]
|
| 7569 |
|
| 7570 |
``` cpp
|
| 7571 |
template <class T>
|
| 7572 |
bool operator==(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 7573 |
template <class T>
|
|
|
|
| 7591 |
template <class T>
|
| 7592 |
bool operator<(nullptr_t, const shared_ptr<T>& a) noexcept;
|
| 7593 |
```
|
| 7594 |
|
| 7595 |
*Returns:* The first function template returns
|
| 7596 |
+
`less<shared_ptr<T>::element_type*>()(a.get(), nullptr)`. The second
|
| 7597 |
+
function template returns
|
| 7598 |
+
`less<shared_ptr<T>::element_type*>()(nullptr, a.get())`.
|
| 7599 |
|
| 7600 |
``` cpp
|
| 7601 |
template <class T>
|
| 7602 |
bool operator>(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 7603 |
template <class T>
|
|
|
|
| 7628 |
second function template returns `!(nullptr < a)`.
|
| 7629 |
|
| 7630 |
##### `shared_ptr` specialized algorithms <a id="util.smartptr.shared.spec">[[util.smartptr.shared.spec]]</a>
|
| 7631 |
|
| 7632 |
``` cpp
|
| 7633 |
+
template<class T>
|
| 7634 |
+
void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
|
| 7635 |
```
|
| 7636 |
|
| 7637 |
*Effects:* Equivalent to `a.swap(b)`.
|
| 7638 |
|
| 7639 |
##### `shared_ptr` casts <a id="util.smartptr.shared.cast">[[util.smartptr.shared.cast]]</a>
|
| 7640 |
|
| 7641 |
``` cpp
|
| 7642 |
+
template<class T, class U>
|
| 7643 |
+
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7644 |
```
|
| 7645 |
|
| 7646 |
+
*Requires:* The expression `static_cast<T*>((U*)0)` shall be well
|
| 7647 |
formed.
|
| 7648 |
|
| 7649 |
+
*Returns:*
|
|
|
|
|
|
|
| 7650 |
|
| 7651 |
+
``` cpp
|
| 7652 |
+
shared_ptr<T>(r, static_cast<typename shared_ptr<T>::element_type*>(r.get()))
|
| 7653 |
+
```
|
| 7654 |
|
| 7655 |
+
[*Note 10*: The seemingly equivalent expression
|
| 7656 |
`shared_ptr<T>(static_cast<T*>(r.get()))` will eventually result in
|
| 7657 |
+
undefined behavior, attempting to delete the same object
|
| 7658 |
+
twice. — *end note*]
|
| 7659 |
|
| 7660 |
``` cpp
|
| 7661 |
+
template<class T, class U>
|
| 7662 |
+
shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7663 |
```
|
| 7664 |
|
| 7665 |
+
*Requires:* The expression `dynamic_cast<T*>((U*)0)` shall be well
|
| 7666 |
formed and shall have well defined behavior.
|
| 7667 |
|
| 7668 |
*Returns:*
|
| 7669 |
|
| 7670 |
+
- When `dynamic_cast<typename shared_ptr<T>::element_type*>(r.get())`
|
| 7671 |
+
returns a nonzero value `p`, `shared_ptr<T>(r, p)`.
|
| 7672 |
+
- Otherwise, `shared_ptr<T>()`.
|
|
|
|
| 7673 |
|
| 7674 |
+
[*Note 11*: The seemingly equivalent expression
|
|
|
|
|
|
|
| 7675 |
`shared_ptr<T>(dynamic_cast<T*>(r.get()))` will eventually result in
|
| 7676 |
+
undefined behavior, attempting to delete the same object
|
| 7677 |
+
twice. — *end note*]
|
| 7678 |
|
| 7679 |
``` cpp
|
| 7680 |
+
template<class T, class U>
|
| 7681 |
+
shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7682 |
```
|
| 7683 |
|
| 7684 |
+
*Requires:* The expression `const_cast<T*>((U*)0)` shall be well formed.
|
|
|
|
| 7685 |
|
| 7686 |
+
*Returns:*
|
|
|
|
|
|
|
| 7687 |
|
| 7688 |
+
``` cpp
|
| 7689 |
+
shared_ptr<T>(r, const_cast<typename shared_ptr<T>::element_type*>(r.get()))
|
| 7690 |
+
```
|
| 7691 |
|
| 7692 |
+
[*Note 12*: The seemingly equivalent expression
|
| 7693 |
`shared_ptr<T>(const_cast<T*>(r.get()))` will eventually result in
|
| 7694 |
+
undefined behavior, attempting to delete the same object
|
| 7695 |
+
twice. — *end note*]
|
| 7696 |
|
| 7697 |
+
``` cpp
|
| 7698 |
+
template<class T, class U>
|
| 7699 |
+
shared_ptr<T> reinterpret_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7700 |
+
```
|
| 7701 |
+
|
| 7702 |
+
*Requires:* The expression `reinterpret_cast<T*>((U*)0)` shall be well
|
| 7703 |
+
formed.
|
| 7704 |
+
|
| 7705 |
+
*Returns:*
|
| 7706 |
+
|
| 7707 |
+
``` cpp
|
| 7708 |
+
shared_ptr<T>(r, reinterpret_cast<typename shared_ptr<T>::element_type*>(r.get()))
|
| 7709 |
+
```
|
| 7710 |
+
|
| 7711 |
+
[*Note 13*: The seemingly equivalent expression
|
| 7712 |
+
`shared_ptr<T>(reinterpret_cast<T*>(r.get()))` will eventually result in
|
| 7713 |
+
undefined behavior, attempting to delete the same object
|
| 7714 |
+
twice. — *end note*]
|
| 7715 |
+
|
| 7716 |
+
##### `get_deleter` <a id="util.smartptr.getdeleter">[[util.smartptr.getdeleter]]</a>
|
| 7717 |
|
| 7718 |
``` cpp
|
| 7719 |
+
template<class D, class T>
|
| 7720 |
+
D* get_deleter(const shared_ptr<T>& p) noexcept;
|
| 7721 |
```
|
| 7722 |
|
| 7723 |
+
*Returns:* If `p` owns a deleter `d` of type cv-unqualified `D`, returns
|
| 7724 |
+
`addressof(d)`; otherwise returns `nullptr`. The returned pointer
|
| 7725 |
+
remains valid as long as there exists a `shared_ptr` instance that owns
|
| 7726 |
+
`d`.
|
| 7727 |
+
|
| 7728 |
+
[*Note 14*: It is unspecified whether the pointer remains valid longer
|
| 7729 |
+
than that. This can happen if the implementation doesn’t destroy the
|
| 7730 |
+
deleter until all `weak_ptr` instances that share ownership with `p`
|
| 7731 |
+
have been destroyed. — *end note*]
|
| 7732 |
|
| 7733 |
##### `shared_ptr` I/O <a id="util.smartptr.shared.io">[[util.smartptr.shared.io]]</a>
|
| 7734 |
|
| 7735 |
``` cpp
|
| 7736 |
template<class E, class T, class Y>
|
| 7737 |
+
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, const shared_ptr<Y>& p);
|
| 7738 |
```
|
| 7739 |
|
| 7740 |
+
*Effects:* As if by: `os << p.get();`
|
| 7741 |
|
| 7742 |
*Returns:* `os`.
|
| 7743 |
|
| 7744 |
#### Class template `weak_ptr` <a id="util.smartptr.weak">[[util.smartptr.weak]]</a>
|
| 7745 |
|
|
|
|
| 7749 |
|
| 7750 |
``` cpp
|
| 7751 |
namespace std {
|
| 7752 |
template<class T> class weak_ptr {
|
| 7753 |
public:
|
| 7754 |
+
using element_type = T;
|
| 7755 |
|
| 7756 |
// [util.smartptr.weak.const], constructors
|
| 7757 |
constexpr weak_ptr() noexcept;
|
| 7758 |
+
template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
|
| 7759 |
+
weak_ptr(const weak_ptr& r) noexcept;
|
| 7760 |
+
template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
|
| 7761 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 7762 |
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
|
| 7763 |
|
| 7764 |
// [util.smartptr.weak.dest], destructor
|
| 7765 |
~weak_ptr();
|
| 7766 |
|
| 7767 |
// [util.smartptr.weak.assign], assignment
|
| 7768 |
+
weak_ptr& operator=(const weak_ptr& r) noexcept;
|
| 7769 |
+
template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r) noexcept;
|
| 7770 |
+
template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 7771 |
weak_ptr& operator=(weak_ptr&& r) noexcept;
|
| 7772 |
template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
|
| 7773 |
|
| 7774 |
// [util.smartptr.weak.mod], modifiers
|
| 7775 |
void swap(weak_ptr& r) noexcept;
|
|
|
|
| 7777 |
|
| 7778 |
// [util.smartptr.weak.obs], observers
|
| 7779 |
long use_count() const noexcept;
|
| 7780 |
bool expired() const noexcept;
|
| 7781 |
shared_ptr<T> lock() const noexcept;
|
| 7782 |
+
template<class U> bool owner_before(const shared_ptr<U>& b) const;
|
| 7783 |
+
template<class U> bool owner_before(const weak_ptr<U>& b) const;
|
| 7784 |
};
|
| 7785 |
|
| 7786 |
+
template<class T> weak_ptr(shared_ptr<T>) -> weak_ptr<T>;
|
| 7787 |
+
|
| 7788 |
+
|
| 7789 |
// [util.smartptr.weak.spec], specialized algorithms
|
| 7790 |
template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
| 7791 |
+
}
|
| 7792 |
```
|
| 7793 |
|
| 7794 |
Specializations of `weak_ptr` shall be `CopyConstructible` and
|
| 7795 |
`CopyAssignable`, allowing their use in standard containers. The
|
| 7796 |
template parameter `T` of `weak_ptr` may be an incomplete type.
|
|
|
|
| 7799 |
|
| 7800 |
``` cpp
|
| 7801 |
constexpr weak_ptr() noexcept;
|
| 7802 |
```
|
| 7803 |
|
| 7804 |
+
*Effects:* Constructs an empty `weak_ptr` object.
|
| 7805 |
|
| 7806 |
*Postconditions:* `use_count() == 0`.
|
| 7807 |
|
| 7808 |
``` cpp
|
| 7809 |
weak_ptr(const weak_ptr& r) noexcept;
|
| 7810 |
template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
|
| 7811 |
template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
|
| 7812 |
```
|
| 7813 |
|
| 7814 |
+
*Remarks:* The second and third constructors shall not participate in
|
| 7815 |
+
overload resolution unless `Y*` is compatible with `T*`.
|
| 7816 |
|
| 7817 |
+
*Effects:* If `r` is empty, constructs an empty `weak_ptr` object;
|
| 7818 |
+
otherwise, constructs a `weak_ptr` object that shares ownership with `r`
|
| 7819 |
+
and stores a copy of the pointer stored in `r`.
|
| 7820 |
|
| 7821 |
*Postconditions:* `use_count() == r.use_count()`.
|
| 7822 |
|
| 7823 |
``` cpp
|
| 7824 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 7825 |
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
|
| 7826 |
```
|
| 7827 |
|
| 7828 |
+
*Remarks:* The second constructor shall not participate in overload
|
| 7829 |
+
resolution unless `Y*` is compatible with `T*`.
|
| 7830 |
|
| 7831 |
+
*Effects:* Move constructs a `weak_ptr` instance from `r`.
|
| 7832 |
|
| 7833 |
*Postconditions:* `*this` shall contain the old value of `r`. `r` shall
|
| 7834 |
+
be empty. `r.use_count() == 0`.
|
| 7835 |
|
| 7836 |
##### `weak_ptr` destructor <a id="util.smartptr.weak.dest">[[util.smartptr.weak.dest]]</a>
|
| 7837 |
|
| 7838 |
``` cpp
|
| 7839 |
~weak_ptr();
|
|
|
|
| 7884 |
|
| 7885 |
``` cpp
|
| 7886 |
long use_count() const noexcept;
|
| 7887 |
```
|
| 7888 |
|
| 7889 |
+
*Returns:* `0` if `*this` is empty; otherwise, the number of
|
| 7890 |
+
`shared_ptr` instances that share ownership with `*this`.
|
|
|
|
|
|
|
| 7891 |
|
| 7892 |
``` cpp
|
| 7893 |
bool expired() const noexcept;
|
| 7894 |
```
|
| 7895 |
|
| 7896 |
*Returns:* `use_count() == 0`.
|
| 7897 |
|
|
|
|
|
|
|
| 7898 |
``` cpp
|
| 7899 |
shared_ptr<T> lock() const noexcept;
|
| 7900 |
```
|
| 7901 |
|
| 7902 |
+
*Returns:* `expired() ? shared_ptr<T>() : shared_ptr<T>(*this)`,
|
| 7903 |
executed atomically.
|
| 7904 |
|
| 7905 |
``` cpp
|
| 7906 |
+
template<class U> bool owner_before(const shared_ptr<U>& b) const;
|
| 7907 |
+
template<class U> bool owner_before(const weak_ptr<U>& b) const;
|
| 7908 |
```
|
| 7909 |
|
| 7910 |
*Returns:* An unspecified value such that
|
| 7911 |
|
| 7912 |
- `x.owner_before(y)` defines a strict weak ordering as defined
|
|
|
|
| 7917 |
ownership or are both empty.
|
| 7918 |
|
| 7919 |
##### `weak_ptr` specialized algorithms <a id="util.smartptr.weak.spec">[[util.smartptr.weak.spec]]</a>
|
| 7920 |
|
| 7921 |
``` cpp
|
| 7922 |
+
template<class T>
|
| 7923 |
+
void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
| 7924 |
```
|
| 7925 |
|
| 7926 |
*Effects:* Equivalent to `a.swap(b)`.
|
| 7927 |
|
| 7928 |
#### Class template `owner_less` <a id="util.smartptr.ownerless">[[util.smartptr.ownerless]]</a>
|
|
|
|
| 7930 |
The class template `owner_less` allows ownership-based mixed comparisons
|
| 7931 |
of shared and weak pointers.
|
| 7932 |
|
| 7933 |
``` cpp
|
| 7934 |
namespace std {
|
| 7935 |
+
template<class T = void> struct owner_less;
|
| 7936 |
|
| 7937 |
template<class T> struct owner_less<shared_ptr<T>> {
|
| 7938 |
+
bool operator()(const shared_ptr<T>&, const shared_ptr<T>&) const noexcept;
|
| 7939 |
+
bool operator()(const shared_ptr<T>&, const weak_ptr<T>&) const noexcept;
|
| 7940 |
+
bool operator()(const weak_ptr<T>&, const shared_ptr<T>&) const noexcept;
|
|
|
|
|
|
|
|
|
|
| 7941 |
};
|
| 7942 |
|
| 7943 |
template<class T> struct owner_less<weak_ptr<T>> {
|
| 7944 |
+
bool operator()(const weak_ptr<T>&, const weak_ptr<T>&) const noexcept;
|
| 7945 |
+
bool operator()(const shared_ptr<T>&, const weak_ptr<T>&) const noexcept;
|
| 7946 |
+
bool operator()(const weak_ptr<T>&, const shared_ptr<T>&) const noexcept;
|
| 7947 |
+
};
|
| 7948 |
+
|
| 7949 |
+
template<> struct owner_less<void> {
|
| 7950 |
+
template<class T, class U>
|
| 7951 |
+
bool operator()(const shared_ptr<T>&, const shared_ptr<U>&) const noexcept;
|
| 7952 |
+
template<class T, class U>
|
| 7953 |
+
bool operator()(const shared_ptr<T>&, const weak_ptr<U>&) const noexcept;
|
| 7954 |
+
template<class T, class U>
|
| 7955 |
+
bool operator()(const weak_ptr<T>&, const shared_ptr<U>&) const noexcept;
|
| 7956 |
+
template<class T, class U>
|
| 7957 |
+
bool operator()(const weak_ptr<T>&, const weak_ptr<U>&) const noexcept;
|
| 7958 |
+
|
| 7959 |
+
using is_transparent = unspecified;
|
| 7960 |
};
|
| 7961 |
}
|
| 7962 |
```
|
| 7963 |
|
| 7964 |
+
`operator()(x, y)` shall return `x.owner_before(y)`.
|
| 7965 |
+
|
| 7966 |
+
[*Note 1*:
|
| 7967 |
+
|
| 7968 |
+
Note that
|
| 7969 |
|
| 7970 |
- `operator()` defines a strict weak ordering as defined in
|
| 7971 |
[[alg.sorting]];
|
| 7972 |
- under the equivalence relation defined by `operator()`,
|
| 7973 |
`!operator()(a, b) && !operator()(b, a)`, two `shared_ptr` or
|
| 7974 |
`weak_ptr` instances are equivalent if and only if they share
|
| 7975 |
ownership or are both empty.
|
| 7976 |
|
| 7977 |
+
— *end note*]
|
| 7978 |
+
|
| 7979 |
#### Class template `enable_shared_from_this` <a id="util.smartptr.enab">[[util.smartptr.enab]]</a>
|
| 7980 |
|
| 7981 |
A class `T` can inherit from `enable_shared_from_this<T>` to inherit the
|
| 7982 |
+
`shared_from_this` member functions that obtain a `shared_ptr` instance
|
| 7983 |
pointing to `*this`.
|
| 7984 |
|
| 7985 |
+
[*Example 1*:
|
| 7986 |
+
|
| 7987 |
``` cpp
|
| 7988 |
+
struct X: public enable_shared_from_this<X> { };
|
|
|
|
| 7989 |
|
| 7990 |
int main() {
|
| 7991 |
shared_ptr<X> p(new X);
|
| 7992 |
shared_ptr<X> q = p->shared_from_this();
|
| 7993 |
assert(p == q);
|
| 7994 |
+
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
|
| 7995 |
}
|
| 7996 |
```
|
| 7997 |
|
| 7998 |
+
— *end example*]
|
| 7999 |
+
|
| 8000 |
``` cpp
|
| 8001 |
namespace std {
|
| 8002 |
template<class T> class enable_shared_from_this {
|
| 8003 |
protected:
|
| 8004 |
constexpr enable_shared_from_this() noexcept;
|
| 8005 |
+
enable_shared_from_this(const enable_shared_from_this&) noexcept;
|
| 8006 |
+
enable_shared_from_this& operator=(const enable_shared_from_this&) noexcept;
|
| 8007 |
~enable_shared_from_this();
|
| 8008 |
public:
|
| 8009 |
shared_ptr<T> shared_from_this();
|
| 8010 |
shared_ptr<T const> shared_from_this() const;
|
| 8011 |
+
weak_ptr<T> weak_from_this() noexcept;
|
| 8012 |
+
weak_ptr<T const> weak_from_this() const noexcept;
|
| 8013 |
+
private:
|
| 8014 |
+
mutable weak_ptr<T> weak_this; // exposition only
|
| 8015 |
};
|
| 8016 |
+
}
|
| 8017 |
```
|
| 8018 |
|
| 8019 |
The template parameter `T` of `enable_shared_from_this` may be an
|
| 8020 |
incomplete type.
|
| 8021 |
|
| 8022 |
``` cpp
|
| 8023 |
constexpr enable_shared_from_this() noexcept;
|
| 8024 |
enable_shared_from_this(const enable_shared_from_this<T>&) noexcept;
|
| 8025 |
```
|
| 8026 |
|
| 8027 |
+
*Effects:* Value-initializes `weak_this`.
|
| 8028 |
|
| 8029 |
``` cpp
|
| 8030 |
enable_shared_from_this<T>& operator=(const enable_shared_from_this<T>&) noexcept;
|
| 8031 |
```
|
| 8032 |
|
| 8033 |
*Returns:* `*this`.
|
| 8034 |
|
| 8035 |
+
[*Note 1*: `weak_this` is not changed. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8036 |
|
| 8037 |
``` cpp
|
| 8038 |
shared_ptr<T> shared_from_this();
|
| 8039 |
shared_ptr<T const> shared_from_this() const;
|
| 8040 |
```
|
| 8041 |
|
| 8042 |
+
*Returns:* `shared_ptr<T>(weak_this)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8043 |
|
| 8044 |
``` cpp
|
| 8045 |
+
weak_ptr<T> weak_from_this() noexcept;
|
| 8046 |
+
weak_ptr<T const> weak_from_this() const noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8047 |
```
|
| 8048 |
|
| 8049 |
+
*Returns:* `weak_this`.
|
|
|
|
|
|
|
| 8050 |
|
| 8051 |
#### `shared_ptr` atomic access <a id="util.smartptr.shared.atomic">[[util.smartptr.shared.atomic]]</a>
|
| 8052 |
|
| 8053 |
Concurrent access to a `shared_ptr` object from multiple threads does
|
| 8054 |
not introduce a data race if the access is done exclusively via the
|
|
|
|
| 8100 |
void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
|
| 8101 |
```
|
| 8102 |
|
| 8103 |
*Requires:* `p` shall not be null.
|
| 8104 |
|
| 8105 |
+
*Effects:* As if by `atomic_store_explicit(p, r, memory_order_seq_cst)`.
|
| 8106 |
|
| 8107 |
*Throws:* Nothing.
|
| 8108 |
|
| 8109 |
``` cpp
|
| 8110 |
template<class T>
|
|
|
|
| 8114 |
*Requires:* `p` shall not be null.
|
| 8115 |
|
| 8116 |
*Requires:* `mo` shall not be `memory_order_acquire` or
|
| 8117 |
`memory_order_acq_rel`.
|
| 8118 |
|
| 8119 |
+
*Effects:* As if by `p->swap(r)`.
|
| 8120 |
|
| 8121 |
*Throws:* Nothing.
|
| 8122 |
|
| 8123 |
``` cpp
|
| 8124 |
template<class T>
|
|
|
|
| 8131 |
|
| 8132 |
*Throws:* Nothing.
|
| 8133 |
|
| 8134 |
``` cpp
|
| 8135 |
template<class T>
|
| 8136 |
+
shared_ptr<T> atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
|
|
|
|
| 8137 |
```
|
| 8138 |
|
| 8139 |
*Requires:* `p` shall not be null.
|
| 8140 |
|
| 8141 |
+
*Effects:* As if by `p->swap(r)`.
|
| 8142 |
|
| 8143 |
*Returns:* The previous value of `*p`.
|
| 8144 |
|
| 8145 |
*Throws:* Nothing.
|
| 8146 |
|
| 8147 |
``` cpp
|
| 8148 |
template<class T>
|
| 8149 |
+
bool atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
|
|
|
|
| 8150 |
```
|
| 8151 |
|
| 8152 |
*Requires:* `p` shall not be null and `v` shall not be null.
|
| 8153 |
|
| 8154 |
*Returns:*
|
| 8155 |
+
|
| 8156 |
+
``` cpp
|
| 8157 |
+
atomic_compare_exchange_weak_explicit(p, v, w, memory_order_seq_cst, memory_order_seq_cst)
|
| 8158 |
+
```
|
| 8159 |
|
| 8160 |
*Throws:* Nothing.
|
| 8161 |
|
| 8162 |
``` cpp
|
| 8163 |
template<class T>
|
| 8164 |
+
bool atomic_compare_exchange_strong(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
|
|
|
|
| 8165 |
```
|
| 8166 |
|
| 8167 |
+
*Returns:*
|
| 8168 |
+
|
| 8169 |
+
``` cpp
|
| 8170 |
+
atomic_compare_exchange_strong_explicit(p, v, w, memory_order_seq_cst, memory_order_seq_cst)
|
| 8171 |
+
```
|
| 8172 |
|
| 8173 |
``` cpp
|
| 8174 |
template<class T>
|
| 8175 |
bool atomic_compare_exchange_weak_explicit(
|
| 8176 |
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
|
|
|
|
| 8179 |
bool atomic_compare_exchange_strong_explicit(
|
| 8180 |
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
|
| 8181 |
memory_order success, memory_order failure);
|
| 8182 |
```
|
| 8183 |
|
| 8184 |
+
*Requires:* `p` shall not be null and `v` shall not be null. The
|
| 8185 |
+
`failure` argument shall not be `memory_order_release` nor
|
| 8186 |
+
`memory_order_acq_rel`.
|
|
|
|
| 8187 |
|
| 8188 |
*Effects:* If `*p` is equivalent to `*v`, assigns `w` to `*p` and has
|
| 8189 |
synchronization semantics corresponding to the value of `success`,
|
| 8190 |
otherwise assigns `*p` to `*v` and has synchronization semantics
|
| 8191 |
corresponding to the value of `failure`.
|
| 8192 |
|
| 8193 |
*Returns:* `true` if `*p` was equivalent to `*v`, `false` otherwise.
|
| 8194 |
|
| 8195 |
*Throws:* Nothing.
|
| 8196 |
|
| 8197 |
+
*Remarks:* Two `shared_ptr` objects are equivalent if they store the
|
| 8198 |
+
same pointer value and share ownership. The weak form may fail
|
| 8199 |
+
spuriously. See [[atomics.types.operations]].
|
|
|
|
|
|
|
| 8200 |
|
| 8201 |
#### Smart pointer hash support <a id="util.smartptr.hash">[[util.smartptr.hash]]</a>
|
| 8202 |
|
| 8203 |
``` cpp
|
| 8204 |
template <class T, class D> struct hash<unique_ptr<T, D>>;
|
| 8205 |
```
|
| 8206 |
|
| 8207 |
+
Letting `UP` be `unique_ptr<T,D>`, the specialization `hash<UP>` is
|
| 8208 |
+
enabled ([[unord.hash]]) if and only if `hash<typename UP::pointer>` is
|
| 8209 |
+
enabled. When enabled, for an object `p` of type `UP`, `hash<UP>()(p)`
|
| 8210 |
+
shall evaluate to the same value as
|
| 8211 |
+
`hash<typename UP::pointer>()(p.get())`. The member functions are not
|
| 8212 |
+
guaranteed to be `noexcept`.
|
|
|
|
|
|
|
| 8213 |
|
| 8214 |
``` cpp
|
| 8215 |
template <class T> struct hash<shared_ptr<T>>;
|
| 8216 |
```
|
| 8217 |
|
| 8218 |
+
For an object `p` of type `shared_ptr<T>`, `hash<shared_ptr<T>>()(p)`
|
| 8219 |
+
shall evaluate to the same value as
|
| 8220 |
+
`hash<typename shared_ptr<T>::element_type*>()(p.get())`.
|
| 8221 |
+
|
| 8222 |
+
## Memory resources <a id="mem.res">[[mem.res]]</a>
|
| 8223 |
+
|
| 8224 |
+
### Header `<memory_resource>` synopsis <a id="mem.res.syn">[[mem.res.syn]]</a>
|
| 8225 |
+
|
| 8226 |
+
``` cpp
|
| 8227 |
+
namespace std::pmr {
|
| 8228 |
+
// [mem.res.class], class memory_resource
|
| 8229 |
+
class memory_resource;
|
| 8230 |
+
|
| 8231 |
+
bool operator==(const memory_resource& a, const memory_resource& b) noexcept;
|
| 8232 |
+
bool operator!=(const memory_resource& a, const memory_resource& b) noexcept;
|
| 8233 |
+
|
| 8234 |
+
// [mem.poly.allocator.class], class template polymorphic_allocator
|
| 8235 |
+
template <class Tp> class polymorphic_allocator;
|
| 8236 |
+
|
| 8237 |
+
template <class T1, class T2>
|
| 8238 |
+
bool operator==(const polymorphic_allocator<T1>& a,
|
| 8239 |
+
const polymorphic_allocator<T2>& b) noexcept;
|
| 8240 |
+
template <class T1, class T2>
|
| 8241 |
+
bool operator!=(const polymorphic_allocator<T1>& a,
|
| 8242 |
+
const polymorphic_allocator<T2>& b) noexcept;
|
| 8243 |
+
|
| 8244 |
+
// [mem.res.global], global memory resources
|
| 8245 |
+
memory_resource* new_delete_resource() noexcept;
|
| 8246 |
+
memory_resource* null_memory_resource() noexcept;
|
| 8247 |
+
memory_resource* set_default_resource(memory_resource* r) noexcept;
|
| 8248 |
+
memory_resource* get_default_resource() noexcept;
|
| 8249 |
+
|
| 8250 |
+
// [mem.res.pool], pool resource classes
|
| 8251 |
+
struct pool_options;
|
| 8252 |
+
class synchronized_pool_resource;
|
| 8253 |
+
class unsynchronized_pool_resource;
|
| 8254 |
+
class monotonic_buffer_resource;
|
| 8255 |
+
}
|
| 8256 |
+
```
|
| 8257 |
+
|
| 8258 |
+
### Class `memory_resource` <a id="mem.res.class">[[mem.res.class]]</a>
|
| 8259 |
+
|
| 8260 |
+
The `memory_resource` class is an abstract interface to an unbounded set
|
| 8261 |
+
of classes encapsulating memory resources.
|
| 8262 |
+
|
| 8263 |
+
``` cpp
|
| 8264 |
+
class memory_resource {
|
| 8265 |
+
static constexpr size_t max_align = alignof(max_align_t); // exposition only
|
| 8266 |
+
|
| 8267 |
+
public:
|
| 8268 |
+
virtual ~memory_resource();
|
| 8269 |
+
|
| 8270 |
+
void* allocate(size_t bytes, size_t alignment = max_align);
|
| 8271 |
+
void deallocate(void* p, size_t bytes, size_t alignment = max_align);
|
| 8272 |
+
|
| 8273 |
+
bool is_equal(const memory_resource& other) const noexcept;
|
| 8274 |
+
|
| 8275 |
+
private:
|
| 8276 |
+
virtual void* do_allocate(size_t bytes, size_t alignment) = 0;
|
| 8277 |
+
virtual void do_deallocate(void* p, size_t bytes, size_t alignment) = 0;
|
| 8278 |
+
|
| 8279 |
+
virtual bool do_is_equal(const memory_resource& other) const noexcept = 0;
|
| 8280 |
+
};
|
| 8281 |
+
```
|
| 8282 |
+
|
| 8283 |
+
#### `memory_resource` public member functions <a id="mem.res.public">[[mem.res.public]]</a>
|
| 8284 |
+
|
| 8285 |
+
``` cpp
|
| 8286 |
+
~memory_resource();
|
| 8287 |
+
```
|
| 8288 |
+
|
| 8289 |
+
*Effects:* Destroys this `memory_resource`.
|
| 8290 |
+
|
| 8291 |
+
``` cpp
|
| 8292 |
+
void* allocate(size_t bytes, size_t alignment = max_align);
|
| 8293 |
+
```
|
| 8294 |
+
|
| 8295 |
+
*Effects:* Equivalent to: `return do_allocate(bytes, alignment);`
|
| 8296 |
+
|
| 8297 |
+
``` cpp
|
| 8298 |
+
void deallocate(void* p, size_t bytes, size_t alignment = max_align);
|
| 8299 |
+
```
|
| 8300 |
+
|
| 8301 |
+
*Effects:* Equivalent to: `do_deallocate(p, bytes, alignment);`
|
| 8302 |
+
|
| 8303 |
+
``` cpp
|
| 8304 |
+
bool is_equal(const memory_resource& other) const noexcept;
|
| 8305 |
+
```
|
| 8306 |
+
|
| 8307 |
+
*Effects:* Equivalent to: `return do_is_equal(other);`
|
| 8308 |
+
|
| 8309 |
+
#### `memory_resource` private virtual member functions <a id="mem.res.private">[[mem.res.private]]</a>
|
| 8310 |
+
|
| 8311 |
+
``` cpp
|
| 8312 |
+
virtual void* do_allocate(size_t bytes, size_t alignment) = 0;
|
| 8313 |
+
```
|
| 8314 |
+
|
| 8315 |
+
*Requires:* `alignment` shall be a power of two.
|
| 8316 |
+
|
| 8317 |
+
*Returns:* A derived class shall implement this function to return a
|
| 8318 |
+
pointer to allocated storage ([[basic.stc.dynamic.deallocation]]) with
|
| 8319 |
+
a size of at least `bytes`. The returned storage is aligned to the
|
| 8320 |
+
specified alignment, if such alignment is supported ([[basic.align]]);
|
| 8321 |
+
otherwise it is aligned to `max_align`.
|
| 8322 |
+
|
| 8323 |
+
*Throws:* A derived class implementation shall throw an appropriate
|
| 8324 |
+
exception if it is unable to allocate memory with the requested size and
|
| 8325 |
+
alignment.
|
| 8326 |
+
|
| 8327 |
+
``` cpp
|
| 8328 |
+
virtual void do_deallocate(void* p, size_t bytes, size_t alignment) = 0;
|
| 8329 |
+
```
|
| 8330 |
+
|
| 8331 |
+
*Requires:* `p` shall have been returned from a prior call to
|
| 8332 |
+
`allocate(bytes, alignment)` on a memory resource equal to `*this`, and
|
| 8333 |
+
the storage at `p` shall not yet have been deallocated.
|
| 8334 |
+
|
| 8335 |
+
*Effects:* A derived class shall implement this function to dispose of
|
| 8336 |
+
allocated storage.
|
| 8337 |
+
|
| 8338 |
+
*Throws:* Nothing.
|
| 8339 |
+
|
| 8340 |
+
``` cpp
|
| 8341 |
+
virtual bool do_is_equal(const memory_resource& other) const noexcept = 0;
|
| 8342 |
+
```
|
| 8343 |
+
|
| 8344 |
+
*Returns:* A derived class shall implement this function to return
|
| 8345 |
+
`true` if memory allocated from `this` can be deallocated from `other`
|
| 8346 |
+
and vice-versa, otherwise `false`.
|
| 8347 |
+
|
| 8348 |
+
[*Note 1*: The most-derived type of `other` might not match the type of
|
| 8349 |
+
`this`. For a derived class `D`, a typical implementation of this
|
| 8350 |
+
function will immediately return `false` if
|
| 8351 |
+
`dynamic_cast<const D*>(&other) == nullptr`. — *end note*]
|
| 8352 |
+
|
| 8353 |
+
#### `memory_resource` equality <a id="mem.res.eq">[[mem.res.eq]]</a>
|
| 8354 |
+
|
| 8355 |
+
``` cpp
|
| 8356 |
+
bool operator==(const memory_resource& a, const memory_resource& b) noexcept;
|
| 8357 |
+
```
|
| 8358 |
+
|
| 8359 |
+
*Returns:* `&a == &b || a.is_equal(b)`.
|
| 8360 |
+
|
| 8361 |
+
``` cpp
|
| 8362 |
+
bool operator!=(const memory_resource& a, const memory_resource& b) noexcept;
|
| 8363 |
+
```
|
| 8364 |
+
|
| 8365 |
+
*Returns:* `!(a == b)`.
|
| 8366 |
+
|
| 8367 |
+
### Class template `polymorphic_allocator` <a id="mem.poly.allocator.class">[[mem.poly.allocator.class]]</a>
|
| 8368 |
+
|
| 8369 |
+
A specialization of class template `pmr::polymorphic_allocator` conforms
|
| 8370 |
+
to the `Allocator` requirements ([[allocator.requirements]]).
|
| 8371 |
+
Constructed with different memory resources, different instances of the
|
| 8372 |
+
same specialization of `pmr::polymorphic_allocator` can exhibit entirely
|
| 8373 |
+
different allocation behavior. This runtime polymorphism allows objects
|
| 8374 |
+
that use `polymorphic_allocator` to behave as if they used different
|
| 8375 |
+
allocator types at run time even though they use the same static
|
| 8376 |
+
allocator type.
|
| 8377 |
+
|
| 8378 |
+
``` cpp
|
| 8379 |
+
template <class Tp>
|
| 8380 |
+
class polymorphic_allocator {
|
| 8381 |
+
memory_resource* memory_rsrc; // exposition only
|
| 8382 |
+
|
| 8383 |
+
public:
|
| 8384 |
+
using value_type = Tp;
|
| 8385 |
+
|
| 8386 |
+
// [mem.poly.allocator.ctor], constructors
|
| 8387 |
+
polymorphic_allocator() noexcept;
|
| 8388 |
+
polymorphic_allocator(memory_resource* r);
|
| 8389 |
+
|
| 8390 |
+
polymorphic_allocator(const polymorphic_allocator& other) = default;
|
| 8391 |
+
|
| 8392 |
+
template <class U>
|
| 8393 |
+
polymorphic_allocator(const polymorphic_allocator<U>& other) noexcept;
|
| 8394 |
+
|
| 8395 |
+
polymorphic_allocator&
|
| 8396 |
+
operator=(const polymorphic_allocator& rhs) = delete;
|
| 8397 |
+
|
| 8398 |
+
// [mem.poly.allocator.mem], member functions
|
| 8399 |
+
Tp* allocate(size_t n);
|
| 8400 |
+
void deallocate(Tp* p, size_t n);
|
| 8401 |
+
|
| 8402 |
+
template <class T, class... Args>
|
| 8403 |
+
void construct(T* p, Args&&... args);
|
| 8404 |
+
|
| 8405 |
+
template <class T1, class T2, class... Args1, class... Args2>
|
| 8406 |
+
void construct(pair<T1,T2>* p, piecewise_construct_t,
|
| 8407 |
+
tuple<Args1...> x, tuple<Args2...> y);
|
| 8408 |
+
template <class T1, class T2>
|
| 8409 |
+
void construct(pair<T1,T2>* p);
|
| 8410 |
+
template <class T1, class T2, class U, class V>
|
| 8411 |
+
void construct(pair<T1,T2>* p, U&& x, V&& y);
|
| 8412 |
+
template <class T1, class T2, class U, class V>
|
| 8413 |
+
void construct(pair<T1,T2>* p, const pair<U, V>& pr);
|
| 8414 |
+
template <class T1, class T2, class U, class V>
|
| 8415 |
+
void construct(pair<T1,T2>* p, pair<U, V>&& pr);
|
| 8416 |
+
|
| 8417 |
+
template <class T>
|
| 8418 |
+
void destroy(T* p);
|
| 8419 |
+
|
| 8420 |
+
polymorphic_allocator select_on_container_copy_construction() const;
|
| 8421 |
+
|
| 8422 |
+
memory_resource* resource() const;
|
| 8423 |
+
};
|
| 8424 |
+
```
|
| 8425 |
+
|
| 8426 |
+
#### `polymorphic_allocator` constructors <a id="mem.poly.allocator.ctor">[[mem.poly.allocator.ctor]]</a>
|
| 8427 |
+
|
| 8428 |
+
``` cpp
|
| 8429 |
+
polymorphic_allocator() noexcept;
|
| 8430 |
+
```
|
| 8431 |
+
|
| 8432 |
+
*Effects:* Sets `memory_rsrc` to `get_default_resource()`.
|
| 8433 |
+
|
| 8434 |
+
``` cpp
|
| 8435 |
+
polymorphic_allocator(memory_resource* r);
|
| 8436 |
+
```
|
| 8437 |
+
|
| 8438 |
+
*Requires:* `r` is non-null.
|
| 8439 |
+
|
| 8440 |
+
*Effects:* Sets `memory_rsrc` to `r`.
|
| 8441 |
+
|
| 8442 |
+
*Throws:* Nothing.
|
| 8443 |
+
|
| 8444 |
+
[*Note 1*: This constructor provides an implicit conversion from
|
| 8445 |
+
`memory_resource*`. — *end note*]
|
| 8446 |
+
|
| 8447 |
+
``` cpp
|
| 8448 |
+
template <class U>
|
| 8449 |
+
polymorphic_allocator(const polymorphic_allocator<U>& other) noexcept;
|
| 8450 |
+
```
|
| 8451 |
+
|
| 8452 |
+
*Effects:* Sets `memory_rsrc` to `other.resource()`.
|
| 8453 |
+
|
| 8454 |
+
#### `polymorphic_allocator` member functions <a id="mem.poly.allocator.mem">[[mem.poly.allocator.mem]]</a>
|
| 8455 |
+
|
| 8456 |
+
``` cpp
|
| 8457 |
+
Tp* allocate(size_t n);
|
| 8458 |
+
```
|
| 8459 |
+
|
| 8460 |
+
*Returns:* Equivalent to
|
| 8461 |
+
|
| 8462 |
+
``` cpp
|
| 8463 |
+
return static_cast<Tp*>(memory_rsrc->allocate(n * sizeof(Tp), alignof(Tp)));
|
| 8464 |
+
```
|
| 8465 |
+
|
| 8466 |
+
``` cpp
|
| 8467 |
+
void deallocate(Tp* p, size_t n);
|
| 8468 |
+
```
|
| 8469 |
+
|
| 8470 |
+
*Requires:* `p` was allocated from a memory resource `x`, equal to
|
| 8471 |
+
`*memory_rsrc`, using `x.allocate(n * sizeof(Tp), alignof(Tp))`.
|
| 8472 |
+
|
| 8473 |
+
*Effects:* Equivalent to
|
| 8474 |
+
`memory_rsrc->deallocate(p, n * sizeof(Tp), alignof(Tp))`.
|
| 8475 |
+
|
| 8476 |
+
*Throws:* Nothing.
|
| 8477 |
+
|
| 8478 |
+
``` cpp
|
| 8479 |
+
template <class T, class... Args>
|
| 8480 |
+
void construct(T* p, Args&&... args);
|
| 8481 |
+
```
|
| 8482 |
+
|
| 8483 |
+
*Requires:* Uses-allocator construction of `T` with allocator
|
| 8484 |
+
`resource()` (see [[allocator.uses.construction]]) and constructor
|
| 8485 |
+
arguments `std::forward<Args>(args)...` is well-formed.
|
| 8486 |
+
|
| 8487 |
+
[*Note 1*: Uses-allocator construction is always well formed for types
|
| 8488 |
+
that do not use allocators. — *end note*]
|
| 8489 |
+
|
| 8490 |
+
*Effects:* Construct a `T` object in the storage whose address is
|
| 8491 |
+
represented by `p` by uses-allocator construction with allocator
|
| 8492 |
+
`resource()` and constructor arguments `std::forward<Args>(args)...`.
|
| 8493 |
+
|
| 8494 |
+
*Throws:* Nothing unless the constructor for `T` throws.
|
| 8495 |
+
|
| 8496 |
+
``` cpp
|
| 8497 |
+
template <class T1, class T2, class... Args1, class... Args2>
|
| 8498 |
+
void construct(pair<T1,T2>* p, piecewise_construct_t,
|
| 8499 |
+
tuple<Args1...> x, tuple<Args2...> y);
|
| 8500 |
+
```
|
| 8501 |
+
|
| 8502 |
+
[*Note 2*: This method and the `construct` methods that follow are
|
| 8503 |
+
overloads for piecewise construction of
|
| 8504 |
+
pairs ([[pairs.pair]]). — *end note*]
|
| 8505 |
+
|
| 8506 |
+
*Effects:* Let `xprime` be a `tuple` constructed from `x` according to
|
| 8507 |
+
the appropriate rule from the following list.
|
| 8508 |
+
|
| 8509 |
+
[*Note 3*: The following description can be summarized as constructing
|
| 8510 |
+
a `pair<T1, T2>` object in the storage whose address is represented by
|
| 8511 |
+
`p`, as if by separate uses-allocator construction with allocator
|
| 8512 |
+
`resource()` ([[allocator.uses.construction]]) of `p->first` using the
|
| 8513 |
+
elements of `x` and `p->second` using the elements of
|
| 8514 |
+
`y`. — *end note*]
|
| 8515 |
+
|
| 8516 |
+
- If `uses_allocator_v<T1,memory_resource*>` is `false`
|
| 8517 |
+
and `is_constructible_v<T1,Args1...>` is `true`,
|
| 8518 |
+
then `xprime` is `x`.
|
| 8519 |
+
- Otherwise, if `uses_allocator_v<T1,memory_resource*>` is `true`
|
| 8520 |
+
and `is_constructible_v<T1,allocator_arg_t,memory_resource*,Args1...>`
|
| 8521 |
+
is `true`,
|
| 8522 |
+
then `xprime` is
|
| 8523 |
+
`tuple_cat(make_tuple(allocator_arg, resource()), std::move(x))`.
|
| 8524 |
+
- Otherwise, if `uses_allocator_v<T1,memory_resource*>` is `true`
|
| 8525 |
+
and `is_constructible_v<T1,Args1...,memory_resource*>` is `true`,
|
| 8526 |
+
then `xprime` is `tuple_cat(std::move(x), make_tuple(resource()))`.
|
| 8527 |
+
- Otherwise the program is ill formed.
|
| 8528 |
+
|
| 8529 |
+
Let `yprime` be a tuple constructed from `y` according to the
|
| 8530 |
+
appropriate rule from the following list:
|
| 8531 |
+
|
| 8532 |
+
- If `uses_allocator_v<T2,memory_resource*>` is `false`
|
| 8533 |
+
and `is_constructible_v<T2,Args2...>` is `true`,
|
| 8534 |
+
then `yprime` is `y`.
|
| 8535 |
+
- Otherwise, if `uses_allocator_v<T2,memory_resource*>` is `true`
|
| 8536 |
+
and `is_constructible_v<T2,allocator_arg_t,memory_resource*,Args2...>`
|
| 8537 |
+
is `true`,
|
| 8538 |
+
then `yprime` is
|
| 8539 |
+
`tuple_cat(make_tuple(allocator_arg, resource()), std::move(y))`.
|
| 8540 |
+
- Otherwise, if `uses_allocator_v<T2,memory_resource*>` is `true`
|
| 8541 |
+
and `is_constructible_v<T2,Args2...,memory_resource*>` is `true`,
|
| 8542 |
+
then `yprime` is `tuple_cat(std::move(y), make_tuple(resource()))`.
|
| 8543 |
+
- Otherwise the program is ill formed.
|
| 8544 |
+
|
| 8545 |
+
Then, using `piecewise_construct`, `xprime`, and `yprime` as the
|
| 8546 |
+
constructor arguments, this function constructs a `pair<T1, T2>` object
|
| 8547 |
+
in the storage whose address is represented by `p`.
|
| 8548 |
+
|
| 8549 |
+
``` cpp
|
| 8550 |
+
template <class T1, class T2>
|
| 8551 |
+
void construct(pair<T1,T2>* p);
|
| 8552 |
+
```
|
| 8553 |
+
|
| 8554 |
+
*Effects:* Equivalent to:
|
| 8555 |
+
|
| 8556 |
+
``` cpp
|
| 8557 |
+
construct(p, piecewise_construct, tuple<>(), tuple<>());
|
| 8558 |
+
```
|
| 8559 |
+
|
| 8560 |
+
``` cpp
|
| 8561 |
+
template <class T1, class T2, class U, class V>
|
| 8562 |
+
void construct(pair<T1,T2>* p, U&& x, V&& y);
|
| 8563 |
+
```
|
| 8564 |
+
|
| 8565 |
+
*Effects:* Equivalent to:
|
| 8566 |
+
|
| 8567 |
+
``` cpp
|
| 8568 |
+
construct(p, piecewise_construct,
|
| 8569 |
+
forward_as_tuple(std::forward<U>(x)),
|
| 8570 |
+
forward_as_tuple(std::forward<V>(y)));
|
| 8571 |
+
```
|
| 8572 |
+
|
| 8573 |
+
``` cpp
|
| 8574 |
+
template <class T1, class T2, class U, class V>
|
| 8575 |
+
void construct(pair<T1,T2>* p, const pair<U, V>& pr);
|
| 8576 |
+
```
|
| 8577 |
+
|
| 8578 |
+
*Effects:* Equivalent to:
|
| 8579 |
+
|
| 8580 |
+
``` cpp
|
| 8581 |
+
construct(p, piecewise_construct,
|
| 8582 |
+
forward_as_tuple(pr.first),
|
| 8583 |
+
forward_as_tuple(pr.second));
|
| 8584 |
+
```
|
| 8585 |
+
|
| 8586 |
+
``` cpp
|
| 8587 |
+
template <class T1, class T2, class U, class V>
|
| 8588 |
+
void construct(pair<T1,T2>* p, pair<U, V>&& pr);
|
| 8589 |
+
```
|
| 8590 |
+
|
| 8591 |
+
*Effects:* Equivalent to:
|
| 8592 |
+
|
| 8593 |
+
``` cpp
|
| 8594 |
+
construct(p, piecewise_construct,
|
| 8595 |
+
forward_as_tuple(std::forward<U>(pr.first)),
|
| 8596 |
+
forward_as_tuple(std::forward<V>(pr.second)));
|
| 8597 |
+
```
|
| 8598 |
+
|
| 8599 |
+
``` cpp
|
| 8600 |
+
template <class T>
|
| 8601 |
+
void destroy(T* p);
|
| 8602 |
+
```
|
| 8603 |
+
|
| 8604 |
+
*Effects:* As if by `p->T̃()`.
|
| 8605 |
+
|
| 8606 |
+
``` cpp
|
| 8607 |
+
polymorphic_allocator select_on_container_copy_construction() const;
|
| 8608 |
+
```
|
| 8609 |
+
|
| 8610 |
+
*Returns:* `polymorphic_allocator()`.
|
| 8611 |
+
|
| 8612 |
+
[*Note 4*: The memory resource is not propagated. — *end note*]
|
| 8613 |
+
|
| 8614 |
+
``` cpp
|
| 8615 |
+
memory_resource* resource() const;
|
| 8616 |
+
```
|
| 8617 |
+
|
| 8618 |
+
*Returns:* `memory_rsrc`.
|
| 8619 |
+
|
| 8620 |
+
#### `polymorphic_allocator` equality <a id="mem.poly.allocator.eq">[[mem.poly.allocator.eq]]</a>
|
| 8621 |
+
|
| 8622 |
+
``` cpp
|
| 8623 |
+
template <class T1, class T2>
|
| 8624 |
+
bool operator==(const polymorphic_allocator<T1>& a,
|
| 8625 |
+
const polymorphic_allocator<T2>& b) noexcept;
|
| 8626 |
+
```
|
| 8627 |
+
|
| 8628 |
+
*Returns:* `*a.resource() == *b.resource()`.
|
| 8629 |
+
|
| 8630 |
+
``` cpp
|
| 8631 |
+
template <class T1, class T2>
|
| 8632 |
+
bool operator!=(const polymorphic_allocator<T1>& a,
|
| 8633 |
+
const polymorphic_allocator<T2>& b) noexcept;
|
| 8634 |
+
```
|
| 8635 |
+
|
| 8636 |
+
*Returns:* `!(a == b)`.
|
| 8637 |
+
|
| 8638 |
+
### Access to program-wide `memory_resource` objects <a id="mem.res.global">[[mem.res.global]]</a>
|
| 8639 |
+
|
| 8640 |
+
``` cpp
|
| 8641 |
+
memory_resource* new_delete_resource() noexcept;
|
| 8642 |
+
```
|
| 8643 |
+
|
| 8644 |
+
*Returns:* A pointer to a static-duration object of a type derived from
|
| 8645 |
+
`memory_resource` that can serve as a resource for allocating memory
|
| 8646 |
+
using `::operator new` and `::operator delete`. The same value is
|
| 8647 |
+
returned every time this function is called. For a return value `p` and
|
| 8648 |
+
a memory resource `r`, `p->is_equal(r)` returns `&r == p`.
|
| 8649 |
+
|
| 8650 |
+
``` cpp
|
| 8651 |
+
memory_resource* null_memory_resource() noexcept;
|
| 8652 |
+
```
|
| 8653 |
+
|
| 8654 |
+
*Returns:* A pointer to a static-duration object of a type derived from
|
| 8655 |
+
`memory_resource` for which `allocate()` always throws `bad_alloc` and
|
| 8656 |
+
for which `deallocate()` has no effect. The same value is returned every
|
| 8657 |
+
time this function is called. For a return value `p` and a memory
|
| 8658 |
+
resource `r`, `p->is_equal(r)` returns `&r == p`.
|
| 8659 |
+
|
| 8660 |
+
The *default memory resource pointer* is a pointer to a memory resource
|
| 8661 |
+
that is used by certain facilities when an explicit memory resource is
|
| 8662 |
+
not supplied through the interface. Its initial value is the return
|
| 8663 |
+
value of `new_delete_resource()`.
|
| 8664 |
+
|
| 8665 |
+
``` cpp
|
| 8666 |
+
memory_resource* set_default_resource(memory_resource* r) noexcept;
|
| 8667 |
+
```
|
| 8668 |
+
|
| 8669 |
+
*Effects:* If `r` is non-null, sets the value of the default memory
|
| 8670 |
+
resource pointer to `r`, otherwise sets the default memory resource
|
| 8671 |
+
pointer to `new_delete_resource()`.
|
| 8672 |
+
|
| 8673 |
+
*Postconditions:* `get_default_resource() == r`.
|
| 8674 |
+
|
| 8675 |
+
*Returns:* The previous value of the default memory resource pointer.
|
| 8676 |
+
|
| 8677 |
+
*Remarks:* Calling the `set_default_resource` and `get_default_resource`
|
| 8678 |
+
functions shall not incur a data race. A call to the
|
| 8679 |
+
`set_default_resource` function shall synchronize with subsequent calls
|
| 8680 |
+
to the `set_default_resource` and `get_default_resource` functions.
|
| 8681 |
+
|
| 8682 |
+
``` cpp
|
| 8683 |
+
memory_resource* get_default_resource() noexcept;
|
| 8684 |
+
```
|
| 8685 |
+
|
| 8686 |
+
*Returns:* The current value of the default memory resource pointer.
|
| 8687 |
+
|
| 8688 |
+
### Pool resource classes <a id="mem.res.pool">[[mem.res.pool]]</a>
|
| 8689 |
+
|
| 8690 |
+
#### Classes `synchronized_pool_resource` and `unsynchronized_pool_resource` <a id="mem.res.pool.overview">[[mem.res.pool.overview]]</a>
|
| 8691 |
+
|
| 8692 |
+
The `synchronized_pool_resource` and `unsynchronized_pool_resource`
|
| 8693 |
+
classes (collectively called *pool resource classes*) are
|
| 8694 |
+
general-purpose memory resources having the following qualities:
|
| 8695 |
+
|
| 8696 |
+
- Each resource frees its allocated memory on destruction, even if
|
| 8697 |
+
`deallocate` has not been called for some of the allocated blocks.
|
| 8698 |
+
- A pool resource consists of a collection of *pools*, serving requests
|
| 8699 |
+
for different block sizes. Each individual pool manages a collection
|
| 8700 |
+
of *chunks* that are in turn divided into blocks of uniform size,
|
| 8701 |
+
returned via calls to `do_allocate`. Each call to
|
| 8702 |
+
`do_allocate(size, alignment)` is dispatched to the pool serving the
|
| 8703 |
+
smallest blocks accommodating at least `size` bytes.
|
| 8704 |
+
- When a particular pool is exhausted, allocating a block from that pool
|
| 8705 |
+
results in the allocation of an additional chunk of memory from the
|
| 8706 |
+
*upstream allocator* (supplied at construction), thus replenishing the
|
| 8707 |
+
pool. With each successive replenishment, the chunk size obtained
|
| 8708 |
+
increases geometrically. \[*Note 1*: By allocating memory in chunks,
|
| 8709 |
+
the pooling strategy increases the chance that consecutive allocations
|
| 8710 |
+
will be close together in memory. — *end note*]
|
| 8711 |
+
- Allocation requests that exceed the largest block size of any pool are
|
| 8712 |
+
fulfilled directly from the upstream allocator.
|
| 8713 |
+
- A `pool_options` struct may be passed to the pool resource
|
| 8714 |
+
constructors to tune the largest block size and the maximum chunk
|
| 8715 |
+
size.
|
| 8716 |
+
|
| 8717 |
+
A `synchronized_pool_resource` may be accessed from multiple threads
|
| 8718 |
+
without external synchronization and may have thread-specific pools to
|
| 8719 |
+
reduce synchronization costs. An `unsynchronized_pool_resource` class
|
| 8720 |
+
may not be accessed from multiple threads simultaneously and thus avoids
|
| 8721 |
+
the cost of synchronization entirely in single-threaded applications.
|
| 8722 |
+
|
| 8723 |
+
``` cpp
|
| 8724 |
+
struct pool_options {
|
| 8725 |
+
size_t max_blocks_per_chunk = 0;
|
| 8726 |
+
size_t largest_required_pool_block = 0;
|
| 8727 |
+
};
|
| 8728 |
+
|
| 8729 |
+
class synchronized_pool_resource : public memory_resource {
|
| 8730 |
+
public:
|
| 8731 |
+
synchronized_pool_resource(const pool_options& opts,
|
| 8732 |
+
memory_resource* upstream);
|
| 8733 |
+
|
| 8734 |
+
synchronized_pool_resource()
|
| 8735 |
+
: synchronized_pool_resource(pool_options(), get_default_resource()) {}
|
| 8736 |
+
explicit synchronized_pool_resource(memory_resource* upstream)
|
| 8737 |
+
: synchronized_pool_resource(pool_options(), upstream) {}
|
| 8738 |
+
explicit synchronized_pool_resource(const pool_options& opts)
|
| 8739 |
+
: synchronized_pool_resource(opts, get_default_resource()) {}
|
| 8740 |
+
|
| 8741 |
+
synchronized_pool_resource(const synchronized_pool_resource&) = delete;
|
| 8742 |
+
virtual ~synchronized_pool_resource();
|
| 8743 |
+
|
| 8744 |
+
synchronized_pool_resource&
|
| 8745 |
+
operator=(const synchronized_pool_resource&) = delete;
|
| 8746 |
+
|
| 8747 |
+
void release();
|
| 8748 |
+
memory_resource* upstream_resource() const;
|
| 8749 |
+
pool_options options() const;
|
| 8750 |
+
|
| 8751 |
+
protected:
|
| 8752 |
+
void *do_allocate(size_t bytes, size_t alignment) override;
|
| 8753 |
+
void do_deallocate(void *p, size_t bytes, size_t alignment) override;
|
| 8754 |
+
|
| 8755 |
+
bool do_is_equal(const memory_resource& other) const noexcept override;
|
| 8756 |
+
};
|
| 8757 |
+
|
| 8758 |
+
class unsynchronized_pool_resource : public memory_resource {
|
| 8759 |
+
public:
|
| 8760 |
+
unsynchronized_pool_resource(const pool_options& opts,
|
| 8761 |
+
memory_resource* upstream);
|
| 8762 |
+
|
| 8763 |
+
unsynchronized_pool_resource()
|
| 8764 |
+
: unsynchronized_pool_resource(pool_options(), get_default_resource()) {}
|
| 8765 |
+
explicit unsynchronized_pool_resource(memory_resource* upstream)
|
| 8766 |
+
: unsynchronized_pool_resource(pool_options(), upstream) {}
|
| 8767 |
+
explicit unsynchronized_pool_resource(const pool_options& opts)
|
| 8768 |
+
: unsynchronized_pool_resource(opts, get_default_resource()) {}
|
| 8769 |
+
|
| 8770 |
+
unsynchronized_pool_resource(const unsynchronized_pool_resource&) = delete;
|
| 8771 |
+
virtual ~unsynchronized_pool_resource();
|
| 8772 |
+
|
| 8773 |
+
unsynchronized_pool_resource&
|
| 8774 |
+
operator=(const unsynchronized_pool_resource&) = delete;
|
| 8775 |
+
|
| 8776 |
+
void release();
|
| 8777 |
+
memory_resource *upstream_resource() const;
|
| 8778 |
+
pool_options options() const;
|
| 8779 |
+
|
| 8780 |
+
protected:
|
| 8781 |
+
void* do_allocate(size_t bytes, size_t alignment) override;
|
| 8782 |
+
void do_deallocate(void* p, size_t bytes, size_t alignment) override;
|
| 8783 |
+
|
| 8784 |
+
bool do_is_equal(const memory_resource& other) const noexcept override;
|
| 8785 |
+
};
|
| 8786 |
+
```
|
| 8787 |
+
|
| 8788 |
+
#### `pool_options` data members <a id="mem.res.pool.options">[[mem.res.pool.options]]</a>
|
| 8789 |
+
|
| 8790 |
+
The members of `pool_options` comprise a set of constructor options for
|
| 8791 |
+
pool resources. The effect of each option on the pool resource behavior
|
| 8792 |
+
is described below:
|
| 8793 |
+
|
| 8794 |
+
``` cpp
|
| 8795 |
+
size_t max_blocks_per_chunk;
|
| 8796 |
+
```
|
| 8797 |
+
|
| 8798 |
+
The maximum number of blocks that will be allocated at once from the
|
| 8799 |
+
upstream memory resource ([[mem.res.monotonic.buffer]]) to replenish a
|
| 8800 |
+
pool. If the value of `max_blocks_per_chunk` is zero or is greater than
|
| 8801 |
+
an *implementation-defined* limit, that limit is used instead. The
|
| 8802 |
+
implementation may choose to use a smaller value than is specified in
|
| 8803 |
+
this field and may use different values for different pools.
|
| 8804 |
+
|
| 8805 |
+
``` cpp
|
| 8806 |
+
size_t largest_required_pool_block;
|
| 8807 |
+
```
|
| 8808 |
+
|
| 8809 |
+
The largest allocation size that is required to be fulfilled using the
|
| 8810 |
+
pooling mechanism. Attempts to allocate a single block larger than this
|
| 8811 |
+
threshold will be allocated directly from the upstream memory resource.
|
| 8812 |
+
If `largest_required_pool_block` is zero or is greater than an
|
| 8813 |
+
*implementation-defined* limit, that limit is used instead. The
|
| 8814 |
+
implementation may choose a pass-through threshold larger than specified
|
| 8815 |
+
in this field.
|
| 8816 |
+
|
| 8817 |
+
#### Pool resource constructors and destructors <a id="mem.res.pool.ctor">[[mem.res.pool.ctor]]</a>
|
| 8818 |
+
|
| 8819 |
+
``` cpp
|
| 8820 |
+
synchronized_pool_resource(const pool_options& opts, memory_resource* upstream);
|
| 8821 |
+
unsynchronized_pool_resource(const pool_options& opts, memory_resource* upstream);
|
| 8822 |
+
```
|
| 8823 |
+
|
| 8824 |
+
*Requires:* `upstream` is the address of a valid memory resource.
|
| 8825 |
+
|
| 8826 |
+
*Effects:* Constructs a pool resource object that will obtain memory
|
| 8827 |
+
from `upstream` whenever the pool resource is unable to satisfy a memory
|
| 8828 |
+
request from its own internal data structures. The resulting object will
|
| 8829 |
+
hold a copy of `upstream`, but will not own the resource to which
|
| 8830 |
+
`upstream` points.
|
| 8831 |
+
|
| 8832 |
+
[*Note 1*: The intention is that calls to `upstream->allocate()` will
|
| 8833 |
+
be substantially fewer than calls to `this->allocate()` in most
|
| 8834 |
+
cases. — *end note*]
|
| 8835 |
+
|
| 8836 |
+
The behavior of the pooling mechanism is tuned according to the value of
|
| 8837 |
+
the `opts` argument.
|
| 8838 |
+
|
| 8839 |
+
*Throws:* Nothing unless `upstream->allocate()` throws. It is
|
| 8840 |
+
unspecified if, or under what conditions, this constructor calls
|
| 8841 |
+
`upstream->allocate()`.
|
| 8842 |
+
|
| 8843 |
+
``` cpp
|
| 8844 |
+
virtual ~synchronized_pool_resource();
|
| 8845 |
+
virtual ~unsynchronized_pool_resource();
|
| 8846 |
+
```
|
| 8847 |
+
|
| 8848 |
+
*Effects:* Calls `release()`.
|
| 8849 |
+
|
| 8850 |
+
#### Pool resource members <a id="mem.res.pool.mem">[[mem.res.pool.mem]]</a>
|
| 8851 |
+
|
| 8852 |
+
``` cpp
|
| 8853 |
+
void release();
|
| 8854 |
+
```
|
| 8855 |
+
|
| 8856 |
+
*Effects:* Calls `upstream_resource()->deallocate()` as necessary to
|
| 8857 |
+
release all allocated memory.
|
| 8858 |
+
|
| 8859 |
+
[*Note 1*: The memory is released back to `upstream_resource()` even if
|
| 8860 |
+
`deallocate` has not been called for some of the allocated
|
| 8861 |
+
blocks. — *end note*]
|
| 8862 |
+
|
| 8863 |
+
``` cpp
|
| 8864 |
+
memory_resource* upstream_resource() const;
|
| 8865 |
+
```
|
| 8866 |
+
|
| 8867 |
+
*Returns:* The value of the `upstream` argument provided to the
|
| 8868 |
+
constructor of this object.
|
| 8869 |
+
|
| 8870 |
+
``` cpp
|
| 8871 |
+
pool_options options() const;
|
| 8872 |
+
```
|
| 8873 |
+
|
| 8874 |
+
*Returns:* The options that control the pooling behavior of this
|
| 8875 |
+
resource. The values in the returned struct may differ from those
|
| 8876 |
+
supplied to the pool resource constructor in that values of zero will be
|
| 8877 |
+
replaced with *implementation-defined* defaults, and sizes may be
|
| 8878 |
+
rounded to unspecified granularity.
|
| 8879 |
+
|
| 8880 |
+
``` cpp
|
| 8881 |
+
void* do_allocate(size_t bytes, size_t alignment) override;
|
| 8882 |
+
```
|
| 8883 |
+
|
| 8884 |
+
*Returns:* A pointer to allocated storage
|
| 8885 |
+
([[basic.stc.dynamic.deallocation]]) with a size of at least `bytes`.
|
| 8886 |
+
The size and alignment of the allocated memory shall meet the
|
| 8887 |
+
requirements for a class derived from `memory_resource` ([[mem.res]]).
|
| 8888 |
+
|
| 8889 |
+
*Effects:* If the pool selected for a block of size `bytes` is unable to
|
| 8890 |
+
satisfy the memory request from its own internal data structures, it
|
| 8891 |
+
will call `upstream_resource()->allocate()` to obtain more memory. If
|
| 8892 |
+
`bytes` is larger than that which the largest pool can handle, then
|
| 8893 |
+
memory will be allocated using `upstream_resource()->allocate()`.
|
| 8894 |
+
|
| 8895 |
+
*Throws:* Nothing unless `upstream_resource()->allocate()` throws.
|
| 8896 |
+
|
| 8897 |
+
``` cpp
|
| 8898 |
+
void do_deallocate(void* p, size_t bytes, size_t alignment) override;
|
| 8899 |
+
```
|
| 8900 |
+
|
| 8901 |
+
*Effects:* Returns the memory at `p` to the pool. It is unspecified if,
|
| 8902 |
+
or under what circumstances, this operation will result in a call to
|
| 8903 |
+
`upstream_resource()->deallocate()`.
|
| 8904 |
+
|
| 8905 |
+
*Throws:* Nothing.
|
| 8906 |
+
|
| 8907 |
+
``` cpp
|
| 8908 |
+
bool synchronized_pool_resource::do_is_equal(
|
| 8909 |
+
const memory_resource& other) const noexcept override;
|
| 8910 |
+
```
|
| 8911 |
+
|
| 8912 |
+
*Returns:*
|
| 8913 |
+
`this == dynamic_cast<const synchronized_pool_resource*>(&other)`.
|
| 8914 |
+
|
| 8915 |
+
``` cpp
|
| 8916 |
+
bool unsynchronized_pool_resource::do_is_equal(
|
| 8917 |
+
const memory_resource& other) const noexcept override;
|
| 8918 |
+
```
|
| 8919 |
+
|
| 8920 |
+
*Returns:*
|
| 8921 |
+
`this == dynamic_cast<const unsynchronized_pool_resource*>(&other)`.
|
| 8922 |
+
|
| 8923 |
+
### Class `monotonic_buffer_resource` <a id="mem.res.monotonic.buffer">[[mem.res.monotonic.buffer]]</a>
|
| 8924 |
+
|
| 8925 |
+
A `monotonic_buffer_resource` is a special-purpose memory resource
|
| 8926 |
+
intended for very fast memory allocations in situations where memory is
|
| 8927 |
+
used to build up a few objects and then is released all at once when the
|
| 8928 |
+
memory resource object is destroyed. It has the following qualities:
|
| 8929 |
+
|
| 8930 |
+
- A call to `deallocate` has no effect, thus the amount of memory
|
| 8931 |
+
consumed increases monotonically until the resource is destroyed.
|
| 8932 |
+
- The program can supply an initial buffer, which the allocator uses to
|
| 8933 |
+
satisfy memory requests.
|
| 8934 |
+
- When the initial buffer (if any) is exhausted, it obtains additional
|
| 8935 |
+
buffers from an *upstream* memory resource supplied at construction.
|
| 8936 |
+
Each additional buffer is larger than the previous one, following a
|
| 8937 |
+
geometric progression.
|
| 8938 |
+
- It is intended for access from one thread of control at a time.
|
| 8939 |
+
Specifically, calls to `allocate` and `deallocate` do not synchronize
|
| 8940 |
+
with one another.
|
| 8941 |
+
- It frees the allocated memory on destruction, even if `deallocate` has
|
| 8942 |
+
not been called for some of the allocated blocks.
|
| 8943 |
+
|
| 8944 |
+
``` cpp
|
| 8945 |
+
class monotonic_buffer_resource : public memory_resource {
|
| 8946 |
+
memory_resource *upstream_rsrc; // exposition only
|
| 8947 |
+
void *current_buffer; // exposition only
|
| 8948 |
+
size_t next_buffer_size; // exposition only
|
| 8949 |
+
|
| 8950 |
+
public:
|
| 8951 |
+
explicit monotonic_buffer_resource(memory_resource *upstream);
|
| 8952 |
+
monotonic_buffer_resource(size_t initial_size, memory_resource *upstream);
|
| 8953 |
+
monotonic_buffer_resource(void *buffer, size_t buffer_size,
|
| 8954 |
+
memory_resource *upstream);
|
| 8955 |
+
|
| 8956 |
+
monotonic_buffer_resource()
|
| 8957 |
+
: monotonic_buffer_resource(get_default_resource()) {}
|
| 8958 |
+
explicit monotonic_buffer_resource(size_t initial_size)
|
| 8959 |
+
: monotonic_buffer_resource(initial_size, get_default_resource()) {}
|
| 8960 |
+
monotonic_buffer_resource(void *buffer, size_t buffer_size)
|
| 8961 |
+
: monotonic_buffer_resource(buffer, buffer_size, get_default_resource()) {}
|
| 8962 |
+
|
| 8963 |
+
monotonic_buffer_resource(const monotonic_buffer_resource&) = delete;
|
| 8964 |
+
|
| 8965 |
+
virtual ~monotonic_buffer_resource();
|
| 8966 |
+
|
| 8967 |
+
monotonic_buffer_resource
|
| 8968 |
+
operator=(const monotonic_buffer_resource&) = delete;
|
| 8969 |
+
|
| 8970 |
+
void release();
|
| 8971 |
+
memory_resource* upstream_resource() const;
|
| 8972 |
+
|
| 8973 |
+
protected:
|
| 8974 |
+
void* do_allocate(size_t bytes, size_t alignment) override;
|
| 8975 |
+
void do_deallocate(void* p, size_t bytes, size_t alignment) override;
|
| 8976 |
+
|
| 8977 |
+
bool do_is_equal(const memory_resource& other) const noexcept override;
|
| 8978 |
+
};
|
| 8979 |
+
```
|
| 8980 |
+
|
| 8981 |
+
#### `monotonic_buffer_resource` constructor and destructor <a id="mem.res.monotonic.buffer.ctor">[[mem.res.monotonic.buffer.ctor]]</a>
|
| 8982 |
+
|
| 8983 |
+
``` cpp
|
| 8984 |
+
explicit monotonic_buffer_resource(memory_resource* upstream);
|
| 8985 |
+
monotonic_buffer_resource(size_t initial_size, memory_resource* upstream);
|
| 8986 |
+
```
|
| 8987 |
+
|
| 8988 |
+
*Requires:* `upstream` shall be the address of a valid memory resource.
|
| 8989 |
+
`initial_size`, if specified, shall be greater than zero.
|
| 8990 |
+
|
| 8991 |
+
*Effects:* Sets `upstream_rsrc` to `upstream` and `current_buffer` to
|
| 8992 |
+
`nullptr`. If `initial_size` is specified, sets `next_buffer_size` to at
|
| 8993 |
+
least `initial_size`; otherwise sets `next_buffer_size` to an
|
| 8994 |
+
*implementation-defined* size.
|
| 8995 |
+
|
| 8996 |
+
``` cpp
|
| 8997 |
+
monotonic_buffer_resource(void* buffer, size_t buffer_size, memory_resource* upstream);
|
| 8998 |
+
```
|
| 8999 |
+
|
| 9000 |
+
*Requires:* `upstream` shall be the address of a valid memory resource.
|
| 9001 |
+
`buffer_size` shall be no larger than the number of bytes in `buffer`.
|
| 9002 |
+
|
| 9003 |
+
*Effects:* Sets `upstream_rsrc` to `upstream`, `current_buffer` to
|
| 9004 |
+
`buffer`, and `next_buffer_size` to `buffer_size` (but not less than 1),
|
| 9005 |
+
then increases `next_buffer_size` by an *implementation-defined* growth
|
| 9006 |
+
factor (which need not be integral).
|
| 9007 |
+
|
| 9008 |
+
``` cpp
|
| 9009 |
+
~monotonic_buffer_resource();
|
| 9010 |
+
```
|
| 9011 |
+
|
| 9012 |
+
*Effects:* Calls `release()`.
|
| 9013 |
+
|
| 9014 |
+
#### `monotonic_buffer_resource` members <a id="mem.res.monotonic.buffer.mem">[[mem.res.monotonic.buffer.mem]]</a>
|
| 9015 |
+
|
| 9016 |
+
``` cpp
|
| 9017 |
+
void release();
|
| 9018 |
+
```
|
| 9019 |
+
|
| 9020 |
+
*Effects:* Calls `upstream_rsrc->deallocate()` as necessary to release
|
| 9021 |
+
all allocated memory.
|
| 9022 |
+
|
| 9023 |
+
[*Note 1*: The memory is released back to `upstream_rsrc` even if some
|
| 9024 |
+
blocks that were allocated from `this` have not been deallocated from
|
| 9025 |
+
`this`. — *end note*]
|
| 9026 |
+
|
| 9027 |
+
``` cpp
|
| 9028 |
+
memory_resource* upstream_resource() const;
|
| 9029 |
+
```
|
| 9030 |
+
|
| 9031 |
+
*Returns:* The value of `upstream_rsrc`.
|
| 9032 |
+
|
| 9033 |
+
``` cpp
|
| 9034 |
+
void* do_allocate(size_t bytes, size_t alignment) override;
|
| 9035 |
+
```
|
| 9036 |
+
|
| 9037 |
+
*Returns:* A pointer to allocated storage
|
| 9038 |
+
([[basic.stc.dynamic.deallocation]]) with a size of at least `bytes`.
|
| 9039 |
+
The size and alignment of the allocated memory shall meet the
|
| 9040 |
+
requirements for a class derived from `memory_resource` ([[mem.res]]).
|
| 9041 |
+
|
| 9042 |
+
*Effects:* If the unused space in `current_buffer` can fit a block with
|
| 9043 |
+
the specified `bytes` and `alignment`, then allocate the return block
|
| 9044 |
+
from `current_buffer`; otherwise set `current_buffer` to
|
| 9045 |
+
`upstream_rsrc->allocate(n, m)`, where `n` is not less than
|
| 9046 |
+
`max(bytes, next_buffer_size)` and `m` is not less than `alignment`, and
|
| 9047 |
+
increase `next_buffer_size` by an *implementation-defined* growth factor
|
| 9048 |
+
(which need not be integral), then allocate the return block from the
|
| 9049 |
+
newly-allocated `current_buffer`.
|
| 9050 |
+
|
| 9051 |
+
*Throws:* Nothing unless `upstream_rsrc->allocate()` throws.
|
| 9052 |
+
|
| 9053 |
+
``` cpp
|
| 9054 |
+
void do_deallocate(void* p, size_t bytes, size_t alignment) override;
|
| 9055 |
+
```
|
| 9056 |
+
|
| 9057 |
+
*Effects:* None.
|
| 9058 |
+
|
| 9059 |
+
*Throws:* Nothing.
|
| 9060 |
+
|
| 9061 |
+
*Remarks:* Memory used by this resource increases monotonically until
|
| 9062 |
+
its destruction.
|
| 9063 |
+
|
| 9064 |
+
``` cpp
|
| 9065 |
+
bool do_is_equal(const memory_resource& other) const noexcept override;
|
| 9066 |
+
```
|
| 9067 |
+
|
| 9068 |
+
*Returns:*
|
| 9069 |
+
`this == dynamic_cast<const monotonic_buffer_resource*>(&other)`.
|
| 9070 |
+
|
| 9071 |
+
## Class template `scoped_allocator_adaptor` <a id="allocator.adaptor">[[allocator.adaptor]]</a>
|
| 9072 |
+
|
| 9073 |
+
### Header `<scoped_allocator>` synopsis <a id="allocator.adaptor.syn">[[allocator.adaptor.syn]]</a>
|
| 9074 |
+
|
| 9075 |
+
``` cpp
|
| 9076 |
+
// scoped allocator adaptor
|
| 9077 |
+
template <class OuterAlloc, class... InnerAlloc>
|
| 9078 |
+
class scoped_allocator_adaptor;
|
| 9079 |
+
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 9080 |
+
bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 9081 |
+
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 9082 |
+
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 9083 |
+
bool operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 9084 |
+
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 9085 |
+
```
|
| 9086 |
+
|
| 9087 |
+
The class template `scoped_allocator_adaptor` is an allocator template
|
| 9088 |
+
that specifies the memory resource (the outer allocator) to be used by a
|
| 9089 |
+
container (as any other allocator does) and also specifies an inner
|
| 9090 |
+
allocator resource to be passed to the constructor of every element
|
| 9091 |
+
within the container. This adaptor is instantiated with one outer and
|
| 9092 |
+
zero or more inner allocator types. If instantiated with only one
|
| 9093 |
+
allocator type, the inner allocator becomes the
|
| 9094 |
+
`scoped_allocator_adaptor` itself, thus using the same allocator
|
| 9095 |
+
resource for the container and every element within the container and,
|
| 9096 |
+
if the elements themselves are containers, each of their elements
|
| 9097 |
+
recursively. If instantiated with more than one allocator, the first
|
| 9098 |
+
allocator is the outer allocator for use by the container, the second
|
| 9099 |
+
allocator is passed to the constructors of the container’s elements,
|
| 9100 |
+
and, if the elements themselves are containers, the third allocator is
|
| 9101 |
+
passed to the elements’ elements, and so on. If containers are nested to
|
| 9102 |
+
a depth greater than the number of allocators, the last allocator is
|
| 9103 |
+
used repeatedly, as in the single-allocator case, for any remaining
|
| 9104 |
+
recursions.
|
| 9105 |
+
|
| 9106 |
+
[*Note 1*: The `scoped_allocator_adaptor` is derived from the outer
|
| 9107 |
+
allocator type so it can be substituted for the outer allocator type in
|
| 9108 |
+
most expressions. — *end note*]
|
| 9109 |
+
|
| 9110 |
+
``` cpp
|
| 9111 |
+
namespace std {
|
| 9112 |
+
template <class OuterAlloc, class... InnerAllocs>
|
| 9113 |
+
class scoped_allocator_adaptor : public OuterAlloc {
|
| 9114 |
+
private:
|
| 9115 |
+
using OuterTraits = allocator_traits<OuterAlloc>; // exposition only
|
| 9116 |
+
scoped_allocator_adaptor<InnerAllocs...> inner; // exposition only
|
| 9117 |
+
public:
|
| 9118 |
+
using outer_allocator_type = OuterAlloc;
|
| 9119 |
+
using inner_allocator_type = see below;
|
| 9120 |
+
|
| 9121 |
+
using value_type = typename OuterTraits::value_type;
|
| 9122 |
+
using size_type = typename OuterTraits::size_type;
|
| 9123 |
+
using difference_type = typename OuterTraits::difference_type;
|
| 9124 |
+
using pointer = typename OuterTraits::pointer;
|
| 9125 |
+
using const_pointer = typename OuterTraits::const_pointer;
|
| 9126 |
+
using void_pointer = typename OuterTraits::void_pointer;
|
| 9127 |
+
using const_void_pointer = typename OuterTraits::const_void_pointer;
|
| 9128 |
+
|
| 9129 |
+
using propagate_on_container_copy_assignment = see below;
|
| 9130 |
+
using propagate_on_container_move_assignment = see below;
|
| 9131 |
+
using propagate_on_container_swap = see below;
|
| 9132 |
+
using is_always_equal = see below;
|
| 9133 |
+
|
| 9134 |
+
template <class Tp>
|
| 9135 |
+
struct rebind {
|
| 9136 |
+
using other = scoped_allocator_adaptor<
|
| 9137 |
+
OuterTraits::template rebind_alloc<Tp>, InnerAllocs...>;
|
| 9138 |
+
};
|
| 9139 |
+
|
| 9140 |
+
scoped_allocator_adaptor();
|
| 9141 |
+
template <class OuterA2>
|
| 9142 |
+
scoped_allocator_adaptor(OuterA2&& outerAlloc,
|
| 9143 |
+
const InnerAllocs&... innerAllocs) noexcept;
|
| 9144 |
+
|
| 9145 |
+
scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
|
| 9146 |
+
scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept;
|
| 9147 |
+
|
| 9148 |
+
template <class OuterA2>
|
| 9149 |
+
scoped_allocator_adaptor(
|
| 9150 |
+
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept;
|
| 9151 |
+
template <class OuterA2>
|
| 9152 |
+
scoped_allocator_adaptor(
|
| 9153 |
+
scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
|
| 9154 |
+
|
| 9155 |
+
scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
|
| 9156 |
+
scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default;
|
| 9157 |
+
|
| 9158 |
+
~scoped_allocator_adaptor();
|
| 9159 |
+
|
| 9160 |
+
inner_allocator_type& inner_allocator() noexcept;
|
| 9161 |
+
const inner_allocator_type& inner_allocator() const noexcept;
|
| 9162 |
+
outer_allocator_type& outer_allocator() noexcept;
|
| 9163 |
+
const outer_allocator_type& outer_allocator() const noexcept;
|
| 9164 |
+
|
| 9165 |
+
pointer allocate(size_type n);
|
| 9166 |
+
pointer allocate(size_type n, const_void_pointer hint);
|
| 9167 |
+
void deallocate(pointer p, size_type n);
|
| 9168 |
+
size_type max_size() const;
|
| 9169 |
+
|
| 9170 |
+
template <class T, class... Args>
|
| 9171 |
+
void construct(T* p, Args&&... args);
|
| 9172 |
+
template <class T1, class T2, class... Args1, class... Args2>
|
| 9173 |
+
void construct(pair<T1, T2>* p, piecewise_construct_t,
|
| 9174 |
+
tuple<Args1...> x, tuple<Args2...> y);
|
| 9175 |
+
template <class T1, class T2>
|
| 9176 |
+
void construct(pair<T1, T2>* p);
|
| 9177 |
+
template <class T1, class T2, class U, class V>
|
| 9178 |
+
void construct(pair<T1, T2>* p, U&& x, V&& y);
|
| 9179 |
+
template <class T1, class T2, class U, class V>
|
| 9180 |
+
void construct(pair<T1, T2>* p, const pair<U, V>& x);
|
| 9181 |
+
template <class T1, class T2, class U, class V>
|
| 9182 |
+
void construct(pair<T1, T2>* p, pair<U, V>&& x);
|
| 9183 |
+
|
| 9184 |
+
template <class T>
|
| 9185 |
+
void destroy(T* p);
|
| 9186 |
+
|
| 9187 |
+
scoped_allocator_adaptor select_on_container_copy_construction() const;
|
| 9188 |
+
};
|
| 9189 |
+
|
| 9190 |
+
template<class OuterAlloc, class... InnerAllocs>
|
| 9191 |
+
scoped_allocator_adaptor(OuterAlloc, InnerAllocs...)
|
| 9192 |
+
-> scoped_allocator_adaptor<OuterAlloc, InnerAllocs...>;
|
| 9193 |
+
|
| 9194 |
+
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 9195 |
+
bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 9196 |
+
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 9197 |
+
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 9198 |
+
bool operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 9199 |
+
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 9200 |
+
}
|
| 9201 |
+
```
|
| 9202 |
+
|
| 9203 |
+
### Scoped allocator adaptor member types <a id="allocator.adaptor.types">[[allocator.adaptor.types]]</a>
|
| 9204 |
+
|
| 9205 |
+
``` cpp
|
| 9206 |
+
using inner_allocator_type = see below;
|
| 9207 |
+
```
|
| 9208 |
+
|
| 9209 |
+
*Type:* `scoped_allocator_adaptor<OuterAlloc>` if
|
| 9210 |
+
`sizeof...(InnerAllocs)` is zero; otherwise,
|
| 9211 |
+
`scoped_allocator_adaptor<InnerAllocs...>`.
|
| 9212 |
+
|
| 9213 |
+
``` cpp
|
| 9214 |
+
using propagate_on_container_copy_assignment = see below;
|
| 9215 |
+
```
|
| 9216 |
+
|
| 9217 |
+
*Type:* `true_type` if
|
| 9218 |
+
`allocator_traits<A>::propagate_on_container_copy_assignment::value` is
|
| 9219 |
+
`true` for any `A` in the set of `OuterAlloc` and `InnerAllocs...`;
|
| 9220 |
+
otherwise, `false_type`.
|
| 9221 |
+
|
| 9222 |
+
``` cpp
|
| 9223 |
+
using propagate_on_container_move_assignment = see below;
|
| 9224 |
+
```
|
| 9225 |
+
|
| 9226 |
+
*Type:* `true_type` if
|
| 9227 |
+
`allocator_traits<A>::propagate_on_container_move_assignment::value` is
|
| 9228 |
+
`true` for any `A` in the set of `OuterAlloc` and `InnerAllocs...`;
|
| 9229 |
+
otherwise, `false_type`.
|
| 9230 |
+
|
| 9231 |
+
``` cpp
|
| 9232 |
+
using propagate_on_container_swap = see below;
|
| 9233 |
+
```
|
| 9234 |
+
|
| 9235 |
+
*Type:* `true_type` if
|
| 9236 |
+
`allocator_traits<A>::propagate_on_container_swap::value` is `true` for
|
| 9237 |
+
any `A` in the set of `OuterAlloc` and `InnerAllocs...`; otherwise,
|
| 9238 |
+
`false_type`.
|
| 9239 |
+
|
| 9240 |
+
``` cpp
|
| 9241 |
+
using is_always_equal = see below;
|
| 9242 |
+
```
|
| 9243 |
+
|
| 9244 |
+
*Type:* `true_type` if `allocator_traits<A>::is_always_equal::value` is
|
| 9245 |
+
`true` for every `A` in the set of `OuterAlloc` and `InnerAllocs...`;
|
| 9246 |
+
otherwise, `false_type`.
|
| 9247 |
+
|
| 9248 |
+
### Scoped allocator adaptor constructors <a id="allocator.adaptor.cnstr">[[allocator.adaptor.cnstr]]</a>
|
| 9249 |
+
|
| 9250 |
+
``` cpp
|
| 9251 |
+
scoped_allocator_adaptor();
|
| 9252 |
+
```
|
| 9253 |
+
|
| 9254 |
+
*Effects:* Value-initializes the `OuterAlloc` base class and the `inner`
|
| 9255 |
+
allocator object.
|
| 9256 |
+
|
| 9257 |
+
``` cpp
|
| 9258 |
+
template <class OuterA2>
|
| 9259 |
+
scoped_allocator_adaptor(OuterA2&& outerAlloc,
|
| 9260 |
+
const InnerAllocs&... innerAllocs) noexcept;
|
| 9261 |
+
```
|
| 9262 |
+
|
| 9263 |
+
*Effects:* Initializes the `OuterAlloc` base class with
|
| 9264 |
+
`std::forward<OuterA2>(outerAlloc)` and `inner` with `innerAllocs...`
|
| 9265 |
+
(hence recursively initializing each allocator within the adaptor with
|
| 9266 |
+
the corresponding allocator from the argument list).
|
| 9267 |
+
|
| 9268 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 9269 |
+
unless `is_constructible_v<OuterAlloc, OuterA2>` is `true`.
|
| 9270 |
+
|
| 9271 |
+
``` cpp
|
| 9272 |
+
scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
|
| 9273 |
+
```
|
| 9274 |
+
|
| 9275 |
+
*Effects:* Initializes each allocator within the adaptor with the
|
| 9276 |
+
corresponding allocator from `other`.
|
| 9277 |
+
|
| 9278 |
+
``` cpp
|
| 9279 |
+
scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept;
|
| 9280 |
+
```
|
| 9281 |
+
|
| 9282 |
+
*Effects:* Move constructs each allocator within the adaptor with the
|
| 9283 |
+
corresponding allocator from `other`.
|
| 9284 |
+
|
| 9285 |
+
``` cpp
|
| 9286 |
+
template <class OuterA2>
|
| 9287 |
+
scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2,
|
| 9288 |
+
InnerAllocs...>& other) noexcept;
|
| 9289 |
+
```
|
| 9290 |
+
|
| 9291 |
+
*Effects:* Initializes each allocator within the adaptor with the
|
| 9292 |
+
corresponding allocator from `other`.
|
| 9293 |
+
|
| 9294 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 9295 |
+
unless `is_constructible_v<OuterAlloc, const OuterA2&>` is `true`.
|
| 9296 |
+
|
| 9297 |
+
``` cpp
|
| 9298 |
+
template <class OuterA2>
|
| 9299 |
+
scoped_allocator_adaptor(scoped_allocator_adaptor<OuterA2,
|
| 9300 |
+
InnerAllocs...>&& other) noexcept;
|
| 9301 |
+
```
|
| 9302 |
+
|
| 9303 |
+
*Effects:* Initializes each allocator within the adaptor with the
|
| 9304 |
+
corresponding allocator rvalue from `other`.
|
| 9305 |
+
|
| 9306 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 9307 |
+
unless `is_constructible_v<OuterAlloc, OuterA2>` is `true`.
|
| 9308 |
+
|
| 9309 |
+
### Scoped allocator adaptor members <a id="allocator.adaptor.members">[[allocator.adaptor.members]]</a>
|
| 9310 |
+
|
| 9311 |
+
In the `construct` member functions, `OUTERMOST(x)` is `x` if `x` does
|
| 9312 |
+
not have an `outer_allocator()` member function and
|
| 9313 |
+
`OUTERMOST(x.outer_allocator())` otherwise; `OUTERMOST_ALLOC_TRAITS(x)`
|
| 9314 |
+
is `allocator_traits<decltype(OUTERMOST(x))>`.
|
| 9315 |
+
|
| 9316 |
+
[*Note 1*: `OUTERMOST(x)` and `OUTERMOST_ALLOC_TRAITS(x)` are recursive
|
| 9317 |
+
operations. It is incumbent upon the definition of `outer_allocator()`
|
| 9318 |
+
to ensure that the recursion terminates. It will terminate for all
|
| 9319 |
+
instantiations of `scoped_allocator_adaptor`. — *end note*]
|
| 9320 |
+
|
| 9321 |
+
``` cpp
|
| 9322 |
+
inner_allocator_type& inner_allocator() noexcept;
|
| 9323 |
+
const inner_allocator_type& inner_allocator() const noexcept;
|
| 9324 |
+
```
|
| 9325 |
+
|
| 9326 |
+
*Returns:* `*this` if `sizeof...(InnerAllocs)` is zero; otherwise,
|
| 9327 |
+
`inner`.
|
| 9328 |
+
|
| 9329 |
+
``` cpp
|
| 9330 |
+
outer_allocator_type& outer_allocator() noexcept;
|
| 9331 |
+
```
|
| 9332 |
+
|
| 9333 |
+
*Returns:* `static_cast<OuterAlloc&>(*this)`.
|
| 9334 |
+
|
| 9335 |
+
``` cpp
|
| 9336 |
+
const outer_allocator_type& outer_allocator() const noexcept;
|
| 9337 |
+
```
|
| 9338 |
+
|
| 9339 |
+
*Returns:* `static_cast<const OuterAlloc&>(*this)`.
|
| 9340 |
+
|
| 9341 |
+
``` cpp
|
| 9342 |
+
pointer allocate(size_type n);
|
| 9343 |
+
```
|
| 9344 |
+
|
| 9345 |
+
*Returns:*
|
| 9346 |
+
`allocator_traits<OuterAlloc>::allocate(outer_allocator(), n)`.
|
| 9347 |
+
|
| 9348 |
+
``` cpp
|
| 9349 |
+
pointer allocate(size_type n, const_void_pointer hint);
|
| 9350 |
+
```
|
| 9351 |
+
|
| 9352 |
+
*Returns:*
|
| 9353 |
+
`allocator_traits<OuterAlloc>::allocate(outer_allocator(), n, hint)`.
|
| 9354 |
+
|
| 9355 |
+
``` cpp
|
| 9356 |
+
void deallocate(pointer p, size_type n) noexcept;
|
| 9357 |
+
```
|
| 9358 |
+
|
| 9359 |
+
*Effects:* As if by:
|
| 9360 |
+
`allocator_traits<OuterAlloc>::deallocate(outer_allocator(), p, n);`
|
| 9361 |
+
|
| 9362 |
+
``` cpp
|
| 9363 |
+
size_type max_size() const;
|
| 9364 |
+
```
|
| 9365 |
+
|
| 9366 |
+
*Returns:* `allocator_traits<OuterAlloc>::max_size(outer_allocator())`.
|
| 9367 |
+
|
| 9368 |
+
``` cpp
|
| 9369 |
+
template <class T, class... Args>
|
| 9370 |
+
void construct(T* p, Args&&... args);
|
| 9371 |
+
```
|
| 9372 |
+
|
| 9373 |
+
*Effects:*
|
| 9374 |
+
|
| 9375 |
+
- If `uses_allocator_v<T, inner_allocator_type>` is `false` and
|
| 9376 |
+
`is_constructible_v<T,`
|
| 9377 |
+
`Args...>` is `true`, calls:
|
| 9378 |
+
``` cpp
|
| 9379 |
+
OUTERMOST_ALLOC_TRAITS(*this)::construct(
|
| 9380 |
+
OUTERMOST(*this), p, std::forward<Args>(args)...)
|
| 9381 |
+
```
|
| 9382 |
+
- Otherwise, if `uses_allocator_v<T, inner_allocator_type>` is `true`
|
| 9383 |
+
and
|
| 9384 |
+
`is_constructible_v<T, allocator_arg_t, inner_allocator_type&, Args...>`
|
| 9385 |
+
is `true`, calls:
|
| 9386 |
+
``` cpp
|
| 9387 |
+
OUTERMOST_ALLOC_TRAITS(*this)::construct(
|
| 9388 |
+
OUTERMOST(*this), p, allocator_arg, inner_allocator(), std::forward<Args>(args)...)
|
| 9389 |
+
```
|
| 9390 |
+
- Otherwise, if `uses_allocator_v<T, inner_allocator_type>` is `true`
|
| 9391 |
+
and `is_constructible_v<T, Args..., inner_allocator_type&>` is `true`,
|
| 9392 |
+
calls:
|
| 9393 |
+
``` cpp
|
| 9394 |
+
OUTERMOST_ALLOC_TRAITS(*this)::construct(
|
| 9395 |
+
OUTERMOST(*this), p, std::forward<Args>(args)..., inner_allocator())
|
| 9396 |
+
```
|
| 9397 |
+
- Otherwise, the program is ill-formed. \[*Note 2*: An error will result
|
| 9398 |
+
if `uses_allocator` evaluates to `true` but the specific constructor
|
| 9399 |
+
does not take an allocator. This definition prevents a silent failure
|
| 9400 |
+
to pass an inner allocator to a contained element. — *end note*]
|
| 9401 |
+
|
| 9402 |
+
``` cpp
|
| 9403 |
+
template <class T1, class T2, class... Args1, class... Args2>
|
| 9404 |
+
void construct(pair<T1, T2>* p, piecewise_construct_t,
|
| 9405 |
+
tuple<Args1...> x, tuple<Args2...> y);
|
| 9406 |
+
```
|
| 9407 |
+
|
| 9408 |
+
*Requires:* all of the types in `Args1` and `Args2` shall be
|
| 9409 |
+
`CopyConstructible` (Table [[tab:copyconstructible]]).
|
| 9410 |
+
|
| 9411 |
+
*Effects:* Constructs a `tuple` object `xprime` from `x` by the
|
| 9412 |
+
following rules:
|
| 9413 |
+
|
| 9414 |
+
- If `uses_allocator_v<T1, inner_allocator_type>` is `false` and
|
| 9415 |
+
`is_constructible_v<T1,`
|
| 9416 |
+
`Args1...>` is `true`, then `xprime` is `x`.
|
| 9417 |
+
- Otherwise, if `uses_allocator_v<T1, inner_allocator_type>` is `true`
|
| 9418 |
+
and
|
| 9419 |
+
`is_constructible_v<T1, allocator_arg_t, inner_allocator_type&, Args1...>`
|
| 9420 |
+
is `true`, then `xprime` is:
|
| 9421 |
+
``` cpp
|
| 9422 |
+
tuple_cat(
|
| 9423 |
+
tuple<allocator_arg_t, inner_allocator_type&>(allocator_arg, inner_allocator()),
|
| 9424 |
+
std::move(x))
|
| 9425 |
+
```
|
| 9426 |
+
- Otherwise, if `uses_allocator_v<T1, inner_allocator_type>` is `true`
|
| 9427 |
+
and `is_constructible_v<T1, Args1..., inner_allocator_type&>` is
|
| 9428 |
+
`true`, then `xprime` is:
|
| 9429 |
+
``` cpp
|
| 9430 |
+
tuple_cat(std::move(x), tuple<inner_allocator_type&>(inner_allocator()))
|
| 9431 |
+
```
|
| 9432 |
+
- Otherwise, the program is ill-formed.
|
| 9433 |
+
|
| 9434 |
+
and constructs a `tuple` object `yprime` from `y` by the following
|
| 9435 |
+
rules:
|
| 9436 |
+
|
| 9437 |
+
- If `uses_allocator_v<T2, inner_allocator_type>` is `false` and
|
| 9438 |
+
`is_constructible_v<T2,`
|
| 9439 |
+
`Args2...>` is `true`, then `yprime` is `y`.
|
| 9440 |
+
- Otherwise, if `uses_allocator_v<T2, inner_allocator_type>` is `true`
|
| 9441 |
+
and
|
| 9442 |
+
`is_constructible_v<T2, allocator_arg_t, inner_allocator_type&, Args2...>`
|
| 9443 |
+
is `true`, then `yprime` is:
|
| 9444 |
+
``` cpp
|
| 9445 |
+
tuple_cat(
|
| 9446 |
+
tuple<allocator_arg_t, inner_allocator_type&>(allocator_arg, inner_allocator()),
|
| 9447 |
+
std::move(y))
|
| 9448 |
+
```
|
| 9449 |
+
- Otherwise, if `uses_allocator_v<T2, inner_allocator_type>` is `true`
|
| 9450 |
+
and `is_constructible_v<T2, Args2..., inner_allocator_type&>` is
|
| 9451 |
+
`true`, then `yprime` is:
|
| 9452 |
+
``` cpp
|
| 9453 |
+
tuple_cat(std::move(y), tuple<inner_allocator_type&>(inner_allocator()))
|
| 9454 |
+
```
|
| 9455 |
+
- Otherwise, the program is ill-formed.
|
| 9456 |
+
|
| 9457 |
+
then calls:
|
| 9458 |
+
|
| 9459 |
+
``` cpp
|
| 9460 |
+
OUTERMOST_ALLOC_TRAITS(*this)::construct(
|
| 9461 |
+
OUTERMOST(*this), p, piecewise_construct, std::move(xprime), std::move(yprime))
|
| 9462 |
+
```
|
| 9463 |
+
|
| 9464 |
+
``` cpp
|
| 9465 |
+
template <class T1, class T2>
|
| 9466 |
+
void construct(pair<T1, T2>* p);
|
| 9467 |
+
```
|
| 9468 |
+
|
| 9469 |
+
*Effects:* Equivalent to:
|
| 9470 |
+
|
| 9471 |
+
``` cpp
|
| 9472 |
+
construct(p, piecewise_construct, tuple<>(), tuple<>());
|
| 9473 |
+
```
|
| 9474 |
+
|
| 9475 |
+
``` cpp
|
| 9476 |
+
template <class T1, class T2, class U, class V>
|
| 9477 |
+
void construct(pair<T1, T2>* p, U&& x, V&& y);
|
| 9478 |
+
```
|
| 9479 |
+
|
| 9480 |
+
*Effects:* Equivalent to:
|
| 9481 |
+
|
| 9482 |
+
``` cpp
|
| 9483 |
+
construct(p, piecewise_construct,
|
| 9484 |
+
forward_as_tuple(std::forward<U>(x)),
|
| 9485 |
+
forward_as_tuple(std::forward<V>(y)));
|
| 9486 |
+
```
|
| 9487 |
+
|
| 9488 |
+
``` cpp
|
| 9489 |
+
template <class T1, class T2, class U, class V>
|
| 9490 |
+
void construct(pair<T1, T2>* p, const pair<U, V>& x);
|
| 9491 |
+
```
|
| 9492 |
+
|
| 9493 |
+
*Effects:* Equivalent to:
|
| 9494 |
+
|
| 9495 |
+
``` cpp
|
| 9496 |
+
construct(p, piecewise_construct,
|
| 9497 |
+
forward_as_tuple(x.first),
|
| 9498 |
+
forward_as_tuple(x.second));
|
| 9499 |
+
```
|
| 9500 |
+
|
| 9501 |
+
``` cpp
|
| 9502 |
+
template <class T1, class T2, class U, class V>
|
| 9503 |
+
void construct(pair<T1, T2>* p, pair<U, V>&& x);
|
| 9504 |
+
```
|
| 9505 |
+
|
| 9506 |
+
*Effects:* Equivalent to:
|
| 9507 |
+
|
| 9508 |
+
``` cpp
|
| 9509 |
+
construct(p, piecewise_construct,
|
| 9510 |
+
forward_as_tuple(std::forward<U>(x.first)),
|
| 9511 |
+
forward_as_tuple(std::forward<V>(x.second)));
|
| 9512 |
+
```
|
| 9513 |
+
|
| 9514 |
+
``` cpp
|
| 9515 |
+
template <class T>
|
| 9516 |
+
void destroy(T* p);
|
| 9517 |
+
```
|
| 9518 |
+
|
| 9519 |
+
*Effects:* Calls
|
| 9520 |
+
*OUTERMOST_ALLOC_TRAITS*(\*this)::destroy(*OUTERMOST*(\*this), p).
|
| 9521 |
+
|
| 9522 |
+
``` cpp
|
| 9523 |
+
scoped_allocator_adaptor select_on_container_copy_construction() const;
|
| 9524 |
+
```
|
| 9525 |
+
|
| 9526 |
+
*Returns:* A new `scoped_allocator_adaptor` object where each allocator
|
| 9527 |
+
`A` in the adaptor is initialized from the result of calling
|
| 9528 |
+
`allocator_traits<A>::select_on_container_copy_construction()` on the
|
| 9529 |
+
corresponding allocator in `*this`.
|
| 9530 |
+
|
| 9531 |
+
### Scoped allocator operators <a id="scoped.adaptor.operators">[[scoped.adaptor.operators]]</a>
|
| 9532 |
+
|
| 9533 |
+
``` cpp
|
| 9534 |
+
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 9535 |
+
bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 9536 |
+
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 9537 |
+
```
|
| 9538 |
+
|
| 9539 |
+
*Returns:* If `sizeof...(InnerAllocs)` is zero,
|
| 9540 |
+
|
| 9541 |
+
``` cpp
|
| 9542 |
+
a.outer_allocator() == b.outer_allocator()
|
| 9543 |
+
```
|
| 9544 |
+
|
| 9545 |
+
otherwise
|
| 9546 |
+
|
| 9547 |
+
``` cpp
|
| 9548 |
+
a.outer_allocator() == b.outer_allocator() && a.inner_allocator() == b.inner_allocator()
|
| 9549 |
+
```
|
| 9550 |
+
|
| 9551 |
+
``` cpp
|
| 9552 |
+
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
| 9553 |
+
bool operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 9554 |
+
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 9555 |
+
```
|
| 9556 |
+
|
| 9557 |
+
*Returns:* `!(a == b)`.
|
| 9558 |
|
| 9559 |
## Function objects <a id="function.objects">[[function.objects]]</a>
|
| 9560 |
|
| 9561 |
A *function object type* is an object type ([[basic.types]]) that can
|
| 9562 |
be the type of the *postfix-expression* in a function call (
|
|
|
|
| 9566 |
[[algorithms]]), the interface is specified to accept a function object.
|
| 9567 |
This not only makes algorithmic templates work with pointers to
|
| 9568 |
functions, but also enables them to work with arbitrary function
|
| 9569 |
objects.
|
| 9570 |
|
| 9571 |
+
### Header `<functional>` synopsis <a id="functional.syn">[[functional.syn]]</a>
|
| 9572 |
+
|
| 9573 |
``` cpp
|
| 9574 |
namespace std {
|
| 9575 |
+
// [func.invoke], invoke
|
| 9576 |
+
template <class F, class... Args>
|
| 9577 |
+
invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
|
| 9578 |
+
noexcept(is_nothrow_invocable_v<F, Args...>);
|
| 9579 |
|
| 9580 |
+
// [refwrap], reference_wrapper
|
| 9581 |
template <class T> class reference_wrapper;
|
| 9582 |
|
| 9583 |
template <class T> reference_wrapper<T> ref(T&) noexcept;
|
| 9584 |
template <class T> reference_wrapper<const T> cref(const T&) noexcept;
|
| 9585 |
template <class T> void ref(const T&&) = delete;
|
| 9586 |
template <class T> void cref(const T&&) = delete;
|
| 9587 |
|
| 9588 |
template <class T> reference_wrapper<T> ref(reference_wrapper<T>) noexcept;
|
| 9589 |
template <class T> reference_wrapper<const T> cref(reference_wrapper<T>) noexcept;
|
| 9590 |
|
| 9591 |
+
// [arithmetic.operations], arithmetic operations
|
| 9592 |
template <class T = void> struct plus;
|
| 9593 |
template <class T = void> struct minus;
|
| 9594 |
template <class T = void> struct multiplies;
|
| 9595 |
template <class T = void> struct divides;
|
| 9596 |
template <class T = void> struct modulus;
|
|
|
|
| 9600 |
template <> struct multiplies<void>;
|
| 9601 |
template <> struct divides<void>;
|
| 9602 |
template <> struct modulus<void>;
|
| 9603 |
template <> struct negate<void>;
|
| 9604 |
|
| 9605 |
+
// [comparisons], comparisons
|
| 9606 |
template <class T = void> struct equal_to;
|
| 9607 |
template <class T = void> struct not_equal_to;
|
| 9608 |
template <class T = void> struct greater;
|
| 9609 |
template <class T = void> struct less;
|
| 9610 |
template <class T = void> struct greater_equal;
|
|
|
|
| 9614 |
template <> struct greater<void>;
|
| 9615 |
template <> struct less<void>;
|
| 9616 |
template <> struct greater_equal<void>;
|
| 9617 |
template <> struct less_equal<void>;
|
| 9618 |
|
| 9619 |
+
// [logical.operations], logical operations
|
| 9620 |
template <class T = void> struct logical_and;
|
| 9621 |
template <class T = void> struct logical_or;
|
| 9622 |
template <class T = void> struct logical_not;
|
| 9623 |
template <> struct logical_and<void>;
|
| 9624 |
template <> struct logical_or<void>;
|
| 9625 |
template <> struct logical_not<void>;
|
| 9626 |
|
| 9627 |
+
// [bitwise.operations], bitwise operations
|
| 9628 |
template <class T = void> struct bit_and;
|
| 9629 |
template <class T = void> struct bit_or;
|
| 9630 |
template <class T = void> struct bit_xor;
|
| 9631 |
template <class T = void> struct bit_not;
|
| 9632 |
template <> struct bit_and<void>;
|
| 9633 |
template <> struct bit_or<void>;
|
| 9634 |
template <> struct bit_xor<void>;
|
| 9635 |
template <> struct bit_not<void>;
|
| 9636 |
|
| 9637 |
+
// [func.not_fn], function template not_fn
|
| 9638 |
+
template <class F>
|
| 9639 |
+
unspecified not_fn(F&& f);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9640 |
|
| 9641 |
+
// [func.bind], bind
|
| 9642 |
template<class T> struct is_bind_expression;
|
| 9643 |
template<class T> struct is_placeholder;
|
| 9644 |
|
| 9645 |
template<class F, class... BoundArgs>
|
| 9646 |
unspecified bind(F&&, BoundArgs&&...);
|
| 9647 |
template<class R, class F, class... BoundArgs>
|
| 9648 |
unspecified bind(F&&, BoundArgs&&...);
|
| 9649 |
|
| 9650 |
namespace placeholders {
|
| 9651 |
// M is the implementation-defined number of placeholders
|
| 9652 |
+
see belownc _1;
|
| 9653 |
+
see belownc _2;
|
| 9654 |
.
|
| 9655 |
.
|
| 9656 |
.
|
| 9657 |
+
see belownc _M;
|
| 9658 |
}
|
| 9659 |
|
| 9660 |
+
// [func.memfn], member function adaptors
|
| 9661 |
+
template<class R, class T>
|
| 9662 |
+
unspecified mem_fn(R T::*) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9663 |
|
| 9664 |
+
// [func.wrap], polymorphic function wrappers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9665 |
class bad_function_call;
|
| 9666 |
|
| 9667 |
+
template<class> class function; // not defined
|
| 9668 |
template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
|
| 9669 |
|
| 9670 |
template<class R, class... ArgTypes>
|
| 9671 |
+
void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
|
| 9672 |
|
| 9673 |
template<class R, class... ArgTypes>
|
| 9674 |
+
bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
|
| 9675 |
template<class R, class... ArgTypes>
|
| 9676 |
+
bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
|
| 9677 |
template<class R, class... ArgTypes>
|
| 9678 |
+
bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
|
| 9679 |
template<class R, class... ArgTypes>
|
| 9680 |
+
bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
|
| 9681 |
|
| 9682 |
+
// [func.search], searchers
|
| 9683 |
+
template<class ForwardIterator, class BinaryPredicate = equal_to<>>
|
| 9684 |
+
class default_searcher;
|
| 9685 |
|
| 9686 |
+
template<class RandomAccessIterator,
|
| 9687 |
+
class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
|
| 9688 |
+
class BinaryPredicate = equal_to<>>
|
| 9689 |
+
class boyer_moore_searcher;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9690 |
|
| 9691 |
+
template<class RandomAccessIterator,
|
| 9692 |
+
class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
|
| 9693 |
+
class BinaryPredicate = equal_to<>>
|
| 9694 |
+
class boyer_moore_horspool_searcher;
|
| 9695 |
|
| 9696 |
+
// [unord.hash], hash function primary template
|
| 9697 |
+
template <class T>
|
| 9698 |
+
struct hash;
|
| 9699 |
+
|
| 9700 |
+
// [func.bind], function object binders
|
| 9701 |
+
template <class T>
|
| 9702 |
+
inline constexpr bool is_bind_expression_v = is_bind_expression<T>::value;
|
| 9703 |
+
template <class T>
|
| 9704 |
+
inline constexpr int is_placeholder_v = is_placeholder<T>::value;
|
| 9705 |
}
|
| 9706 |
```
|
| 9707 |
|
| 9708 |
+
[*Example 1*:
|
| 9709 |
+
|
| 9710 |
If a C++program wants to have a by-element addition of two vectors `a`
|
| 9711 |
and `b` containing `double` and put the result into `a`, it can do:
|
| 9712 |
|
| 9713 |
``` cpp
|
| 9714 |
transform(a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
|
| 9715 |
```
|
| 9716 |
|
| 9717 |
+
— *end example*]
|
| 9718 |
+
|
| 9719 |
+
[*Example 2*:
|
| 9720 |
+
|
| 9721 |
To negate every element of `a`:
|
| 9722 |
|
| 9723 |
``` cpp
|
| 9724 |
transform(a.begin(), a.end(), a.begin(), negate<double>());
|
| 9725 |
```
|
| 9726 |
|
| 9727 |
+
— *end example*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9728 |
|
| 9729 |
### Definitions <a id="func.def">[[func.def]]</a>
|
| 9730 |
|
| 9731 |
The following definitions apply to this Clause:
|
| 9732 |
|
|
|
|
| 9748 |
### Requirements <a id="func.require">[[func.require]]</a>
|
| 9749 |
|
| 9750 |
Define `INVOKE(f, t1, t2, ..., tN)` as follows:
|
| 9751 |
|
| 9752 |
- `(t1.*f)(t2, ..., tN)` when `f` is a pointer to a member function of a
|
| 9753 |
+
class `T` and `is_base_of_v<T, decay_t<decltype(t1)>>` is `true`;
|
| 9754 |
+
- `(t1.get().*f)(t2, ..., tN)` when `f` is a pointer to a member
|
| 9755 |
+
function of a class `T` and `decay_t<decltype(t1)>` is a
|
| 9756 |
+
specialization of `reference_wrapper`;
|
| 9757 |
- `((*t1).*f)(t2, ..., tN)` when `f` is a pointer to a member function
|
| 9758 |
+
of a class `T` and `t1` does not satisfy the previous two items;
|
| 9759 |
+
- `t1.*f` when `N == 1` and `f` is a pointer to data member of a class
|
| 9760 |
+
`T` and `is_base_of_v<T, decay_t<decltype(t1)>>` is `true`;
|
| 9761 |
+
- `t1.get().*f` when `N == 1` and `f` is a pointer to data member of a
|
| 9762 |
+
class `T` and `decay_t<decltype(t1)>` is a specialization of
|
| 9763 |
+
`reference_wrapper`;
|
| 9764 |
+
- `(*t1).*f` when `N == 1` and `f` is a pointer to data member of a
|
| 9765 |
+
class `T` and `t1` does not satisfy the previous two items;
|
| 9766 |
- `f(t1, t2, ..., tN)` in all other cases.
|
| 9767 |
|
| 9768 |
+
Define `INVOKE<R>(f, t1, t2, ..., tN)` as
|
| 9769 |
+
`static_cast<void>(INVOKE(f, t1, t2, ..., tN))` if `R` is cv `void`,
|
| 9770 |
+
otherwise `INVOKE(f, t1, t2, ..., tN)` implicitly converted to `R`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9771 |
|
| 9772 |
Every call wrapper ([[func.def]]) shall be `MoveConstructible`. A
|
| 9773 |
+
*forwarding call wrapper* is a call wrapper that can be called with an
|
| 9774 |
+
arbitrary argument list and delivers the arguments to the wrapped
|
| 9775 |
+
callable object as references. This forwarding step shall ensure that
|
| 9776 |
+
rvalue arguments are delivered as rvalue references and lvalue arguments
|
| 9777 |
+
are delivered as lvalue references. A *simple call wrapper* is a
|
| 9778 |
+
forwarding call wrapper that is `CopyConstructible` and `CopyAssignable`
|
| 9779 |
+
and whose copy constructor, move constructor, and assignment operator do
|
| 9780 |
+
not throw exceptions.
|
| 9781 |
+
|
| 9782 |
+
[*Note 1*:
|
| 9783 |
+
|
| 9784 |
+
In a typical implementation forwarding call wrappers have an overloaded
|
| 9785 |
+
function call operator of the form
|
| 9786 |
|
| 9787 |
``` cpp
|
| 9788 |
template<class... UnBoundArgs>
|
| 9789 |
R operator()(UnBoundArgs&&... unbound_args) cv-qual;
|
| 9790 |
```
|
| 9791 |
|
| 9792 |
+
— *end note*]
|
| 9793 |
+
|
| 9794 |
+
### Function template `invoke` <a id="func.invoke">[[func.invoke]]</a>
|
| 9795 |
+
|
| 9796 |
+
``` cpp
|
| 9797 |
+
template <class F, class... Args>
|
| 9798 |
+
invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
|
| 9799 |
+
noexcept(is_nothrow_invocable_v<F, Args...>);
|
| 9800 |
+
```
|
| 9801 |
+
|
| 9802 |
+
*Returns:* *INVOKE*(std::forward\<F\>(f),
|
| 9803 |
+
std::forward\<Args\>(args)...) ([[func.require]]).
|
| 9804 |
+
|
| 9805 |
### Class template `reference_wrapper` <a id="refwrap">[[refwrap]]</a>
|
| 9806 |
|
| 9807 |
``` cpp
|
| 9808 |
namespace std {
|
| 9809 |
template <class T> class reference_wrapper {
|
| 9810 |
public :
|
| 9811 |
// types
|
| 9812 |
+
using type = T;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9813 |
|
| 9814 |
// construct/copy/destroy
|
| 9815 |
reference_wrapper(T&) noexcept;
|
| 9816 |
reference_wrapper(T&&) = delete; // do not bind to temporary objects
|
| 9817 |
reference_wrapper(const reference_wrapper& x) noexcept;
|
|
|
|
| 9823 |
operator T& () const noexcept;
|
| 9824 |
T& get() const noexcept;
|
| 9825 |
|
| 9826 |
// invocation
|
| 9827 |
template <class... ArgTypes>
|
| 9828 |
+
invoke_result_t<T&, ArgTypes...>
|
| 9829 |
operator() (ArgTypes&&...) const;
|
| 9830 |
};
|
| 9831 |
+
|
| 9832 |
+
template<class T>
|
| 9833 |
+
reference_wrapper(reference_wrapper<T>) -> reference_wrapper<T>;
|
| 9834 |
}
|
| 9835 |
```
|
| 9836 |
|
| 9837 |
`reference_wrapper<T>` is a `CopyConstructible` and `CopyAssignable`
|
| 9838 |
wrapper around a reference to an object or function of type `T`.
|
| 9839 |
|
| 9840 |
+
`reference_wrapper<T>` shall be a trivially copyable type (
|
| 9841 |
+
[[basic.types]]).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9842 |
|
| 9843 |
#### `reference_wrapper` construct/copy/destroy <a id="refwrap.const">[[refwrap.const]]</a>
|
| 9844 |
|
| 9845 |
``` cpp
|
| 9846 |
reference_wrapper(T& t) noexcept;
|
|
|
|
| 9876 |
T& get() const noexcept;
|
| 9877 |
```
|
| 9878 |
|
| 9879 |
*Returns:* The stored reference.
|
| 9880 |
|
| 9881 |
+
#### `reference_wrapper` invocation <a id="refwrap.invoke">[[refwrap.invoke]]</a>
|
| 9882 |
|
| 9883 |
``` cpp
|
| 9884 |
template <class... ArgTypes>
|
| 9885 |
+
invoke_result_t<T&, ArgTypes...>
|
| 9886 |
operator()(ArgTypes&&... args) const;
|
| 9887 |
```
|
| 9888 |
|
| 9889 |
+
*Returns:* *INVOKE*(get(),
|
| 9890 |
+
std::forward\<ArgTypes\>(args)...). ([[func.require]])
|
| 9891 |
|
| 9892 |
+
#### `reference_wrapper` helper functions <a id="refwrap.helpers">[[refwrap.helpers]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9893 |
|
| 9894 |
``` cpp
|
| 9895 |
template <class T> reference_wrapper<T> ref(T& t) noexcept;
|
| 9896 |
```
|
| 9897 |
|
| 9898 |
+
*Returns:* `reference_wrapper<T>(t)`.
|
| 9899 |
|
| 9900 |
``` cpp
|
| 9901 |
template <class T> reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;
|
| 9902 |
```
|
| 9903 |
|
| 9904 |
+
*Returns:* `ref(t.get())`.
|
| 9905 |
|
| 9906 |
``` cpp
|
| 9907 |
template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
|
| 9908 |
```
|
| 9909 |
|
| 9910 |
+
*Returns:* `reference_wrapper <const T>(t)`.
|
| 9911 |
|
| 9912 |
``` cpp
|
| 9913 |
template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
|
| 9914 |
```
|
| 9915 |
|
| 9916 |
+
*Returns:* `cref(t.get())`.
|
| 9917 |
|
| 9918 |
### Arithmetic operations <a id="arithmetic.operations">[[arithmetic.operations]]</a>
|
| 9919 |
|
| 9920 |
The library provides basic function object classes for all of the
|
| 9921 |
arithmetic operators in the language ([[expr.mul]], [[expr.add]]).
|
| 9922 |
|
| 9923 |
+
#### Class template `plus` <a id="arithmetic.operations.plus">[[arithmetic.operations.plus]]</a>
|
| 9924 |
+
|
| 9925 |
``` cpp
|
| 9926 |
template <class T = void> struct plus {
|
| 9927 |
constexpr T operator()(const T& x, const T& y) const;
|
|
|
|
|
|
|
|
|
|
| 9928 |
};
|
| 9929 |
```
|
| 9930 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9931 |
``` cpp
|
|
|
|
| 9932 |
constexpr T operator()(const T& x, const T& y) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9933 |
```
|
| 9934 |
|
| 9935 |
+
*Returns:* `x + y`.
|
| 9936 |
|
| 9937 |
``` cpp
|
| 9938 |
template <> struct plus<void> {
|
| 9939 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 9940 |
-> decltype(std::forward<T>(t) + std::forward<U>(u));
|
| 9941 |
|
| 9942 |
+
using is_transparent = unspecified;
|
| 9943 |
};
|
| 9944 |
```
|
| 9945 |
|
| 9946 |
+
``` cpp
|
| 9947 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 9948 |
+
-> decltype(std::forward<T>(t) + std::forward<U>(u));
|
| 9949 |
+
```
|
| 9950 |
+
|
| 9951 |
+
*Returns:* `std::forward<T>(t) + std::forward<U>(u)`.
|
| 9952 |
+
|
| 9953 |
+
#### Class template `minus` <a id="arithmetic.operations.minus">[[arithmetic.operations.minus]]</a>
|
| 9954 |
+
|
| 9955 |
+
``` cpp
|
| 9956 |
+
template <class T = void> struct minus {
|
| 9957 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 9958 |
+
};
|
| 9959 |
+
```
|
| 9960 |
+
|
| 9961 |
+
``` cpp
|
| 9962 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 9963 |
+
```
|
| 9964 |
+
|
| 9965 |
+
*Returns:* `x - y`.
|
| 9966 |
|
| 9967 |
``` cpp
|
| 9968 |
template <> struct minus<void> {
|
| 9969 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 9970 |
-> decltype(std::forward<T>(t) - std::forward<U>(u));
|
| 9971 |
|
| 9972 |
+
using is_transparent = unspecified;
|
| 9973 |
};
|
| 9974 |
```
|
| 9975 |
|
| 9976 |
+
``` cpp
|
| 9977 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 9978 |
+
-> decltype(std::forward<T>(t) - std::forward<U>(u));
|
| 9979 |
+
```
|
| 9980 |
+
|
| 9981 |
+
*Returns:* `std::forward<T>(t) - std::forward<U>(u)`.
|
| 9982 |
+
|
| 9983 |
+
#### Class template `multiplies` <a id="arithmetic.operations.multiplies">[[arithmetic.operations.multiplies]]</a>
|
| 9984 |
+
|
| 9985 |
+
``` cpp
|
| 9986 |
+
template <class T = void> struct multiplies {
|
| 9987 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 9988 |
+
};
|
| 9989 |
+
```
|
| 9990 |
+
|
| 9991 |
+
``` cpp
|
| 9992 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 9993 |
+
```
|
| 9994 |
+
|
| 9995 |
+
*Returns:* `x * y`.
|
| 9996 |
|
| 9997 |
``` cpp
|
| 9998 |
template <> struct multiplies<void> {
|
| 9999 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10000 |
-> decltype(std::forward<T>(t) * std::forward<U>(u));
|
| 10001 |
|
| 10002 |
+
using is_transparent = unspecified;
|
| 10003 |
};
|
| 10004 |
```
|
| 10005 |
|
| 10006 |
+
``` cpp
|
| 10007 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10008 |
+
-> decltype(std::forward<T>(t) * std::forward<U>(u));
|
| 10009 |
+
```
|
| 10010 |
+
|
| 10011 |
+
*Returns:* `std::forward<T>(t) * std::forward<U>(u)`.
|
| 10012 |
+
|
| 10013 |
+
#### Class template `divides` <a id="arithmetic.operations.divides">[[arithmetic.operations.divides]]</a>
|
| 10014 |
+
|
| 10015 |
+
``` cpp
|
| 10016 |
+
template <class T = void> struct divides {
|
| 10017 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 10018 |
+
};
|
| 10019 |
+
```
|
| 10020 |
+
|
| 10021 |
+
``` cpp
|
| 10022 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 10023 |
+
```
|
| 10024 |
+
|
| 10025 |
+
*Returns:* `x / y`.
|
| 10026 |
|
| 10027 |
``` cpp
|
| 10028 |
template <> struct divides<void> {
|
| 10029 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10030 |
-> decltype(std::forward<T>(t) / std::forward<U>(u));
|
| 10031 |
|
| 10032 |
+
using is_transparent = unspecified;
|
| 10033 |
};
|
| 10034 |
```
|
| 10035 |
|
| 10036 |
+
``` cpp
|
| 10037 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10038 |
+
-> decltype(std::forward<T>(t) / std::forward<U>(u));
|
| 10039 |
+
```
|
| 10040 |
+
|
| 10041 |
+
*Returns:* `std::forward<T>(t) / std::forward<U>(u)`.
|
| 10042 |
+
|
| 10043 |
+
#### Class template `modulus` <a id="arithmetic.operations.modulus">[[arithmetic.operations.modulus]]</a>
|
| 10044 |
+
|
| 10045 |
+
``` cpp
|
| 10046 |
+
template <class T = void> struct modulus {
|
| 10047 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 10048 |
+
};
|
| 10049 |
+
```
|
| 10050 |
+
|
| 10051 |
+
``` cpp
|
| 10052 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 10053 |
+
```
|
| 10054 |
+
|
| 10055 |
+
*Returns:* `x % y`.
|
| 10056 |
|
| 10057 |
``` cpp
|
| 10058 |
template <> struct modulus<void> {
|
| 10059 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10060 |
-> decltype(std::forward<T>(t) % std::forward<U>(u));
|
| 10061 |
|
| 10062 |
+
using is_transparent = unspecified;
|
| 10063 |
};
|
| 10064 |
```
|
| 10065 |
|
| 10066 |
+
``` cpp
|
| 10067 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10068 |
+
-> decltype(std::forward<T>(t) % std::forward<U>(u));
|
| 10069 |
+
```
|
| 10070 |
+
|
| 10071 |
+
*Returns:* `std::forward<T>(t) % std::forward<U>(u)`.
|
| 10072 |
+
|
| 10073 |
+
#### Class template `negate` <a id="arithmetic.operations.negate">[[arithmetic.operations.negate]]</a>
|
| 10074 |
+
|
| 10075 |
+
``` cpp
|
| 10076 |
+
template <class T = void> struct negate {
|
| 10077 |
+
constexpr T operator()(const T& x) const;
|
| 10078 |
+
};
|
| 10079 |
+
```
|
| 10080 |
+
|
| 10081 |
+
``` cpp
|
| 10082 |
+
constexpr T operator()(const T& x) const;
|
| 10083 |
+
```
|
| 10084 |
+
|
| 10085 |
+
*Returns:* `-x`.
|
| 10086 |
|
| 10087 |
``` cpp
|
| 10088 |
template <> struct negate<void> {
|
| 10089 |
template <class T> constexpr auto operator()(T&& t) const
|
| 10090 |
-> decltype(-std::forward<T>(t));
|
| 10091 |
|
| 10092 |
+
using is_transparent = unspecified;
|
| 10093 |
};
|
| 10094 |
```
|
| 10095 |
|
| 10096 |
+
``` cpp
|
| 10097 |
+
template <class T> constexpr auto operator()(T&& t) const
|
| 10098 |
+
-> decltype(-std::forward<T>(t));
|
| 10099 |
+
```
|
| 10100 |
+
|
| 10101 |
+
*Returns:* `-std::forward<T>(t)`.
|
| 10102 |
|
| 10103 |
### Comparisons <a id="comparisons">[[comparisons]]</a>
|
| 10104 |
|
| 10105 |
The library provides basic function object classes for all of the
|
| 10106 |
comparison operators in the language ([[expr.rel]], [[expr.eq]]).
|
| 10107 |
|
| 10108 |
+
For templates `less`, `greater`, `less_equal`, and `greater_equal`, the
|
| 10109 |
+
specializations for any pointer type yield a strict total order that is
|
| 10110 |
+
consistent among those specializations and is also consistent with the
|
| 10111 |
+
partial order imposed by the built-in operators `<`, `>`, `<=`, `>=`.
|
| 10112 |
+
|
| 10113 |
+
[*Note 1*: When `a < b` is well-defined for pointers `a` and `b` of
|
| 10114 |
+
type `P`, this implies `(a < b) == less<P>(a, b)`,
|
| 10115 |
+
`(a > b) == greater<P>(a, b)`, and so forth. — *end note*]
|
| 10116 |
+
|
| 10117 |
+
For template specializations `less<void>`, `greater<void>`,
|
| 10118 |
+
`less_equal<void>`, and `greater_equal<void>`, if the call operator
|
| 10119 |
+
calls a built-in operator comparing pointers, the call operator yields a
|
| 10120 |
+
strict total order that is consistent among those specializations and is
|
| 10121 |
+
also consistent with the partial order imposed by those built-in
|
| 10122 |
+
operators.
|
| 10123 |
+
|
| 10124 |
+
#### Class template `equal_to` <a id="comparisons.equal_to">[[comparisons.equal_to]]</a>
|
| 10125 |
+
|
| 10126 |
``` cpp
|
| 10127 |
template <class T = void> struct equal_to {
|
| 10128 |
constexpr bool operator()(const T& x, const T& y) const;
|
|
|
|
|
|
|
|
|
|
| 10129 |
};
|
| 10130 |
```
|
| 10131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10132 |
``` cpp
|
|
|
|
| 10133 |
constexpr bool operator()(const T& x, const T& y) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10134 |
```
|
| 10135 |
|
| 10136 |
+
*Returns:* `x == y`.
|
| 10137 |
|
| 10138 |
``` cpp
|
| 10139 |
template <> struct equal_to<void> {
|
| 10140 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10141 |
-> decltype(std::forward<T>(t) == std::forward<U>(u));
|
| 10142 |
|
| 10143 |
+
using is_transparent = unspecified;
|
| 10144 |
};
|
| 10145 |
```
|
| 10146 |
|
| 10147 |
+
``` cpp
|
| 10148 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10149 |
+
-> decltype(std::forward<T>(t) == std::forward<U>(u));
|
| 10150 |
+
```
|
| 10151 |
+
|
| 10152 |
+
*Returns:* `std::forward<T>(t) == std::forward<U>(u)`.
|
| 10153 |
+
|
| 10154 |
+
#### Class template `not_equal_to` <a id="comparisons.not_equal_to">[[comparisons.not_equal_to]]</a>
|
| 10155 |
+
|
| 10156 |
+
``` cpp
|
| 10157 |
+
template <class T = void> struct not_equal_to {
|
| 10158 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10159 |
+
};
|
| 10160 |
+
```
|
| 10161 |
+
|
| 10162 |
+
``` cpp
|
| 10163 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10164 |
+
```
|
| 10165 |
+
|
| 10166 |
+
*Returns:* `x != y`.
|
| 10167 |
|
| 10168 |
``` cpp
|
| 10169 |
template <> struct not_equal_to<void> {
|
| 10170 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10171 |
-> decltype(std::forward<T>(t) != std::forward<U>(u));
|
| 10172 |
|
| 10173 |
+
using is_transparent = unspecified;
|
| 10174 |
};
|
| 10175 |
```
|
| 10176 |
|
| 10177 |
+
``` cpp
|
| 10178 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10179 |
+
-> decltype(std::forward<T>(t) != std::forward<U>(u));
|
| 10180 |
+
```
|
| 10181 |
+
|
| 10182 |
+
*Returns:* `std::forward<T>(t) != std::forward<U>(u)`.
|
| 10183 |
+
|
| 10184 |
+
#### Class template `greater` <a id="comparisons.greater">[[comparisons.greater]]</a>
|
| 10185 |
+
|
| 10186 |
+
``` cpp
|
| 10187 |
+
template <class T = void> struct greater {
|
| 10188 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10189 |
+
};
|
| 10190 |
+
```
|
| 10191 |
+
|
| 10192 |
+
``` cpp
|
| 10193 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10194 |
+
```
|
| 10195 |
+
|
| 10196 |
+
*Returns:* `x > y`.
|
| 10197 |
|
| 10198 |
``` cpp
|
| 10199 |
template <> struct greater<void> {
|
| 10200 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10201 |
-> decltype(std::forward<T>(t) > std::forward<U>(u));
|
| 10202 |
|
| 10203 |
+
using is_transparent = unspecified;
|
| 10204 |
};
|
| 10205 |
```
|
| 10206 |
|
| 10207 |
+
``` cpp
|
| 10208 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10209 |
+
-> decltype(std::forward<T>(t) > std::forward<U>(u));
|
| 10210 |
+
```
|
| 10211 |
+
|
| 10212 |
+
*Returns:* `std::forward<T>(t) > std::forward<U>(u)`.
|
| 10213 |
+
|
| 10214 |
+
#### Class template `less` <a id="comparisons.less">[[comparisons.less]]</a>
|
| 10215 |
+
|
| 10216 |
+
``` cpp
|
| 10217 |
+
template <class T = void> struct less {
|
| 10218 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10219 |
+
};
|
| 10220 |
+
```
|
| 10221 |
+
|
| 10222 |
+
``` cpp
|
| 10223 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10224 |
+
```
|
| 10225 |
+
|
| 10226 |
+
*Returns:* `x < y`.
|
| 10227 |
|
| 10228 |
``` cpp
|
| 10229 |
template <> struct less<void> {
|
| 10230 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10231 |
-> decltype(std::forward<T>(t) < std::forward<U>(u));
|
| 10232 |
|
| 10233 |
+
using is_transparent = unspecified;
|
| 10234 |
};
|
| 10235 |
```
|
| 10236 |
|
| 10237 |
+
``` cpp
|
| 10238 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10239 |
+
-> decltype(std::forward<T>(t) < std::forward<U>(u));
|
| 10240 |
+
```
|
| 10241 |
+
|
| 10242 |
+
*Returns:* `std::forward<T>(t) < std::forward<U>(u)`.
|
| 10243 |
+
|
| 10244 |
+
#### Class template `greater_equal` <a id="comparisons.greater_equal">[[comparisons.greater_equal]]</a>
|
| 10245 |
+
|
| 10246 |
+
``` cpp
|
| 10247 |
+
template <class T = void> struct greater_equal {
|
| 10248 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10249 |
+
};
|
| 10250 |
+
```
|
| 10251 |
+
|
| 10252 |
+
``` cpp
|
| 10253 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10254 |
+
```
|
| 10255 |
+
|
| 10256 |
+
*Returns:* `x >= y`.
|
| 10257 |
|
| 10258 |
``` cpp
|
| 10259 |
template <> struct greater_equal<void> {
|
| 10260 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10261 |
-> decltype(std::forward<T>(t) >= std::forward<U>(u));
|
| 10262 |
|
| 10263 |
+
using is_transparent = unspecified;
|
| 10264 |
};
|
| 10265 |
```
|
| 10266 |
|
| 10267 |
+
``` cpp
|
| 10268 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10269 |
+
-> decltype(std::forward<T>(t) >= std::forward<U>(u));
|
| 10270 |
+
```
|
| 10271 |
+
|
| 10272 |
+
*Returns:* `std::forward<T>(t) >= std::forward<U>(u)`.
|
| 10273 |
+
|
| 10274 |
+
#### Class template `less_equal` <a id="comparisons.less_equal">[[comparisons.less_equal]]</a>
|
| 10275 |
+
|
| 10276 |
+
``` cpp
|
| 10277 |
+
template <class T = void> struct less_equal {
|
| 10278 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10279 |
+
};
|
| 10280 |
+
```
|
| 10281 |
+
|
| 10282 |
+
``` cpp
|
| 10283 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10284 |
+
```
|
| 10285 |
+
|
| 10286 |
+
*Returns:* `x <= y`.
|
| 10287 |
|
| 10288 |
``` cpp
|
| 10289 |
template <> struct less_equal<void> {
|
| 10290 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10291 |
-> decltype(std::forward<T>(t) <= std::forward<U>(u));
|
| 10292 |
|
| 10293 |
+
using is_transparent = unspecified;
|
| 10294 |
};
|
| 10295 |
```
|
| 10296 |
|
| 10297 |
+
``` cpp
|
| 10298 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10299 |
+
-> decltype(std::forward<T>(t) <= std::forward<U>(u));
|
| 10300 |
+
```
|
| 10301 |
|
| 10302 |
+
*Returns:* `std::forward<T>(t) <= std::forward<U>(u)`.
|
|
|
|
|
|
|
| 10303 |
|
| 10304 |
### Logical operations <a id="logical.operations">[[logical.operations]]</a>
|
| 10305 |
|
| 10306 |
The library provides basic function object classes for all of the
|
| 10307 |
logical operators in the language ([[expr.log.and]], [[expr.log.or]],
|
| 10308 |
[[expr.unary.op]]).
|
| 10309 |
|
| 10310 |
+
#### Class template `logical_and` <a id="logical.operations.and">[[logical.operations.and]]</a>
|
| 10311 |
+
|
| 10312 |
``` cpp
|
| 10313 |
template <class T = void> struct logical_and {
|
| 10314 |
constexpr bool operator()(const T& x, const T& y) const;
|
|
|
|
|
|
|
|
|
|
| 10315 |
};
|
| 10316 |
```
|
| 10317 |
|
|
|
|
|
|
|
| 10318 |
``` cpp
|
|
|
|
| 10319 |
constexpr bool operator()(const T& x, const T& y) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10320 |
```
|
| 10321 |
|
| 10322 |
+
*Returns:* `x && y`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10323 |
|
| 10324 |
``` cpp
|
| 10325 |
template <> struct logical_and<void> {
|
| 10326 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10327 |
-> decltype(std::forward<T>(t) && std::forward<U>(u));
|
| 10328 |
|
| 10329 |
+
using is_transparent = unspecified;
|
| 10330 |
};
|
| 10331 |
```
|
| 10332 |
|
| 10333 |
+
``` cpp
|
| 10334 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10335 |
+
-> decltype(std::forward<T>(t) && std::forward<U>(u));
|
| 10336 |
+
```
|
| 10337 |
+
|
| 10338 |
+
*Returns:* `std::forward<T>(t) && std::forward<U>(u)`.
|
| 10339 |
+
|
| 10340 |
+
#### Class template `logical_or` <a id="logical.operations.or">[[logical.operations.or]]</a>
|
| 10341 |
+
|
| 10342 |
+
``` cpp
|
| 10343 |
+
template <class T = void> struct logical_or {
|
| 10344 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10345 |
+
};
|
| 10346 |
+
```
|
| 10347 |
+
|
| 10348 |
+
``` cpp
|
| 10349 |
+
constexpr bool operator()(const T& x, const T& y) const;
|
| 10350 |
+
```
|
| 10351 |
+
|
| 10352 |
+
*Returns:* `x || y`.
|
| 10353 |
|
| 10354 |
``` cpp
|
| 10355 |
template <> struct logical_or<void> {
|
| 10356 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10357 |
-> decltype(std::forward<T>(t) || std::forward<U>(u));
|
| 10358 |
|
| 10359 |
+
using is_transparent = unspecified;
|
| 10360 |
};
|
| 10361 |
```
|
| 10362 |
|
| 10363 |
+
``` cpp
|
| 10364 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10365 |
+
-> decltype(std::forward<T>(t) || std::forward<U>(u));
|
| 10366 |
+
```
|
| 10367 |
+
|
| 10368 |
+
*Returns:* `std::forward<T>(t) || std::forward<U>(u)`.
|
| 10369 |
+
|
| 10370 |
+
#### Class template `logical_not` <a id="logical.operations.not">[[logical.operations.not]]</a>
|
| 10371 |
+
|
| 10372 |
+
``` cpp
|
| 10373 |
+
template <class T = void> struct logical_not {
|
| 10374 |
+
constexpr bool operator()(const T& x) const;
|
| 10375 |
+
};
|
| 10376 |
+
```
|
| 10377 |
+
|
| 10378 |
+
``` cpp
|
| 10379 |
+
constexpr bool operator()(const T& x) const;
|
| 10380 |
+
```
|
| 10381 |
+
|
| 10382 |
+
*Returns:* `!x`.
|
| 10383 |
|
| 10384 |
``` cpp
|
| 10385 |
template <> struct logical_not<void> {
|
| 10386 |
template <class T> constexpr auto operator()(T&& t) const
|
| 10387 |
-> decltype(!std::forward<T>(t));
|
| 10388 |
|
| 10389 |
+
using is_transparent = unspecified;
|
| 10390 |
};
|
| 10391 |
```
|
| 10392 |
|
| 10393 |
+
``` cpp
|
| 10394 |
+
template <class T> constexpr auto operator()(T&& t) const
|
| 10395 |
+
-> decltype(!std::forward<T>(t));
|
| 10396 |
+
```
|
| 10397 |
+
|
| 10398 |
+
*Returns:* `!std::forward<T>(t)`.
|
| 10399 |
|
| 10400 |
### Bitwise operations <a id="bitwise.operations">[[bitwise.operations]]</a>
|
| 10401 |
|
| 10402 |
The library provides basic function object classes for all of the
|
| 10403 |
bitwise operators in the language ([[expr.bit.and]], [[expr.or]],
|
| 10404 |
[[expr.xor]], [[expr.unary.op]]).
|
| 10405 |
|
| 10406 |
+
#### Class template `bit_and` <a id="bitwise.operations.and">[[bitwise.operations.and]]</a>
|
| 10407 |
+
|
| 10408 |
``` cpp
|
| 10409 |
template <class T = void> struct bit_and {
|
| 10410 |
constexpr T operator()(const T& x, const T& y) const;
|
|
|
|
|
|
|
|
|
|
| 10411 |
};
|
| 10412 |
```
|
| 10413 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10414 |
``` cpp
|
|
|
|
| 10415 |
constexpr T operator()(const T& x, const T& y) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10416 |
```
|
| 10417 |
|
| 10418 |
+
*Returns:* `x & y`.
|
| 10419 |
|
| 10420 |
``` cpp
|
| 10421 |
template <> struct bit_and<void> {
|
| 10422 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10423 |
-> decltype(std::forward<T>(t) & std::forward<U>(u));
|
| 10424 |
|
| 10425 |
+
using is_transparent = unspecified;
|
| 10426 |
};
|
| 10427 |
```
|
| 10428 |
|
| 10429 |
+
``` cpp
|
| 10430 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10431 |
+
-> decltype(std::forward<T>(t) & std::forward<U>(u));
|
| 10432 |
+
```
|
| 10433 |
+
|
| 10434 |
+
*Returns:* `std::forward<T>(t) & std::forward<U>(u)`.
|
| 10435 |
+
|
| 10436 |
+
#### Class template `bit_or` <a id="bitwise.operations.or">[[bitwise.operations.or]]</a>
|
| 10437 |
+
|
| 10438 |
+
``` cpp
|
| 10439 |
+
template <class T = void> struct bit_or {
|
| 10440 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 10441 |
+
};
|
| 10442 |
+
```
|
| 10443 |
+
|
| 10444 |
+
``` cpp
|
| 10445 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 10446 |
+
```
|
| 10447 |
+
|
| 10448 |
+
*Returns:* `x | y`.
|
| 10449 |
|
| 10450 |
``` cpp
|
| 10451 |
template <> struct bit_or<void> {
|
| 10452 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10453 |
-> decltype(std::forward<T>(t) | std::forward<U>(u));
|
| 10454 |
|
| 10455 |
+
using is_transparent = unspecified;
|
| 10456 |
};
|
| 10457 |
```
|
| 10458 |
|
| 10459 |
+
``` cpp
|
| 10460 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10461 |
+
-> decltype(std::forward<T>(t) | std::forward<U>(u));
|
| 10462 |
+
```
|
| 10463 |
+
|
| 10464 |
+
*Returns:* `std::forward<T>(t) | std::forward<U>(u)`.
|
| 10465 |
+
|
| 10466 |
+
#### Class template `bit_xor` <a id="bitwise.operations.xor">[[bitwise.operations.xor]]</a>
|
| 10467 |
+
|
| 10468 |
+
``` cpp
|
| 10469 |
+
template <class T = void> struct bit_xor {
|
| 10470 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 10471 |
+
};
|
| 10472 |
+
```
|
| 10473 |
+
|
| 10474 |
+
``` cpp
|
| 10475 |
+
constexpr T operator()(const T& x, const T& y) const;
|
| 10476 |
+
```
|
| 10477 |
+
|
| 10478 |
+
*Returns:* `x ^ y`.
|
| 10479 |
|
| 10480 |
``` cpp
|
| 10481 |
template <> struct bit_xor<void> {
|
| 10482 |
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10483 |
-> decltype(std::forward<T>(t) ^ std::forward<U>(u));
|
| 10484 |
|
| 10485 |
+
using is_transparent = unspecified;
|
| 10486 |
};
|
| 10487 |
```
|
| 10488 |
|
| 10489 |
+
``` cpp
|
| 10490 |
+
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
|
| 10491 |
+
-> decltype(std::forward<T>(t) ^ std::forward<U>(u));
|
| 10492 |
+
```
|
| 10493 |
+
|
| 10494 |
+
*Returns:* `std::forward<T>(t) ^ std::forward<U>(u)`.
|
| 10495 |
+
|
| 10496 |
+
#### Class template `bit_not` <a id="bitwise.operations.not">[[bitwise.operations.not]]</a>
|
| 10497 |
+
|
| 10498 |
+
``` cpp
|
| 10499 |
+
template <class T = void> struct bit_not {
|
| 10500 |
+
constexpr T operator()(const T& x) const;
|
| 10501 |
+
};
|
| 10502 |
+
```
|
| 10503 |
+
|
| 10504 |
+
``` cpp
|
| 10505 |
+
constexpr T operator()(const T& x) const;
|
| 10506 |
+
```
|
| 10507 |
+
|
| 10508 |
+
*Returns:* `~x`.
|
| 10509 |
|
| 10510 |
``` cpp
|
| 10511 |
template <> struct bit_not<void> {
|
| 10512 |
template <class T> constexpr auto operator()(T&& t) const
|
| 10513 |
-> decltype(~std::forward<T>(t));
|
| 10514 |
|
| 10515 |
+
using is_transparent = unspecified;
|
| 10516 |
};
|
| 10517 |
```
|
| 10518 |
|
| 10519 |
+
``` cpp
|
| 10520 |
+
template <class T> constexpr auto operator()(T&&) const
|
| 10521 |
+
-> decltype(~std::forward<T>(t));
|
| 10522 |
+
```
|
| 10523 |
+
|
| 10524 |
+
*Returns:* `~std::forward<T>(t)`.
|
| 10525 |
|
| 10526 |
+
### Function template `not_fn` <a id="func.not_fn">[[func.not_fn]]</a>
|
| 10527 |
+
|
| 10528 |
+
``` cpp
|
| 10529 |
+
template <class F> unspecified not_fn(F&& f);
|
| 10530 |
+
```
|
| 10531 |
|
| 10532 |
+
*Effects:* Equivalent to
|
| 10533 |
+
`return `*`call_wrapper`*`(std::forward<F>(f));` where *`call_wrapper`*
|
| 10534 |
+
is an exposition only class defined as follows:
|
| 10535 |
|
| 10536 |
``` cpp
|
| 10537 |
+
class call_wrapper {
|
| 10538 |
+
using FD = decay_t<F>;
|
| 10539 |
+
FD fd;
|
| 10540 |
+
|
| 10541 |
+
explicit call_wrapper(F&& f);
|
| 10542 |
+
|
| 10543 |
public:
|
| 10544 |
+
call_wrapper(call_wrapper&&) = default;
|
| 10545 |
+
call_wrapper(const call_wrapper&) = default;
|
| 10546 |
+
|
| 10547 |
+
template<class... Args>
|
| 10548 |
+
auto operator()(Args&&...) &
|
| 10549 |
+
-> decltype(!declval<invoke_result_t<FD&, Args...>>());
|
| 10550 |
+
|
| 10551 |
+
template<class... Args>
|
| 10552 |
+
auto operator()(Args&&...) const&
|
| 10553 |
+
-> decltype(!declval<invoke_result_t<const FD&, Args...>>());
|
| 10554 |
+
|
| 10555 |
+
template<class... Args>
|
| 10556 |
+
auto operator()(Args&&...) &&
|
| 10557 |
+
-> decltype(!declval<invoke_result_t<FD, Args...>>());
|
| 10558 |
+
|
| 10559 |
+
template<class... Args>
|
| 10560 |
+
auto operator()(Args&&...) const&&
|
| 10561 |
+
-> decltype(!declval<invoke_result_t<const FD, Args...>>());
|
| 10562 |
};
|
| 10563 |
```
|
| 10564 |
|
|
|
|
|
|
|
| 10565 |
``` cpp
|
| 10566 |
+
explicit call_wrapper(F&& f);
|
|
|
|
| 10567 |
```
|
| 10568 |
|
| 10569 |
+
*Requires:* `FD` shall satisfy the requirements of `MoveConstructible`.
|
| 10570 |
+
`is_constructible_v<FD, F>` shall be `true`. `fd` shall be a callable
|
| 10571 |
+
object ([[func.def]]).
|
| 10572 |
+
|
| 10573 |
+
*Effects:* Initializes `fd` from `std::forward<F>(f)`.
|
| 10574 |
+
|
| 10575 |
+
*Throws:* Any exception thrown by construction of `fd`.
|
| 10576 |
|
| 10577 |
``` cpp
|
| 10578 |
+
template<class... Args>
|
| 10579 |
+
auto operator()(Args&&... args) &
|
| 10580 |
+
-> decltype(!declval<invoke_result_t<FD&, Args...>>());
|
| 10581 |
+
template<class... Args>
|
| 10582 |
+
auto operator()(Args&&... args) const&
|
| 10583 |
+
-> decltype(!declval<invoke_result_t<const FD&, Args...>>());
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10584 |
```
|
| 10585 |
|
| 10586 |
+
*Effects:* Equivalent to:
|
| 10587 |
|
| 10588 |
``` cpp
|
| 10589 |
+
return !INVOKE(fd, std::forward<Args>(args)...); // see [func.require]
|
|
|
|
| 10590 |
```
|
| 10591 |
|
| 10592 |
+
``` cpp
|
| 10593 |
+
template<class... Args>
|
| 10594 |
+
auto operator()(Args&&... args) &&
|
| 10595 |
+
-> decltype(!declval<invoke_result_t<FD, Args...>>());
|
| 10596 |
+
template<class... Args>
|
| 10597 |
+
auto operator()(Args&&... args) const&&
|
| 10598 |
+
-> decltype(!declval<invoke_result_t<const FD, Args...>>());
|
| 10599 |
+
```
|
| 10600 |
+
|
| 10601 |
+
*Effects:* Equivalent to:
|
| 10602 |
+
|
| 10603 |
+
``` cpp
|
| 10604 |
+
return !INVOKE(std::move(fd), std::forward<Args>(args)...); // see [func.require]
|
| 10605 |
+
```
|
| 10606 |
|
| 10607 |
### Function object binders <a id="func.bind">[[func.bind]]</a>
|
| 10608 |
|
| 10609 |
This subclause describes a uniform mechanism for binding arguments of
|
| 10610 |
callable objects.
|
|
|
|
| 10615 |
namespace std {
|
| 10616 |
template<class T> struct is_bind_expression; // see below
|
| 10617 |
}
|
| 10618 |
```
|
| 10619 |
|
| 10620 |
+
The class template `is_bind_expression` can be used to detect function
|
| 10621 |
+
objects generated by `bind`. The function template `bind` uses
|
| 10622 |
+
`is_bind_expression` to detect subexpressions.
|
| 10623 |
|
| 10624 |
Instantiations of the `is_bind_expression` template shall meet the
|
| 10625 |
+
`UnaryTypeTrait` requirements ([[meta.rqmts]]). The implementation
|
| 10626 |
+
shall provide a definition that has a base characteristic of `true_type`
|
| 10627 |
+
if `T` is a type returned from `bind`, otherwise it shall have a base
|
| 10628 |
+
characteristic of `false_type`. A program may specialize this template
|
| 10629 |
+
for a user-defined type `T` to have a base characteristic of `true_type`
|
| 10630 |
+
to indicate that `T` should be treated as a subexpression in a `bind`
|
| 10631 |
+
call.
|
| 10632 |
|
| 10633 |
#### Class template `is_placeholder` <a id="func.bind.isplace">[[func.bind.isplace]]</a>
|
| 10634 |
|
| 10635 |
``` cpp
|
| 10636 |
namespace std {
|
| 10637 |
template<class T> struct is_placeholder; // see below
|
| 10638 |
}
|
| 10639 |
```
|
| 10640 |
|
| 10641 |
+
The class template `is_placeholder` can be used to detect the standard
|
| 10642 |
+
placeholders `_1`, `_2`, and so on. The function template `bind` uses
|
| 10643 |
+
`is_placeholder` to detect placeholders.
|
| 10644 |
|
| 10645 |
Instantiations of the `is_placeholder` template shall meet the
|
| 10646 |
+
`UnaryTypeTrait` requirements ([[meta.rqmts]]). The implementation
|
| 10647 |
+
shall provide a definition that has the base characteristic of
|
| 10648 |
`integral_constant<int, J>` if `T` is the type of
|
| 10649 |
+
`std::placeholders::_J`, otherwise it shall have a base characteristic
|
| 10650 |
+
of `integral_constant<int, 0>`. A program may specialize this template
|
| 10651 |
+
for a user-defined type `T` to have a base characteristic of
|
| 10652 |
`integral_constant<int, N>` with `N > 0` to indicate that `T` should be
|
| 10653 |
treated as a placeholder type.
|
| 10654 |
|
| 10655 |
#### Function template `bind` <a id="func.bind.bind">[[func.bind.bind]]</a>
|
| 10656 |
|
| 10657 |
+
In the text that follows:
|
|
|
|
| 10658 |
|
| 10659 |
- `FD` is the type `decay_t<F>`,
|
| 10660 |
- `fd` is an lvalue of type `FD` constructed from `std::forward<F>(f)`,
|
| 10661 |
+
- `Tᵢ` is the iᵗʰ type in the template parameter pack `BoundArgs`,
|
| 10662 |
+
- `TDᵢ` is the type `decay_t<Tᵢ>`,
|
| 10663 |
+
- `tᵢ` is the iᵗʰ argument in the function parameter pack `bound_args`,
|
| 10664 |
+
- `tdᵢ` is an lvalue of type `TDᵢ` constructed from
|
| 10665 |
+
`std::forward<Tᵢ>(tᵢ)`,
|
| 10666 |
+
- `Uⱼ` is the jᵗʰ deduced type of the `UnBoundArgs&&...` parameter of
|
| 10667 |
the forwarding call wrapper, and
|
| 10668 |
+
- `uⱼ` is the jᵗʰ argument associated with `Uⱼ`.
|
| 10669 |
|
| 10670 |
``` cpp
|
| 10671 |
template<class F, class... BoundArgs>
|
| 10672 |
unspecified bind(F&& f, BoundArgs&&... bound_args);
|
| 10673 |
```
|
| 10674 |
|
| 10675 |
+
*Requires:* `is_constructible_v<FD, F>` shall be `true`. For each `Tᵢ`
|
| 10676 |
+
in `BoundArgs`, `is_constructible_v<``TDᵢ``, ``Tᵢ``>` shall be `true`.
|
| 10677 |
+
*INVOKE*(fd, w₁, w₂, …, $w_N$) ([[func.require]]) shall be a valid
|
| 10678 |
+
expression for some values `w₁`, `w₂`, …, `w_N`, where N has the value
|
| 10679 |
+
`sizeof...(bound_args)`. The cv-qualifiers cv of the call wrapper `g`,
|
| 10680 |
+
as specified below, shall be neither `volatile` nor `const volatile`.
|
| 10681 |
|
| 10682 |
+
*Returns:* A forwarding call wrapper `g` ([[func.require]]). The effect
|
| 10683 |
+
of `g(``u₁``, ``u₂``, …, ``u_M``)` shall be
|
| 10684 |
+
|
| 10685 |
+
``` cpp
|
| 10686 |
+
INVOKE(fd, std::forward<$V_1$>($v_1$), std::forward<$V_2$>($v_2$), … , std::forward<$V_N$>($v_N$))
|
| 10687 |
+
```
|
| 10688 |
+
|
| 10689 |
+
where the values and types of the bound arguments `v₁`, `v₂`, …, `v_N`
|
| 10690 |
+
are determined as specified below. The copy constructor and move
|
| 10691 |
+
constructor of the forwarding call wrapper shall throw an exception if
|
| 10692 |
+
and only if the corresponding constructor of `FD` or of any of the types
|
| 10693 |
+
`TDᵢ` throws an exception.
|
| 10694 |
|
| 10695 |
*Throws:* Nothing unless the construction of `fd` or of one of the
|
| 10696 |
+
values `tdᵢ` throws an exception.
|
| 10697 |
|
| 10698 |
*Remarks:* The return type shall satisfy the requirements of
|
| 10699 |
+
`MoveConstructible`. If all of `FD` and `TDᵢ` satisfy the requirements
|
| 10700 |
of `CopyConstructible`, then the return type shall satisfy the
|
| 10701 |
+
requirements of `CopyConstructible`.
|
| 10702 |
+
|
| 10703 |
+
[*Note 1*: This implies that all of `FD` and `TDᵢ` are
|
| 10704 |
+
`MoveConstructible`. — *end note*]
|
| 10705 |
|
| 10706 |
``` cpp
|
| 10707 |
template<class R, class F, class... BoundArgs>
|
| 10708 |
unspecified bind(F&& f, BoundArgs&&... bound_args);
|
| 10709 |
```
|
| 10710 |
|
| 10711 |
+
*Requires:* `is_constructible_v<FD, F>` shall be `true`. For each `Tᵢ`
|
| 10712 |
+
in `BoundArgs`, `is_constructible_v<``TDᵢ``, ``Tᵢ``>` shall be `true`.
|
| 10713 |
+
*INVOKE*(fd, w₁, w₂, …, $w_N$) shall be a valid expression for some
|
| 10714 |
+
values `w₁`, `w₂`, …, `w_N`, where N has the value
|
| 10715 |
+
`sizeof...(bound_args)`. The cv-qualifiers cv of the call wrapper `g`,
|
| 10716 |
+
as specified below, shall be neither `volatile` nor `const volatile`.
|
| 10717 |
|
| 10718 |
+
*Returns:* A forwarding call wrapper `g` ([[func.require]]). The effect
|
| 10719 |
+
of `g(``u₁``, ``u₂``, …, ``u_M``)` shall be
|
| 10720 |
+
|
| 10721 |
+
``` cpp
|
| 10722 |
+
INVOKE<R>(fd, std::forward<$V_1$>($v_1$), std::forward<$V_2$>($v_2$), … , std::forward<$V_N$>($v_N$))
|
| 10723 |
+
```
|
| 10724 |
+
|
| 10725 |
+
where the values and types of the bound arguments `v₁`, `v₂`, …, `v_N`
|
| 10726 |
+
are determined as specified below. The copy constructor and move
|
| 10727 |
+
constructor of the forwarding call wrapper shall throw an exception if
|
| 10728 |
+
and only if the corresponding constructor of `FD` or of any of the types
|
| 10729 |
+
`TDᵢ` throws an exception.
|
| 10730 |
|
| 10731 |
*Throws:* Nothing unless the construction of `fd` or of one of the
|
| 10732 |
+
values `tdᵢ` throws an exception.
|
| 10733 |
|
| 10734 |
*Remarks:* The return type shall satisfy the requirements of
|
| 10735 |
+
`MoveConstructible`. If all of `FD` and `TDᵢ` satisfy the requirements
|
| 10736 |
of `CopyConstructible`, then the return type shall satisfy the
|
| 10737 |
+
requirements of `CopyConstructible`.
|
|
|
|
| 10738 |
|
| 10739 |
+
[*Note 2*: This implies that all of `FD` and `TDᵢ` are
|
| 10740 |
+
`MoveConstructible`. — *end note*]
|
|
|
|
|
|
|
| 10741 |
|
| 10742 |
+
The values of the *bound arguments* `v₁`, `v₂`, …, `v_N` and their
|
| 10743 |
+
corresponding types `V₁`, `V₂`, …, `V_N` depend on the types `TDᵢ`
|
| 10744 |
+
derived from the call to `bind` and the cv-qualifiers cv of the call
|
| 10745 |
+
wrapper `g` as follows:
|
| 10746 |
+
|
| 10747 |
+
- if `TDᵢ` is `reference_wrapper<T>`, the argument is `tdᵢ.get()` and
|
| 10748 |
+
its type `Vᵢ` is `T&`;
|
| 10749 |
+
- if the value of `is_bind_expression_v<TDᵢ>` is `true`, the argument is
|
| 10750 |
+
`tdᵢ(std::forward<Uⱼ>(uⱼ)...)` and its type `Vᵢ` is
|
| 10751 |
+
`invoke_result_t<TDᵢ cv &, Uⱼ...>&&`;
|
| 10752 |
+
- if the value `j` of `is_placeholder_v<TDᵢ>` is not zero, the argument
|
| 10753 |
+
is `std::forward<Uⱼ>(uⱼ)` and its type `Vᵢ` is `Uⱼ&&`;
|
| 10754 |
+
- otherwise, the value is `tdᵢ` and its type `Vᵢ` is `TDᵢ cv &`.
|
| 10755 |
|
| 10756 |
#### Placeholders <a id="func.bind.place">[[func.bind.place]]</a>
|
| 10757 |
|
| 10758 |
``` cpp
|
| 10759 |
+
namespace std::placeholders {
|
|
|
|
| 10760 |
// M is the implementation-defined number of placeholders
|
| 10761 |
+
see below _1;
|
| 10762 |
+
see below _2;
|
| 10763 |
.
|
| 10764 |
.
|
| 10765 |
.
|
| 10766 |
+
see below _M;
|
|
|
|
| 10767 |
}
|
| 10768 |
```
|
| 10769 |
|
| 10770 |
All placeholder types shall be `DefaultConstructible` and
|
| 10771 |
`CopyConstructible`, and their default constructors and copy/move
|
| 10772 |
constructors shall not throw exceptions. It is *implementation-defined*
|
| 10773 |
whether placeholder types are `CopyAssignable`. `CopyAssignable`
|
| 10774 |
placeholders’ copy assignment operators shall not throw exceptions.
|
| 10775 |
|
| 10776 |
+
Placeholders should be defined as:
|
| 10777 |
+
|
| 10778 |
+
``` cpp
|
| 10779 |
+
inline constexpr unspecified _1{};
|
| 10780 |
+
```
|
| 10781 |
+
|
| 10782 |
+
If they are not, they shall be declared as:
|
| 10783 |
+
|
| 10784 |
+
``` cpp
|
| 10785 |
+
extern unspecified _1;
|
| 10786 |
+
```
|
| 10787 |
+
|
| 10788 |
### Function template `mem_fn` <a id="func.memfn">[[func.memfn]]</a>
|
| 10789 |
|
| 10790 |
``` cpp
|
| 10791 |
+
template<class R, class T> unspecified mem_fn(R T::* pm) noexcept;
|
| 10792 |
```
|
| 10793 |
|
| 10794 |
*Returns:* A simple call wrapper ([[func.def]]) `fn` such that the
|
| 10795 |
+
expression `fn(t, a2, ..., aN)` is equivalent to *INVOKE*(pm, t, a2,
|
| 10796 |
+
..., aN) ([[func.require]]).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10797 |
|
| 10798 |
### Polymorphic function wrappers <a id="func.wrap">[[func.wrap]]</a>
|
| 10799 |
|
| 10800 |
This subclause describes a polymorphic wrapper class that encapsulates
|
| 10801 |
arbitrary callable objects.
|
|
|
|
| 10806 |
`function::operator()` ([[func.wrap.func.inv]]) when the function
|
| 10807 |
wrapper object has no target.
|
| 10808 |
|
| 10809 |
``` cpp
|
| 10810 |
namespace std {
|
| 10811 |
+
class bad_function_call : public exception {
|
| 10812 |
public:
|
| 10813 |
+
// [func.wrap.badcall.const], constructor
|
| 10814 |
bad_function_call() noexcept;
|
| 10815 |
};
|
| 10816 |
+
}
|
| 10817 |
```
|
| 10818 |
|
| 10819 |
##### `bad_function_call` constructor <a id="func.wrap.badcall.const">[[func.wrap.badcall.const]]</a>
|
| 10820 |
|
| 10821 |
``` cpp
|
| 10822 |
bad_function_call() noexcept;
|
| 10823 |
```
|
| 10824 |
|
| 10825 |
+
*Effects:* Constructs a `bad_function_call` object.
|
| 10826 |
+
|
| 10827 |
+
*Postconditions:* `what()` returns an *implementation-defined* NTBS.
|
| 10828 |
|
| 10829 |
#### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
|
| 10830 |
|
| 10831 |
``` cpp
|
| 10832 |
namespace std {
|
| 10833 |
+
template<class> class function; // not defined
|
| 10834 |
|
| 10835 |
template<class R, class... ArgTypes>
|
| 10836 |
class function<R(ArgTypes...)> {
|
| 10837 |
public:
|
| 10838 |
+
using result_type = R;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10839 |
|
| 10840 |
+
// [func.wrap.func.con], construct/copy/destroy
|
| 10841 |
function() noexcept;
|
| 10842 |
function(nullptr_t) noexcept;
|
| 10843 |
function(const function&);
|
| 10844 |
function(function&&);
|
| 10845 |
template<class F> function(F);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10846 |
|
| 10847 |
function& operator=(const function&);
|
| 10848 |
function& operator=(function&&);
|
| 10849 |
+
function& operator=(nullptr_t) noexcept;
|
| 10850 |
template<class F> function& operator=(F&&);
|
| 10851 |
template<class F> function& operator=(reference_wrapper<F>) noexcept;
|
| 10852 |
|
| 10853 |
~function();
|
| 10854 |
|
| 10855 |
+
// [func.wrap.func.mod], function modifiers
|
| 10856 |
void swap(function&) noexcept;
|
|
|
|
| 10857 |
|
| 10858 |
+
// [func.wrap.func.cap], function capacity
|
| 10859 |
explicit operator bool() const noexcept;
|
| 10860 |
|
| 10861 |
+
// [func.wrap.func.inv], function invocation
|
| 10862 |
R operator()(ArgTypes...) const;
|
| 10863 |
|
| 10864 |
+
// [func.wrap.func.targ], function target access
|
| 10865 |
+
const type_info& target_type() const noexcept;
|
| 10866 |
template<class T> T* target() noexcept;
|
| 10867 |
template<class T> const T* target() const noexcept;
|
|
|
|
| 10868 |
};
|
| 10869 |
|
| 10870 |
+
template<class R, class... ArgTypes>
|
| 10871 |
+
function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>;
|
| 10872 |
+
|
| 10873 |
+
template<class F> function(F) -> function<see below>;
|
| 10874 |
+
|
| 10875 |
+
// [func.wrap.func.nullptr], Null pointer comparisons
|
| 10876 |
template <class R, class... ArgTypes>
|
| 10877 |
bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
|
| 10878 |
|
| 10879 |
template <class R, class... ArgTypes>
|
| 10880 |
bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
|
|
|
|
| 10883 |
bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
|
| 10884 |
|
| 10885 |
template <class R, class... ArgTypes>
|
| 10886 |
bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
|
| 10887 |
|
| 10888 |
+
// [func.wrap.func.alg], specialized algorithms
|
| 10889 |
template <class R, class... ArgTypes>
|
| 10890 |
+
void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10891 |
}
|
| 10892 |
```
|
| 10893 |
|
| 10894 |
The `function` class template provides polymorphic wrappers that
|
| 10895 |
generalize the notion of a function pointer. Wrappers can store, copy,
|
| 10896 |
and call arbitrary callable objects ([[func.def]]), given a call
|
| 10897 |
signature ([[func.def]]), allowing functions to be first-class objects.
|
| 10898 |
|
| 10899 |
+
A callable type ([[func.def]]) `F` is *Lvalue-Callable* for argument
|
| 10900 |
+
types `ArgTypes` and return type `R` if the expression
|
| 10901 |
+
`INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
|
| 10902 |
+
unevaluated operand (Clause [[expr]]), is well formed (
|
| 10903 |
+
[[func.require]]).
|
| 10904 |
|
| 10905 |
The `function` class template is a call wrapper ([[func.def]]) whose
|
| 10906 |
call signature ([[func.def]]) is `R(ArgTypes...)`.
|
| 10907 |
|
| 10908 |
+
[*Note 1*: The types deduced by the deduction guides for `function` may
|
| 10909 |
+
change in future versions of this International Standard. — *end note*]
|
| 10910 |
+
|
| 10911 |
##### `function` construct/copy/destroy <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
|
| 10912 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10913 |
``` cpp
|
| 10914 |
function() noexcept;
|
|
|
|
| 10915 |
```
|
| 10916 |
|
| 10917 |
*Postconditions:* `!*this`.
|
| 10918 |
|
| 10919 |
``` cpp
|
| 10920 |
function(nullptr_t) noexcept;
|
|
|
|
| 10921 |
```
|
| 10922 |
|
| 10923 |
*Postconditions:* `!*this`.
|
| 10924 |
|
| 10925 |
``` cpp
|
| 10926 |
function(const function& f);
|
|
|
|
| 10927 |
```
|
| 10928 |
|
| 10929 |
*Postconditions:* `!*this` if `!f`; otherwise, `*this` targets a copy of
|
| 10930 |
`f.target()`.
|
| 10931 |
|
| 10932 |
+
*Throws:* shall not throw exceptions if `f`’s target is a specialization
|
| 10933 |
+
of `reference_wrapper` or a function pointer. Otherwise, may throw
|
| 10934 |
+
`bad_alloc` or any exception thrown by the copy constructor of the
|
| 10935 |
+
stored callable object.
|
| 10936 |
+
|
| 10937 |
+
[*Note 1*: Implementations are encouraged to avoid the use of
|
| 10938 |
+
dynamically allocated memory for small callable objects, for example,
|
| 10939 |
+
where `f`’s target is an object holding only a pointer or reference to
|
| 10940 |
+
an object and a member function pointer. — *end note*]
|
| 10941 |
|
| 10942 |
``` cpp
|
| 10943 |
function(function&& f);
|
|
|
|
| 10944 |
```
|
| 10945 |
|
| 10946 |
+
*Postconditions:* If `!f`, `*this` has no target; otherwise, the target
|
| 10947 |
+
of `*this` is equivalent to the target of `f` before the construction,
|
| 10948 |
+
and `f` is in a valid state with an unspecified value.
|
| 10949 |
+
|
| 10950 |
+
*Throws:* shall not throw exceptions if `f`’s target is a specialization
|
| 10951 |
+
of `reference_wrapper` or a function pointer. Otherwise, may throw
|
| 10952 |
+
`bad_alloc` or any exception thrown by the copy or move constructor of
|
| 10953 |
+
the stored callable object.
|
| 10954 |
+
|
| 10955 |
+
[*Note 2*: Implementations are encouraged to avoid the use of
|
| 10956 |
+
dynamically allocated memory for small callable objects, for example,
|
| 10957 |
+
where `f`’s target is an object holding only a pointer or reference to
|
| 10958 |
+
an object and a member function pointer. — *end note*]
|
| 10959 |
|
| 10960 |
``` cpp
|
| 10961 |
template<class F> function(F f);
|
|
|
|
| 10962 |
```
|
| 10963 |
|
| 10964 |
*Requires:* `F` shall be `CopyConstructible`.
|
| 10965 |
|
| 10966 |
+
*Remarks:* This constructor template shall not participate in overload
|
| 10967 |
+
resolution unless `F` is Lvalue-Callable ([[func.wrap.func]]) for
|
| 10968 |
+
argument types `ArgTypes...` and return type `R`.
|
| 10969 |
|
| 10970 |
*Postconditions:* `!*this` if any of the following hold:
|
| 10971 |
|
| 10972 |
- `f` is a null function pointer value.
|
| 10973 |
- `f` is a null member pointer value.
|
| 10974 |
- `F` is an instance of the `function` class template, and `!f`.
|
| 10975 |
|
| 10976 |
Otherwise, `*this` targets a copy of `f` initialized with
|
| 10977 |
+
`std::move(f)`.
|
| 10978 |
+
|
| 10979 |
+
[*Note 3*: Implementations are encouraged to avoid the use of
|
| 10980 |
dynamically allocated memory for small callable objects, for example,
|
| 10981 |
+
where `f` is an object holding only a pointer or reference to an object
|
| 10982 |
+
and a member function pointer. — *end note*]
|
| 10983 |
|
| 10984 |
*Throws:* shall not throw exceptions when `f` is a function pointer or a
|
| 10985 |
`reference_wrapper<T>` for some `T`. Otherwise, may throw `bad_alloc` or
|
| 10986 |
any exception thrown by `F`’s copy or move constructor.
|
| 10987 |
|
| 10988 |
+
``` cpp
|
| 10989 |
+
template<class F> function(F) -> function<see below>;
|
| 10990 |
+
```
|
| 10991 |
+
|
| 10992 |
+
*Remarks:* This deduction guide participates in overload resolution only
|
| 10993 |
+
if `&F::operator()` is well-formed when treated as an unevaluated
|
| 10994 |
+
operand. In that case, if `decltype(&F::operator())` is of the form
|
| 10995 |
+
`R(G::*)(A...)` cv `&`ₒₚₜ ` noexcept` for a class type `G`, then the
|
| 10996 |
+
deduced type is `function<R(A...)>`.
|
| 10997 |
+
|
| 10998 |
+
[*Example 1*:
|
| 10999 |
+
|
| 11000 |
+
``` cpp
|
| 11001 |
+
void f() {
|
| 11002 |
+
int i{5};
|
| 11003 |
+
function g = [&](double) { return i; }; // deduces function<int(double)>
|
| 11004 |
+
}
|
| 11005 |
+
```
|
| 11006 |
+
|
| 11007 |
+
— *end example*]
|
| 11008 |
+
|
| 11009 |
``` cpp
|
| 11010 |
function& operator=(const function& f);
|
| 11011 |
```
|
| 11012 |
|
| 11013 |
+
*Effects:* As if by `function(f).swap(*this);`
|
| 11014 |
|
| 11015 |
+
*Returns:* `*this`.
|
| 11016 |
|
| 11017 |
``` cpp
|
| 11018 |
function& operator=(function&& f);
|
| 11019 |
```
|
| 11020 |
|
| 11021 |
*Effects:* Replaces the target of `*this` with the target of `f`.
|
| 11022 |
|
| 11023 |
+
*Returns:* `*this`.
|
| 11024 |
|
| 11025 |
``` cpp
|
| 11026 |
+
function& operator=(nullptr_t) noexcept;
|
| 11027 |
```
|
| 11028 |
|
| 11029 |
*Effects:* If `*this != nullptr`, destroys the target of `this`.
|
| 11030 |
|
| 11031 |
*Postconditions:* `!(*this)`.
|
| 11032 |
|
| 11033 |
+
*Returns:* `*this`.
|
| 11034 |
|
| 11035 |
``` cpp
|
| 11036 |
template<class F> function& operator=(F&& f);
|
| 11037 |
```
|
| 11038 |
|
| 11039 |
+
*Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
|
| 11040 |
|
| 11041 |
+
*Returns:* `*this`.
|
| 11042 |
|
| 11043 |
*Remarks:* This assignment operator shall not participate in overload
|
| 11044 |
+
resolution unless `decay_t<F>` is Lvalue-Callable ([[func.wrap.func]])
|
| 11045 |
+
for argument types `ArgTypes...` and return type `R`.
|
|
|
|
| 11046 |
|
| 11047 |
``` cpp
|
| 11048 |
template<class F> function& operator=(reference_wrapper<F> f) noexcept;
|
| 11049 |
```
|
| 11050 |
|
| 11051 |
+
*Effects:* As if by: `function(f).swap(*this);`
|
| 11052 |
|
| 11053 |
+
*Returns:* `*this`.
|
| 11054 |
|
| 11055 |
``` cpp
|
| 11056 |
~function();
|
| 11057 |
```
|
| 11058 |
|
|
|
|
| 11064 |
void swap(function& other) noexcept;
|
| 11065 |
```
|
| 11066 |
|
| 11067 |
*Effects:* interchanges the targets of `*this` and `other`.
|
| 11068 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11069 |
##### `function` capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
|
| 11070 |
|
| 11071 |
``` cpp
|
| 11072 |
explicit operator bool() const noexcept;
|
| 11073 |
```
|
|
|
|
| 11075 |
*Returns:* `true` if `*this` has a target, otherwise `false`.
|
| 11076 |
|
| 11077 |
##### `function` invocation <a id="func.wrap.func.inv">[[func.wrap.func.inv]]</a>
|
| 11078 |
|
| 11079 |
``` cpp
|
| 11080 |
+
R operator()(ArgTypes... args) const;
|
| 11081 |
```
|
| 11082 |
|
| 11083 |
+
*Returns:* *INVOKE*\<R\>(f,
|
| 11084 |
+
std::forward\<ArgTypes\>(args)...) ([[func.require]]), where `f` is the
|
| 11085 |
+
target object ([[func.def]]) of `*this`.
|
|
|
|
|
|
|
|
|
|
| 11086 |
|
| 11087 |
*Throws:* `bad_function_call` if `!*this`; otherwise, any exception
|
| 11088 |
thrown by the wrapped callable object.
|
| 11089 |
|
| 11090 |
+
##### `function` target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
|
| 11091 |
|
| 11092 |
``` cpp
|
| 11093 |
+
const type_info& target_type() const noexcept;
|
| 11094 |
```
|
| 11095 |
|
| 11096 |
*Returns:* If `*this` has a target of type `T`, `typeid(T)`; otherwise,
|
| 11097 |
`typeid(void)`.
|
| 11098 |
|
| 11099 |
``` cpp
|
| 11100 |
template<class T> T* target() noexcept;
|
| 11101 |
template<class T> const T* target() const noexcept;
|
| 11102 |
```
|
| 11103 |
|
|
|
|
|
|
|
|
|
|
| 11104 |
*Returns:* If `target_type() == typeid(T)` a pointer to the stored
|
| 11105 |
function target; otherwise a null pointer.
|
| 11106 |
|
| 11107 |
+
##### null pointer comparison functions <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
|
| 11108 |
|
| 11109 |
``` cpp
|
| 11110 |
template <class R, class... ArgTypes>
|
| 11111 |
bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
|
| 11112 |
template <class R, class... ArgTypes>
|
|
|
|
| 11126 |
|
| 11127 |
##### specialized algorithms <a id="func.wrap.func.alg">[[func.wrap.func.alg]]</a>
|
| 11128 |
|
| 11129 |
``` cpp
|
| 11130 |
template<class R, class... ArgTypes>
|
| 11131 |
+
void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
|
| 11132 |
```
|
| 11133 |
|
| 11134 |
+
*Effects:* As if by: `f1.swap(f2);`
|
| 11135 |
+
|
| 11136 |
+
### Searchers <a id="func.search">[[func.search]]</a>
|
| 11137 |
+
|
| 11138 |
+
This subclause provides function object types ([[function.objects]])
|
| 11139 |
+
for operations that search for a sequence \[`pat``first`, `pat_last`) in
|
| 11140 |
+
another sequence \[`first`, `last`) that is provided to the object’s
|
| 11141 |
+
function call operator. The first sequence (the pattern to be searched
|
| 11142 |
+
for) is provided to the object’s constructor, and the second (the
|
| 11143 |
+
sequence to be searched) is provided to the function call operator.
|
| 11144 |
+
|
| 11145 |
+
Each specialization of a class template specified in this subclause
|
| 11146 |
+
[[func.search]] shall meet the `CopyConstructible` and `CopyAssignable`
|
| 11147 |
+
requirements. Template parameters named
|
| 11148 |
+
|
| 11149 |
+
- `ForwardIterator`,
|
| 11150 |
+
- `ForwardIterator1`,
|
| 11151 |
+
- `ForwardIterator2`,
|
| 11152 |
+
- `RandomAccessIterator`,
|
| 11153 |
+
- `RandomAccessIterator1`,
|
| 11154 |
+
- `RandomAccessIterator2`, and
|
| 11155 |
+
- `BinaryPredicate`
|
| 11156 |
+
|
| 11157 |
+
of templates specified in this subclause [[func.search]] shall meet the
|
| 11158 |
+
same requirements and semantics as specified in [[algorithms.general]].
|
| 11159 |
+
Template parameters named `Hash` shall meet the requirements as
|
| 11160 |
+
specified in [[hash.requirements]].
|
| 11161 |
+
|
| 11162 |
+
The Boyer-Moore searcher implements the Boyer-Moore search algorithm.
|
| 11163 |
+
The Boyer-Moore-Horspool searcher implements the Boyer-Moore-Horspool
|
| 11164 |
+
search algorithm. In general, the Boyer-Moore searcher will use more
|
| 11165 |
+
memory and give better runtime performance than Boyer-Moore-Horspool.
|
| 11166 |
+
|
| 11167 |
+
#### Class template `default_searcher` <a id="func.search.default">[[func.search.default]]</a>
|
| 11168 |
+
|
| 11169 |
+
``` cpp
|
| 11170 |
+
template <class ForwardIterator1, class BinaryPredicate = equal_to<>>
|
| 11171 |
+
class default_searcher {
|
| 11172 |
+
public:
|
| 11173 |
+
default_searcher(ForwardIterator1 pat_first, ForwardIterator1 pat_last,
|
| 11174 |
+
BinaryPredicate pred = BinaryPredicate());
|
| 11175 |
+
|
| 11176 |
+
template <class ForwardIterator2>
|
| 11177 |
+
pair<ForwardIterator2, ForwardIterator2>
|
| 11178 |
+
operator()(ForwardIterator2 first, ForwardIterator2 last) const;
|
| 11179 |
+
|
| 11180 |
+
private:
|
| 11181 |
+
ForwardIterator1 pat_first_; // exposition only
|
| 11182 |
+
ForwardIterator1 pat_last_; // exposition only
|
| 11183 |
+
BinaryPredicate pred_; // exposition only
|
| 11184 |
+
};
|
| 11185 |
+
```
|
| 11186 |
+
|
| 11187 |
+
``` cpp
|
| 11188 |
+
default_searcher(ForwardIterator pat_first, ForwardIterator pat_last,
|
| 11189 |
+
BinaryPredicate pred = BinaryPredicate());
|
| 11190 |
+
```
|
| 11191 |
+
|
| 11192 |
+
*Effects:* Constructs a `default_searcher` object, initializing
|
| 11193 |
+
`pat_first_` with `pat_first`, \texttt{pat_last\_} with `pat_last`, and
|
| 11194 |
+
`pred_` with `pred`.
|
| 11195 |
+
|
| 11196 |
+
*Throws:* Any exception thrown by the copy constructor of
|
| 11197 |
+
`BinaryPredicate` or `ForwardIterator1`.
|
| 11198 |
+
|
| 11199 |
+
``` cpp
|
| 11200 |
+
template<class ForwardIterator2>
|
| 11201 |
+
pair<ForwardIterator2, ForwardIterator2>
|
| 11202 |
+
operator()(ForwardIterator2 first, ForwardIterator2 last) const;
|
| 11203 |
+
```
|
| 11204 |
+
|
| 11205 |
+
*Effects:* Returns a pair of iterators `i` and `j` such that
|
| 11206 |
+
|
| 11207 |
+
- `i == search(first, last, pat_first_, pat_last_, pred_)`, and
|
| 11208 |
+
- if `i == last`, then `j == last`, otherwise
|
| 11209 |
+
`j == next(i, distance(pat_first_, pat_last_))`.
|
| 11210 |
+
|
| 11211 |
+
#### Class template `boyer_moore_searcher` <a id="func.search.bm">[[func.search.bm]]</a>
|
| 11212 |
+
|
| 11213 |
+
``` cpp
|
| 11214 |
+
template <class RandomAccessIterator1,
|
| 11215 |
+
class Hash = hash<typename iterator_traits<RandomAccessIterator1>::value_type>,
|
| 11216 |
+
class BinaryPredicate = equal_to<>>
|
| 11217 |
+
class boyer_moore_searcher {
|
| 11218 |
+
public:
|
| 11219 |
+
boyer_moore_searcher(RandomAccessIterator1 pat_first,
|
| 11220 |
+
RandomAccessIterator1 pat_last,
|
| 11221 |
+
Hash hf = Hash(),
|
| 11222 |
+
BinaryPredicate pred = BinaryPredicate());
|
| 11223 |
+
|
| 11224 |
+
template <class RandomAccessIterator2>
|
| 11225 |
+
pair<RandomAccessIterator2, RandomAccessIterator2>
|
| 11226 |
+
operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
|
| 11227 |
+
|
| 11228 |
+
private:
|
| 11229 |
+
RandomAccessIterator1 pat_first_; // exposition only
|
| 11230 |
+
RandomAccessIterator1 pat_last_; // exposition only
|
| 11231 |
+
Hash hash_; // exposition only
|
| 11232 |
+
BinaryPredicate pred_; // exposition only
|
| 11233 |
+
};
|
| 11234 |
+
```
|
| 11235 |
+
|
| 11236 |
+
``` cpp
|
| 11237 |
+
boyer_moore_searcher(RandomAccessIterator1 pat_first,
|
| 11238 |
+
RandomAccessIterator1 pat_last,
|
| 11239 |
+
Hash hf = Hash(),
|
| 11240 |
+
BinaryPredicate pred = BinaryPredicate());
|
| 11241 |
+
```
|
| 11242 |
+
|
| 11243 |
+
*Requires:* The value type of `RandomAccessIterator1` shall meet the
|
| 11244 |
+
`DefaultConstructible` requirements, the `CopyConstructible`
|
| 11245 |
+
requirements, and the `CopyAssignable` requirements.
|
| 11246 |
+
|
| 11247 |
+
*Requires:* For any two values `A` and `B` of the type
|
| 11248 |
+
`iterator_traits<RandomAccessIterator1>::value_type`, if
|
| 11249 |
+
`pred(A, B) == true`, then `hf(A) == hf(B)` shall be `true`.
|
| 11250 |
+
|
| 11251 |
+
*Effects:* Constructs a `boyer_moore_searcher` object, initializing
|
| 11252 |
+
`pat_first_` with `pat_first`, `pat_last_` with `pat_last`, `hash_` with
|
| 11253 |
+
`hf`, and `pred_` with `pred`.
|
| 11254 |
+
|
| 11255 |
+
*Throws:* Any exception thrown by the copy constructor of
|
| 11256 |
+
`RandomAccessIterator1`, or by the default constructor, copy
|
| 11257 |
+
constructor, or the copy assignment operator of the value type of
|
| 11258 |
+
`RandomAccessIterator1`, or the copy constructor or `operator()` of
|
| 11259 |
+
`BinaryPredicate` or `Hash`. May throw `bad_alloc` if additional memory
|
| 11260 |
+
needed for internal data structures cannot be allocated.
|
| 11261 |
+
|
| 11262 |
+
``` cpp
|
| 11263 |
+
template <class RandomAccessIterator2>
|
| 11264 |
+
pair<RandomAccessIterator2, RandomAccessIterator2>
|
| 11265 |
+
operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
|
| 11266 |
+
```
|
| 11267 |
+
|
| 11268 |
+
*Requires:* `RandomAccessIterator1` and `RandomAccessIterator2` shall
|
| 11269 |
+
have the same value type.
|
| 11270 |
+
|
| 11271 |
+
*Effects:* Finds a subsequence of equal values in a sequence.
|
| 11272 |
+
|
| 11273 |
+
*Returns:* A pair of iterators `i` and `j` such that
|
| 11274 |
+
|
| 11275 |
+
- `i` is the first iterator in the range \[`first`,
|
| 11276 |
+
`last - (pat_last_ - pat_first_)`) such that for every non-negative
|
| 11277 |
+
integer `n` less than `pat_last_ - pat_first_` the following condition
|
| 11278 |
+
holds: `pred(*(i + n), *(pat_first_ + n)) != false`, and
|
| 11279 |
+
- `j == next(i, distance(pat_first_, pat_last_))`.
|
| 11280 |
+
|
| 11281 |
+
Returns `make_pair(first, first)` if \[`pat_first_`, `pat_last_`) is
|
| 11282 |
+
empty, otherwise returns `make_pair(last, last)` if no such iterator is
|
| 11283 |
+
found.
|
| 11284 |
+
|
| 11285 |
+
*Complexity:* At most `(last - first) * (pat_last_ - pat_first_)`
|
| 11286 |
+
applications of the predicate.
|
| 11287 |
+
|
| 11288 |
+
#### Class template `boyer_moore_horspool_searcher` <a id="func.search.bmh">[[func.search.bmh]]</a>
|
| 11289 |
+
|
| 11290 |
+
``` cpp
|
| 11291 |
+
template <class RandomAccessIterator1,
|
| 11292 |
+
class Hash = hash<typename iterator_traits<RandomAccessIterator1>::value_type>,
|
| 11293 |
+
class BinaryPredicate = equal_to<>>
|
| 11294 |
+
class boyer_moore_horspool_searcher {
|
| 11295 |
+
public:
|
| 11296 |
+
boyer_moore_horspool_searcher(RandomAccessIterator1 pat_first,
|
| 11297 |
+
RandomAccessIterator1 pat_last,
|
| 11298 |
+
Hash hf = Hash(),
|
| 11299 |
+
BinaryPredicate pred = BinaryPredicate());
|
| 11300 |
+
|
| 11301 |
+
template <class RandomAccessIterator2>
|
| 11302 |
+
pair<RandomAccessIterator2, RandomAccessIterator2>
|
| 11303 |
+
operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
|
| 11304 |
+
|
| 11305 |
+
private:
|
| 11306 |
+
RandomAccessIterator1 pat_first_; // exposition only
|
| 11307 |
+
RandomAccessIterator1 pat_last_; // exposition only
|
| 11308 |
+
Hash hash_; // exposition only
|
| 11309 |
+
BinaryPredicate pred_; // exposition only
|
| 11310 |
+
};
|
| 11311 |
+
```
|
| 11312 |
+
|
| 11313 |
+
``` cpp
|
| 11314 |
+
boyer_moore_horspool_searcher(RandomAccessIterator1 pat_first,
|
| 11315 |
+
RandomAccessIterator1 pat_last,
|
| 11316 |
+
Hash hf = Hash(),
|
| 11317 |
+
BinaryPredicate pred = BinaryPredicate());
|
| 11318 |
+
```
|
| 11319 |
+
|
| 11320 |
+
*Requires:* The value type of `RandomAccessIterator1` shall meet the
|
| 11321 |
+
`DefaultConstructible`, `CopyConstructible`, and `CopyAssignable`
|
| 11322 |
+
requirements.
|
| 11323 |
+
|
| 11324 |
+
*Requires:* For any two values `A` and `B` of the type
|
| 11325 |
+
`iterator_traits<RandomAccessIterator1>::value_type`, if
|
| 11326 |
+
`pred(A, B) == true`, then `hf(A) == hf(B)` shall be `true`.
|
| 11327 |
+
|
| 11328 |
+
*Effects:* Constructs a `boyer_moore_horspool_searcher` object,
|
| 11329 |
+
initializing `pat_first_` with `pat_first`, `pat_last_` with `pat_last`,
|
| 11330 |
+
`hash_` with `hf`, and `pred_` with `pred`.
|
| 11331 |
+
|
| 11332 |
+
*Throws:* Any exception thrown by the copy constructor of
|
| 11333 |
+
`RandomAccessIterator1`, or by the default constructor, copy
|
| 11334 |
+
constructor, or the copy assignment operator of the value type of
|
| 11335 |
+
`RandomAccessIterator1` or the copy constructor or `operator()` of
|
| 11336 |
+
`BinaryPredicate` or `Hash`. May throw `bad_alloc` if additional memory
|
| 11337 |
+
needed for internal data structures cannot be allocated.
|
| 11338 |
+
|
| 11339 |
+
``` cpp
|
| 11340 |
+
template <class RandomAccessIterator2>
|
| 11341 |
+
pair<RandomAccessIterator2, RandomAccessIterator2>
|
| 11342 |
+
operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
|
| 11343 |
+
```
|
| 11344 |
+
|
| 11345 |
+
*Requires:* `RandomAccessIterator1` and `RandomAccessIterator2` shall
|
| 11346 |
+
have the same value type.
|
| 11347 |
+
|
| 11348 |
+
*Effects:* Finds a subsequence of equal values in a sequence.
|
| 11349 |
+
|
| 11350 |
+
*Returns:* A pair of iterators `i` and `j` such that
|
| 11351 |
+
|
| 11352 |
+
- `i` is the first iterator `i` in the range \[`first`,
|
| 11353 |
+
`last - (pat_last_ - pat_first_)`) such that for every non-negative
|
| 11354 |
+
integer `n` less than `pat_last_ - pat_first_` the following condition
|
| 11355 |
+
holds: `pred(*(i + n), *(pat_first_ + n)) != false`, and
|
| 11356 |
+
- `j == next(i, distance(pat_first_, pat_last_))`.
|
| 11357 |
+
|
| 11358 |
+
Returns `make_pair(first, first)` if \[`pat_first_`, `pat_last_`) is
|
| 11359 |
+
empty, otherwise returns `make_pair(last, last)` if no such iterator is
|
| 11360 |
+
found.
|
| 11361 |
+
|
| 11362 |
+
*Complexity:* At most `(last - first) * (pat_last_ - pat_first_)`
|
| 11363 |
+
applications of the predicate.
|
| 11364 |
|
| 11365 |
### Class template `hash` <a id="unord.hash">[[unord.hash]]</a>
|
| 11366 |
|
| 11367 |
The unordered associative containers defined in [[unord]] use
|
| 11368 |
+
specializations of the class template `hash` ([[functional.syn]]) as
|
| 11369 |
+
the default hash function.
|
| 11370 |
+
|
| 11371 |
+
Each specialization of `hash` is either enabled or disabled, as
|
| 11372 |
+
described below.
|
| 11373 |
+
|
| 11374 |
+
[*Note 1*: Enabled specializations meet the requirements of `Hash`, and
|
| 11375 |
+
disabled specializations do not. — *end note*]
|
| 11376 |
+
|
| 11377 |
+
Each header that declares the template `hash` provides enabled
|
| 11378 |
+
specializations of `hash` for `nullptr_t` and all cv-unqualified
|
| 11379 |
+
arithmetic, enumeration, and pointer types. For any type `Key` for which
|
| 11380 |
+
neither the library nor the user provides an explicit or partial
|
| 11381 |
+
specialization of the class template `hash`, `hash<Key>` is disabled.
|
| 11382 |
+
|
| 11383 |
+
If the library provides an explicit or partial specialization of
|
| 11384 |
+
`hash<Key>`, that specialization is enabled except as noted otherwise,
|
| 11385 |
+
and its member functions are `noexcept` except as noted otherwise.
|
| 11386 |
+
|
| 11387 |
+
If `H` is a disabled specialization of `hash`, these values are `false`:
|
| 11388 |
+
`is_default_constructible_v<H>`, `is_copy_constructible_v<H>`,
|
| 11389 |
+
`is_move_constructible_v<H>`, `is_copy_assignable_v<H>`, and
|
| 11390 |
+
`is_move_assignable_v<H>`. Disabled specializations of `hash` are not
|
| 11391 |
+
function object types ([[function.objects]]).
|
| 11392 |
+
|
| 11393 |
+
[*Note 2*: This means that the specialization of `hash` exists, but any
|
| 11394 |
+
attempts to use it as a `Hash` will be ill-formed. — *end note*]
|
| 11395 |
+
|
| 11396 |
+
An enabled specialization `hash<Key>` will:
|
| 11397 |
|
| 11398 |
- satisfy the `Hash` requirements ([[hash.requirements]]), with `Key`
|
| 11399 |
as the function call argument type, the `DefaultConstructible`
|
| 11400 |
+
requirements (Table [[tab:defaultconstructible]]), the
|
| 11401 |
+
`CopyAssignable` requirements (Table [[tab:copyassignable]]),
|
| 11402 |
- be swappable ([[swappable.requirements]]) for lvalues,
|
| 11403 |
+
- satisfy the requirement that if `k1 == k2` is `true`, `h(k1) == h(k2)`
|
| 11404 |
+
is also `true`, where `h` is an object of type `hash<Key>` and `k1`
|
| 11405 |
+
and `k2` are objects of type `Key`;
|
|
|
|
|
|
|
| 11406 |
- satisfy the requirement that the expression `h(k)`, where `h` is an
|
| 11407 |
object of type `hash<Key>` and `k` is an object of type `Key`, shall
|
| 11408 |
not throw an exception unless `hash<Key>` is a user-defined
|
| 11409 |
specialization that depends on at least one user-defined type.
|
| 11410 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11411 |
## Metaprogramming and type traits <a id="meta">[[meta]]</a>
|
| 11412 |
|
| 11413 |
This subclause describes components used by C++programs, particularly in
|
| 11414 |
templates, to support the widest possible range of types, optimise
|
| 11415 |
template code usage, detect type related user errors, and perform type
|
|
|
|
| 11420 |
given type belongs. The type property inspection traits allow important
|
| 11421 |
characteristics of types or of combinations of types to be inspected.
|
| 11422 |
The type transformations allow certain properties of types to be
|
| 11423 |
manipulated.
|
| 11424 |
|
| 11425 |
+
All functions specified in this subclause are signal-safe (
|
| 11426 |
+
[[csignal.syn]]).
|
| 11427 |
+
|
| 11428 |
### Requirements <a id="meta.rqmts">[[meta.rqmts]]</a>
|
| 11429 |
|
| 11430 |
A *UnaryTypeTrait* describes a property of a type. It shall be a class
|
| 11431 |
template that takes one template type argument and, optionally,
|
| 11432 |
additional arguments that help define the property being described. It
|
| 11433 |
shall be `DefaultConstructible`, `CopyConstructible`, and publicly and
|
| 11434 |
+
unambiguously derived, directly or indirectly, from its *base
|
| 11435 |
+
characteristic*, which is a specialization of the template
|
| 11436 |
`integral_constant` ([[meta.help]]), with the arguments to the template
|
| 11437 |
`integral_constant` determined by the requirements for the particular
|
| 11438 |
+
property being described. The member names of the base characteristic
|
| 11439 |
shall not be hidden and shall be unambiguously available in the
|
| 11440 |
+
`UnaryTypeTrait`.
|
| 11441 |
|
| 11442 |
A *BinaryTypeTrait* describes a relationship between two types. It shall
|
| 11443 |
be a class template that takes two template type arguments and,
|
| 11444 |
optionally, additional arguments that help define the relationship being
|
| 11445 |
described. It shall be `DefaultConstructible`, `CopyConstructible`, and
|
| 11446 |
publicly and unambiguously derived, directly or indirectly, from its
|
| 11447 |
+
*base characteristic*, which is a specialization of the template
|
| 11448 |
`integral_constant` ([[meta.help]]), with the arguments to the template
|
| 11449 |
`integral_constant` determined by the requirements for the particular
|
| 11450 |
+
relationship being described. The member names of the base
|
| 11451 |
+
characteristic shall not be hidden and shall be unambiguously available
|
| 11452 |
+
in the `BinaryTypeTrait`.
|
| 11453 |
|
| 11454 |
A *TransformationTrait* modifies a property of a type. It shall be a
|
| 11455 |
class template that takes one template type argument and, optionally,
|
| 11456 |
additional arguments that help define the modification. It shall define
|
| 11457 |
a publicly accessible nested type named `type`, which shall be a synonym
|
|
|
|
| 11459 |
|
| 11460 |
### Header `<type_traits>` synopsis <a id="meta.type.synop">[[meta.type.synop]]</a>
|
| 11461 |
|
| 11462 |
``` cpp
|
| 11463 |
namespace std {
|
| 11464 |
+
// [meta.help], helper class
|
| 11465 |
template <class T, T v> struct integral_constant;
|
|
|
|
|
|
|
| 11466 |
|
| 11467 |
+
template <bool B>
|
| 11468 |
+
using bool_constant = integral_constant<bool, B>;
|
| 11469 |
+
using true_type = bool_constant<true>;
|
| 11470 |
+
using false_type = bool_constant<false>;
|
| 11471 |
+
|
| 11472 |
+
// [meta.unary.cat], primary type categories
|
| 11473 |
template <class T> struct is_void;
|
| 11474 |
template <class T> struct is_null_pointer;
|
| 11475 |
template <class T> struct is_integral;
|
| 11476 |
template <class T> struct is_floating_point;
|
| 11477 |
template <class T> struct is_array;
|
|
|
|
| 11483 |
template <class T> struct is_enum;
|
| 11484 |
template <class T> struct is_union;
|
| 11485 |
template <class T> struct is_class;
|
| 11486 |
template <class T> struct is_function;
|
| 11487 |
|
| 11488 |
+
// [meta.unary.comp], composite type categories
|
| 11489 |
template <class T> struct is_reference;
|
| 11490 |
template <class T> struct is_arithmetic;
|
| 11491 |
template <class T> struct is_fundamental;
|
| 11492 |
template <class T> struct is_object;
|
| 11493 |
template <class T> struct is_scalar;
|
| 11494 |
template <class T> struct is_compound;
|
| 11495 |
template <class T> struct is_member_pointer;
|
| 11496 |
|
| 11497 |
+
// [meta.unary.prop], type properties
|
| 11498 |
template <class T> struct is_const;
|
| 11499 |
template <class T> struct is_volatile;
|
| 11500 |
template <class T> struct is_trivial;
|
| 11501 |
template <class T> struct is_trivially_copyable;
|
| 11502 |
template <class T> struct is_standard_layout;
|
| 11503 |
template <class T> struct is_pod;
|
|
|
|
| 11504 |
template <class T> struct is_empty;
|
| 11505 |
template <class T> struct is_polymorphic;
|
| 11506 |
template <class T> struct is_abstract;
|
| 11507 |
template <class T> struct is_final;
|
| 11508 |
+
template <class T> struct is_aggregate;
|
| 11509 |
|
| 11510 |
template <class T> struct is_signed;
|
| 11511 |
template <class T> struct is_unsigned;
|
| 11512 |
|
| 11513 |
template <class T, class... Args> struct is_constructible;
|
|
|
|
| 11517 |
|
| 11518 |
template <class T, class U> struct is_assignable;
|
| 11519 |
template <class T> struct is_copy_assignable;
|
| 11520 |
template <class T> struct is_move_assignable;
|
| 11521 |
|
| 11522 |
+
template <class T, class U> struct is_swappable_with;
|
| 11523 |
+
template <class T> struct is_swappable;
|
| 11524 |
+
|
| 11525 |
template <class T> struct is_destructible;
|
| 11526 |
|
| 11527 |
template <class T, class... Args> struct is_trivially_constructible;
|
| 11528 |
template <class T> struct is_trivially_default_constructible;
|
| 11529 |
template <class T> struct is_trivially_copy_constructible;
|
|
|
|
| 11541 |
|
| 11542 |
template <class T, class U> struct is_nothrow_assignable;
|
| 11543 |
template <class T> struct is_nothrow_copy_assignable;
|
| 11544 |
template <class T> struct is_nothrow_move_assignable;
|
| 11545 |
|
| 11546 |
+
template <class T, class U> struct is_nothrow_swappable_with;
|
| 11547 |
+
template <class T> struct is_nothrow_swappable;
|
| 11548 |
+
|
| 11549 |
template <class T> struct is_nothrow_destructible;
|
| 11550 |
+
|
| 11551 |
template <class T> struct has_virtual_destructor;
|
| 11552 |
|
| 11553 |
+
template <class T> struct has_unique_object_representations;
|
| 11554 |
+
|
| 11555 |
+
// [meta.unary.prop.query], type property queries
|
| 11556 |
template <class T> struct alignment_of;
|
| 11557 |
template <class T> struct rank;
|
| 11558 |
template <class T, unsigned I = 0> struct extent;
|
| 11559 |
|
| 11560 |
+
// [meta.rel], type relations
|
| 11561 |
template <class T, class U> struct is_same;
|
| 11562 |
template <class Base, class Derived> struct is_base_of;
|
| 11563 |
template <class From, class To> struct is_convertible;
|
| 11564 |
|
| 11565 |
+
template <class Fn, class... ArgTypes> struct is_invocable;
|
| 11566 |
+
template <class R, class Fn, class... ArgTypes> struct is_invocable_r;
|
| 11567 |
+
|
| 11568 |
+
template <class Fn, class... ArgTypes> struct is_nothrow_invocable;
|
| 11569 |
+
template <class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r;
|
| 11570 |
+
|
| 11571 |
+
// [meta.trans.cv], const-volatile modifications
|
| 11572 |
template <class T> struct remove_const;
|
| 11573 |
template <class T> struct remove_volatile;
|
| 11574 |
template <class T> struct remove_cv;
|
| 11575 |
template <class T> struct add_const;
|
| 11576 |
template <class T> struct add_volatile;
|
|
|
|
| 11587 |
template <class T>
|
| 11588 |
using add_volatile_t = typename add_volatile<T>::type;
|
| 11589 |
template <class T>
|
| 11590 |
using add_cv_t = typename add_cv<T>::type;
|
| 11591 |
|
| 11592 |
+
// [meta.trans.ref], reference modifications
|
| 11593 |
template <class T> struct remove_reference;
|
| 11594 |
template <class T> struct add_lvalue_reference;
|
| 11595 |
template <class T> struct add_rvalue_reference;
|
| 11596 |
|
| 11597 |
template <class T>
|
|
|
|
| 11599 |
template <class T>
|
| 11600 |
using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;
|
| 11601 |
template <class T>
|
| 11602 |
using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;
|
| 11603 |
|
| 11604 |
+
// [meta.trans.sign], sign modifications
|
| 11605 |
template <class T> struct make_signed;
|
| 11606 |
template <class T> struct make_unsigned;
|
| 11607 |
|
| 11608 |
template <class T>
|
| 11609 |
using make_signed_t = typename make_signed<T>::type;
|
| 11610 |
template <class T>
|
| 11611 |
using make_unsigned_t = typename make_unsigned<T>::type;
|
| 11612 |
|
| 11613 |
+
// [meta.trans.arr], array modifications
|
| 11614 |
template <class T> struct remove_extent;
|
| 11615 |
template <class T> struct remove_all_extents;
|
| 11616 |
|
| 11617 |
template <class T>
|
| 11618 |
using remove_extent_t = typename remove_extent<T>::type;
|
| 11619 |
template <class T>
|
| 11620 |
using remove_all_extents_t = typename remove_all_extents<T>::type;
|
| 11621 |
|
| 11622 |
+
// [meta.trans.ptr], pointer modifications
|
| 11623 |
template <class T> struct remove_pointer;
|
| 11624 |
template <class T> struct add_pointer;
|
| 11625 |
|
| 11626 |
template <class T>
|
| 11627 |
using remove_pointer_t = typename remove_pointer<T>::type;
|
| 11628 |
template <class T>
|
| 11629 |
using add_pointer_t = typename add_pointer<T>::type;
|
| 11630 |
|
| 11631 |
+
// [meta.trans.other], other transformations
|
| 11632 |
+
template <size_t Len,
|
| 11633 |
+
size_t Align = default-alignment> // see [meta.trans.other]
|
| 11634 |
struct aligned_storage;
|
| 11635 |
+
template <size_t Len, class... Types> struct aligned_union;
|
| 11636 |
template <class T> struct decay;
|
| 11637 |
template <bool, class T = void> struct enable_if;
|
| 11638 |
template <bool, class T, class F> struct conditional;
|
| 11639 |
template <class... T> struct common_type;
|
| 11640 |
template <class T> struct underlying_type;
|
| 11641 |
+
template <class Fn, class... ArgTypes> struct invoke_result;
|
|
|
|
| 11642 |
|
| 11643 |
+
template <size_t Len,
|
| 11644 |
+
size_t Align = default-alignment> // see [meta.trans.other]
|
| 11645 |
using aligned_storage_t = typename aligned_storage<Len, Align>::type;
|
| 11646 |
+
template <size_t Len, class... Types>
|
| 11647 |
using aligned_union_t = typename aligned_union<Len, Types...>::type;
|
| 11648 |
template <class T>
|
| 11649 |
using decay_t = typename decay<T>::type;
|
| 11650 |
template <bool b, class T = void>
|
| 11651 |
using enable_if_t = typename enable_if<b, T>::type;
|
|
|
|
| 11653 |
using conditional_t = typename conditional<b, T, F>::type;
|
| 11654 |
template <class... T>
|
| 11655 |
using common_type_t = typename common_type<T...>::type;
|
| 11656 |
template <class T>
|
| 11657 |
using underlying_type_t = typename underlying_type<T>::type;
|
| 11658 |
+
template <class Fn, class... ArgTypes>
|
| 11659 |
+
using invoke_result_t = typename invoke_result<Fn, ArgTypes...>::type;
|
| 11660 |
+
template <class...>
|
| 11661 |
+
using void_t = void;
|
| 11662 |
+
|
| 11663 |
+
// [meta.logical], logical operator traits
|
| 11664 |
+
template<class... B> struct conjunction;
|
| 11665 |
+
template<class... B> struct disjunction;
|
| 11666 |
+
template<class B> struct negation;
|
| 11667 |
+
|
| 11668 |
+
// [meta.unary.cat], primary type categories
|
| 11669 |
+
template <class T> inline constexpr bool is_void_v
|
| 11670 |
+
= is_void<T>::value;
|
| 11671 |
+
template <class T> inline constexpr bool is_null_pointer_v
|
| 11672 |
+
= is_null_pointer<T>::value;
|
| 11673 |
+
template <class T> inline constexpr bool is_integral_v
|
| 11674 |
+
= is_integral<T>::value;
|
| 11675 |
+
template <class T> inline constexpr bool is_floating_point_v
|
| 11676 |
+
= is_floating_point<T>::value;
|
| 11677 |
+
template <class T> inline constexpr bool is_array_v
|
| 11678 |
+
= is_array<T>::value;
|
| 11679 |
+
template <class T> inline constexpr bool is_pointer_v
|
| 11680 |
+
= is_pointer<T>::value;
|
| 11681 |
+
template <class T> inline constexpr bool is_lvalue_reference_v
|
| 11682 |
+
= is_lvalue_reference<T>::value;
|
| 11683 |
+
template <class T> inline constexpr bool is_rvalue_reference_v
|
| 11684 |
+
= is_rvalue_reference<T>::value;
|
| 11685 |
+
template <class T> inline constexpr bool is_member_object_pointer_v
|
| 11686 |
+
= is_member_object_pointer<T>::value;
|
| 11687 |
+
template <class T> inline constexpr bool is_member_function_pointer_v
|
| 11688 |
+
= is_member_function_pointer<T>::value;
|
| 11689 |
+
template <class T> inline constexpr bool is_enum_v
|
| 11690 |
+
= is_enum<T>::value;
|
| 11691 |
+
template <class T> inline constexpr bool is_union_v
|
| 11692 |
+
= is_union<T>::value;
|
| 11693 |
+
template <class T> inline constexpr bool is_class_v
|
| 11694 |
+
= is_class<T>::value;
|
| 11695 |
+
template <class T> inline constexpr bool is_function_v
|
| 11696 |
+
= is_function<T>::value;
|
| 11697 |
+
|
| 11698 |
+
// [meta.unary.comp], composite type categories
|
| 11699 |
+
template <class T> inline constexpr bool is_reference_v
|
| 11700 |
+
= is_reference<T>::value;
|
| 11701 |
+
template <class T> inline constexpr bool is_arithmetic_v
|
| 11702 |
+
= is_arithmetic<T>::value;
|
| 11703 |
+
template <class T> inline constexpr bool is_fundamental_v
|
| 11704 |
+
= is_fundamental<T>::value;
|
| 11705 |
+
template <class T> inline constexpr bool is_object_v
|
| 11706 |
+
= is_object<T>::value;
|
| 11707 |
+
template <class T> inline constexpr bool is_scalar_v
|
| 11708 |
+
= is_scalar<T>::value;
|
| 11709 |
+
template <class T> inline constexpr bool is_compound_v
|
| 11710 |
+
= is_compound<T>::value;
|
| 11711 |
+
template <class T> inline constexpr bool is_member_pointer_v
|
| 11712 |
+
= is_member_pointer<T>::value;
|
| 11713 |
+
|
| 11714 |
+
// [meta.unary.prop], type properties
|
| 11715 |
+
template <class T> inline constexpr bool is_const_v
|
| 11716 |
+
= is_const<T>::value;
|
| 11717 |
+
template <class T> inline constexpr bool is_volatile_v
|
| 11718 |
+
= is_volatile<T>::value;
|
| 11719 |
+
template <class T> inline constexpr bool is_trivial_v
|
| 11720 |
+
= is_trivial<T>::value;
|
| 11721 |
+
template <class T> inline constexpr bool is_trivially_copyable_v
|
| 11722 |
+
= is_trivially_copyable<T>::value;
|
| 11723 |
+
template <class T> inline constexpr bool is_standard_layout_v
|
| 11724 |
+
= is_standard_layout<T>::value;
|
| 11725 |
+
template <class T> inline constexpr bool is_pod_v
|
| 11726 |
+
= is_pod<T>::value;
|
| 11727 |
+
template <class T> inline constexpr bool is_empty_v
|
| 11728 |
+
= is_empty<T>::value;
|
| 11729 |
+
template <class T> inline constexpr bool is_polymorphic_v
|
| 11730 |
+
= is_polymorphic<T>::value;
|
| 11731 |
+
template <class T> inline constexpr bool is_abstract_v
|
| 11732 |
+
= is_abstract<T>::value;
|
| 11733 |
+
template <class T> inline constexpr bool is_final_v
|
| 11734 |
+
= is_final<T>::value;
|
| 11735 |
+
template <class T> inline constexpr bool is_aggregate_v
|
| 11736 |
+
= is_aggregate<T>::value;
|
| 11737 |
+
template <class T> inline constexpr bool is_signed_v
|
| 11738 |
+
= is_signed<T>::value;
|
| 11739 |
+
template <class T> inline constexpr bool is_unsigned_v
|
| 11740 |
+
= is_unsigned<T>::value;
|
| 11741 |
+
template <class T, class... Args> inline constexpr bool is_constructible_v
|
| 11742 |
+
= is_constructible<T, Args...>::value;
|
| 11743 |
+
template <class T> inline constexpr bool is_default_constructible_v
|
| 11744 |
+
= is_default_constructible<T>::value;
|
| 11745 |
+
template <class T> inline constexpr bool is_copy_constructible_v
|
| 11746 |
+
= is_copy_constructible<T>::value;
|
| 11747 |
+
template <class T> inline constexpr bool is_move_constructible_v
|
| 11748 |
+
= is_move_constructible<T>::value;
|
| 11749 |
+
template <class T, class U> inline constexpr bool is_assignable_v
|
| 11750 |
+
= is_assignable<T, U>::value;
|
| 11751 |
+
template <class T> inline constexpr bool is_copy_assignable_v
|
| 11752 |
+
= is_copy_assignable<T>::value;
|
| 11753 |
+
template <class T> inline constexpr bool is_move_assignable_v
|
| 11754 |
+
= is_move_assignable<T>::value;
|
| 11755 |
+
template <class T, class U> inline constexpr bool is_swappable_with_v
|
| 11756 |
+
= is_swappable_with<T, U>::value;
|
| 11757 |
+
template <class T> inline constexpr bool is_swappable_v
|
| 11758 |
+
= is_swappable<T>::value;
|
| 11759 |
+
template <class T> inline constexpr bool is_destructible_v
|
| 11760 |
+
= is_destructible<T>::value;
|
| 11761 |
+
template <class T, class... Args> inline constexpr bool is_trivially_constructible_v
|
| 11762 |
+
= is_trivially_constructible<T, Args...>::value;
|
| 11763 |
+
template <class T> inline constexpr bool is_trivially_default_constructible_v
|
| 11764 |
+
= is_trivially_default_constructible<T>::value;
|
| 11765 |
+
template <class T> inline constexpr bool is_trivially_copy_constructible_v
|
| 11766 |
+
= is_trivially_copy_constructible<T>::value;
|
| 11767 |
+
template <class T> inline constexpr bool is_trivially_move_constructible_v
|
| 11768 |
+
= is_trivially_move_constructible<T>::value;
|
| 11769 |
+
template <class T, class U> inline constexpr bool is_trivially_assignable_v
|
| 11770 |
+
= is_trivially_assignable<T, U>::value;
|
| 11771 |
+
template <class T> inline constexpr bool is_trivially_copy_assignable_v
|
| 11772 |
+
= is_trivially_copy_assignable<T>::value;
|
| 11773 |
+
template <class T> inline constexpr bool is_trivially_move_assignable_v
|
| 11774 |
+
= is_trivially_move_assignable<T>::value;
|
| 11775 |
+
template <class T> inline constexpr bool is_trivially_destructible_v
|
| 11776 |
+
= is_trivially_destructible<T>::value;
|
| 11777 |
+
template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v
|
| 11778 |
+
= is_nothrow_constructible<T, Args...>::value;
|
| 11779 |
+
template <class T> inline constexpr bool is_nothrow_default_constructible_v
|
| 11780 |
+
= is_nothrow_default_constructible<T>::value;
|
| 11781 |
+
template <class T> inline constexpr bool is_nothrow_copy_constructible_v
|
| 11782 |
+
= is_nothrow_copy_constructible<T>::value;
|
| 11783 |
+
template <class T> inline constexpr bool is_nothrow_move_constructible_v
|
| 11784 |
+
= is_nothrow_move_constructible<T>::value;
|
| 11785 |
+
template <class T, class U> inline constexpr bool is_nothrow_assignable_v
|
| 11786 |
+
= is_nothrow_assignable<T, U>::value;
|
| 11787 |
+
template <class T> inline constexpr bool is_nothrow_copy_assignable_v
|
| 11788 |
+
= is_nothrow_copy_assignable<T>::value;
|
| 11789 |
+
template <class T> inline constexpr bool is_nothrow_move_assignable_v
|
| 11790 |
+
= is_nothrow_move_assignable<T>::value;
|
| 11791 |
+
template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v
|
| 11792 |
+
= is_nothrow_swappable_with<T, U>::value;
|
| 11793 |
+
template <class T> inline constexpr bool is_nothrow_swappable_v
|
| 11794 |
+
= is_nothrow_swappable<T>::value;
|
| 11795 |
+
template <class T> inline constexpr bool is_nothrow_destructible_v
|
| 11796 |
+
= is_nothrow_destructible<T>::value;
|
| 11797 |
+
template <class T> inline constexpr bool has_virtual_destructor_v
|
| 11798 |
+
= has_virtual_destructor<T>::value;
|
| 11799 |
+
template <class T> inline constexpr bool has_unique_object_representations_v
|
| 11800 |
+
= has_unique_object_representations<T>::value;
|
| 11801 |
+
|
| 11802 |
+
// [meta.unary.prop.query], type property queries
|
| 11803 |
+
template <class T> inline constexpr size_t alignment_of_v
|
| 11804 |
+
= alignment_of<T>::value;
|
| 11805 |
+
template <class T> inline constexpr size_t rank_v
|
| 11806 |
+
= rank<T>::value;
|
| 11807 |
+
template <class T, unsigned I = 0> inline constexpr size_t extent_v
|
| 11808 |
+
= extent<T, I>::value;
|
| 11809 |
+
|
| 11810 |
+
// [meta.rel], type relations
|
| 11811 |
+
template <class T, class U> inline constexpr bool is_same_v
|
| 11812 |
+
= is_same<T, U>::value;
|
| 11813 |
+
template <class Base, class Derived> inline constexpr bool is_base_of_v
|
| 11814 |
+
= is_base_of<Base, Derived>::value;
|
| 11815 |
+
template <class From, class To> inline constexpr bool is_convertible_v
|
| 11816 |
+
= is_convertible<From, To>::value;
|
| 11817 |
+
template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v
|
| 11818 |
+
= is_invocable<Fn, ArgTypes...>::value;
|
| 11819 |
+
template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v
|
| 11820 |
+
= is_invocable_r<R, Fn, ArgTypes...>::value;
|
| 11821 |
+
template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v
|
| 11822 |
+
= is_nothrow_invocable<Fn, ArgTypes...>::value;
|
| 11823 |
+
template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v
|
| 11824 |
+
= is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;
|
| 11825 |
+
|
| 11826 |
+
// [meta.logical], logical operator traits
|
| 11827 |
+
template<class... B> inline constexpr bool conjunction_v = conjunction<B...>::value;
|
| 11828 |
+
template<class... B> inline constexpr bool disjunction_v = disjunction<B...>::value;
|
| 11829 |
+
template<class B> inline constexpr bool negation_v = negation<B>::value;
|
| 11830 |
+
}
|
| 11831 |
```
|
| 11832 |
|
| 11833 |
+
The behavior of a program that adds specializations for any of the
|
| 11834 |
templates defined in this subclause is undefined unless otherwise
|
| 11835 |
specified.
|
| 11836 |
|
| 11837 |
+
Unless otherwise specified, an incomplete type may be used to
|
| 11838 |
+
instantiate a template in this subclause.
|
| 11839 |
+
|
| 11840 |
### Helper classes <a id="meta.help">[[meta.help]]</a>
|
| 11841 |
|
| 11842 |
``` cpp
|
| 11843 |
namespace std {
|
| 11844 |
template <class T, T v>
|
| 11845 |
struct integral_constant {
|
| 11846 |
static constexpr T value = v;
|
| 11847 |
+
using value_type = T;
|
| 11848 |
+
using type = integral_constant<T, v>;
|
| 11849 |
constexpr operator value_type() const noexcept { return value; }
|
| 11850 |
constexpr value_type operator()() const noexcept { return value; }
|
| 11851 |
};
|
|
|
|
|
|
|
| 11852 |
}
|
| 11853 |
```
|
| 11854 |
|
| 11855 |
+
The class template `integral_constant`, alias template `bool_constant`,
|
| 11856 |
+
and its associated *typedef-name*s `true_type` and `false_type` are used
|
| 11857 |
+
as base classes to define the interface for various type traits.
|
| 11858 |
|
| 11859 |
### Unary type traits <a id="meta.unary">[[meta.unary]]</a>
|
| 11860 |
|
| 11861 |
+
This subclause contains templates that may be used to query the
|
| 11862 |
properties of a type at compile time.
|
| 11863 |
|
| 11864 |
+
Each of these templates shall be a `UnaryTypeTrait` ([[meta.rqmts]])
|
| 11865 |
+
with a base characteristic of `true_type` if the corresponding condition
|
| 11866 |
+
is `true`, otherwise `false_type`.
|
| 11867 |
|
| 11868 |
#### Primary type categories <a id="meta.unary.cat">[[meta.unary.cat]]</a>
|
| 11869 |
|
| 11870 |
The primary type categories correspond to the descriptions given in
|
| 11871 |
section [[basic.types]] of the C++standard.
|
| 11872 |
|
| 11873 |
For any given type `T`, the result of applying one of these templates to
|
| 11874 |
+
`T` and to cv `T` shall yield the same result.
|
| 11875 |
|
| 11876 |
+
[*Note 1*: For any given type `T`, exactly one of the primary type
|
| 11877 |
+
categories has a `value` member that evaluates to `true`. — *end note*]
|
| 11878 |
|
| 11879 |
#### Composite type traits <a id="meta.unary.comp">[[meta.unary.comp]]</a>
|
| 11880 |
|
| 11881 |
These templates provide convenient compositions of the primary type
|
| 11882 |
categories, corresponding to the descriptions given in section
|
| 11883 |
[[basic.types]].
|
| 11884 |
|
| 11885 |
For any given type `T`, the result of applying one of these templates to
|
| 11886 |
+
`T` and to cv `T` shall yield the same result.
|
| 11887 |
|
| 11888 |
#### Type properties <a id="meta.unary.prop">[[meta.unary.prop]]</a>
|
| 11889 |
|
| 11890 |
These templates provide access to some of the more important properties
|
| 11891 |
of types.
|
| 11892 |
|
| 11893 |
It is unspecified whether the library defines any full or partial
|
| 11894 |
specializations of any of these templates.
|
| 11895 |
|
| 11896 |
+
For all of the class templates `X` declared in this subclause,
|
| 11897 |
instantiating that template with a template-argument that is a class
|
| 11898 |
template specialization may result in the implicit instantiation of the
|
| 11899 |
template argument if and only if the semantics of `X` require that the
|
| 11900 |
argument must be a complete type.
|
| 11901 |
|
| 11902 |
+
For the purpose of defining the templates in this subclause, a function
|
| 11903 |
+
call expression `declval<T>()` for any type `T` is considered to be a
|
| 11904 |
+
trivial ([[basic.types]], [[special]]) function call that is not an
|
| 11905 |
+
odr-use ([[basic.def.odr]]) of `declval` in the context of the
|
| 11906 |
+
corresponding definition notwithstanding the restrictions of
|
| 11907 |
+
[[declval]].
|
| 11908 |
+
|
| 11909 |
+
[*Note 1*: A union is a class type that can be marked with
|
| 11910 |
+
`final`. — *end note*]
|
| 11911 |
+
|
| 11912 |
+
[*Example 1*:
|
| 11913 |
+
|
| 11914 |
``` cpp
|
| 11915 |
+
is_const_v<const volatile int> // true
|
| 11916 |
+
is_const_v<const int*> // false
|
| 11917 |
+
is_const_v<const int&> // false
|
| 11918 |
+
is_const_v<int[3]> // false
|
| 11919 |
+
is_const_v<const int[3]> // true
|
| 11920 |
```
|
| 11921 |
|
| 11922 |
+
— *end example*]
|
| 11923 |
+
|
| 11924 |
+
[*Example 2*:
|
| 11925 |
+
|
| 11926 |
``` cpp
|
| 11927 |
remove_const_t<const volatile int> // volatile int
|
| 11928 |
remove_const_t<const int* const> // const int*
|
| 11929 |
remove_const_t<const int&> // const int&
|
| 11930 |
remove_const_t<const int[3]> // int[3]
|
| 11931 |
```
|
| 11932 |
|
| 11933 |
+
— *end example*]
|
| 11934 |
+
|
| 11935 |
+
[*Example 3*:
|
| 11936 |
+
|
| 11937 |
``` cpp
|
| 11938 |
// Given:
|
| 11939 |
struct P final { };
|
| 11940 |
union U1 { };
|
| 11941 |
union U2 final { };
|
| 11942 |
|
| 11943 |
// the following assertions hold:
|
| 11944 |
+
static_assert(!is_final_v<int>);
|
| 11945 |
+
static_assert(is_final_v<P>);
|
| 11946 |
+
static_assert(!is_final_v<U1>);
|
| 11947 |
+
static_assert(is_final_v<U2>);
|
| 11948 |
```
|
| 11949 |
|
| 11950 |
+
— *end example*]
|
| 11951 |
|
| 11952 |
+
The predicate condition for a template specialization
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11953 |
`is_constructible<T, Args...>` shall be satisfied if and only if the
|
| 11954 |
following variable definition would be well-formed for some invented
|
| 11955 |
variable `t`:
|
| 11956 |
|
| 11957 |
``` cpp
|
| 11958 |
+
T t(declval<Args>()...);
|
| 11959 |
```
|
| 11960 |
|
| 11961 |
+
[*Note 2*: These tokens are never interpreted as a function
|
| 11962 |
+
declaration. — *end note*]
|
| 11963 |
+
|
| 11964 |
+
Access checking is performed as if in a context unrelated to `T` and any
|
| 11965 |
+
of the `Args`. Only the validity of the immediate context of the
|
| 11966 |
+
variable initialization is considered.
|
| 11967 |
+
|
| 11968 |
+
[*Note 3*: The evaluation of the initialization can result in side
|
| 11969 |
+
effects such as the instantiation of class template specializations and
|
| 11970 |
+
function template specializations, the generation of implicitly-defined
|
| 11971 |
+
functions, and so on. Such side effects are not in the “immediate
|
| 11972 |
+
context” and can result in the program being ill-formed. — *end note*]
|
| 11973 |
+
|
| 11974 |
+
The predicate condition for a template specialization
|
| 11975 |
+
`has_unique_object_representations<T>` shall be satisfied if and only
|
| 11976 |
+
if:
|
| 11977 |
+
|
| 11978 |
+
- `T` is trivially copyable, and
|
| 11979 |
+
- any two objects of type `T` with the same value have the same object
|
| 11980 |
+
representation, where two objects of array or non-union class type are
|
| 11981 |
+
considered to have the same value if their respective sequences of
|
| 11982 |
+
direct subobjects have the same values, and two objects of union type
|
| 11983 |
+
are considered to have the same value if they have the same active
|
| 11984 |
+
member and the corresponding members have the same value.
|
| 11985 |
+
|
| 11986 |
+
The set of scalar types for which this condition holds is
|
| 11987 |
+
*implementation-defined*.
|
| 11988 |
+
|
| 11989 |
+
[*Note 4*: If a type has padding bits, the condition does not hold;
|
| 11990 |
+
otherwise, the condition holds true for unsigned integral
|
| 11991 |
+
types. — *end note*]
|
| 11992 |
|
| 11993 |
### Type property queries <a id="meta.unary.prop.query">[[meta.unary.prop.query]]</a>
|
| 11994 |
|
| 11995 |
+
This subclause contains templates that may be used to query properties
|
| 11996 |
of types at compile time.
|
| 11997 |
|
| 11998 |
Each of these templates shall be a `UnaryTypeTrait` ([[meta.rqmts]])
|
| 11999 |
+
with a base characteristic of `integral_constant<size_t, Value>`.
|
| 12000 |
+
|
| 12001 |
+
[*Example 1*:
|
| 12002 |
|
| 12003 |
``` cpp
|
| 12004 |
// the following assertions hold:
|
| 12005 |
+
assert(rank_v<int> == 0);
|
| 12006 |
+
assert(rank_v<int[2]> == 1);
|
| 12007 |
+
assert(rank_v<int[][4]> == 2);
|
| 12008 |
```
|
| 12009 |
|
| 12010 |
+
— *end example*]
|
| 12011 |
+
|
| 12012 |
+
[*Example 2*:
|
| 12013 |
+
|
| 12014 |
``` cpp
|
| 12015 |
// the following assertions hold:
|
| 12016 |
+
assert(extent_v<int> == 0);
|
| 12017 |
+
assert(extent_v<int[2]> == 2);
|
| 12018 |
+
assert(extent_v<int[2][4]> == 2);
|
| 12019 |
+
assert(extent_v<int[][4]> == 0);
|
| 12020 |
+
assert((extent_v<int, 1>) == 0);
|
| 12021 |
+
assert((extent_v<int[2], 1>) == 0);
|
| 12022 |
+
assert((extent_v<int[2][4], 1>) == 4);
|
| 12023 |
+
assert((extent_v<int[][4], 1>) == 4);
|
| 12024 |
```
|
| 12025 |
|
| 12026 |
+
— *end example*]
|
| 12027 |
+
|
| 12028 |
### Relationships between types <a id="meta.rel">[[meta.rel]]</a>
|
| 12029 |
|
| 12030 |
+
This subclause contains templates that may be used to query
|
| 12031 |
relationships between types at compile time.
|
| 12032 |
|
| 12033 |
+
Each of these templates shall be a `BinaryTypeTrait` ([[meta.rqmts]])
|
| 12034 |
+
with a base characteristic of `true_type` if the corresponding condition
|
| 12035 |
is true, otherwise `false_type`.
|
| 12036 |
|
| 12037 |
+
[*Note 1*: Base classes that are private, protected, or ambiguous are,
|
| 12038 |
+
nonetheless, base classes. — *end note*]
|
| 12039 |
+
|
| 12040 |
+
For the purpose of defining the templates in this subclause, a function
|
| 12041 |
+
call expression `declval<T>()` for any type `T` is considered to be a
|
| 12042 |
+
trivial ([[basic.types]], [[special]]) function call that is not an
|
| 12043 |
+
odr-use ([[basic.def.odr]]) of `declval` in the context of the
|
| 12044 |
+
corresponding definition notwithstanding the restrictions of
|
| 12045 |
+
[[declval]].
|
| 12046 |
+
|
| 12047 |
+
[*Example 1*:
|
| 12048 |
+
|
| 12049 |
``` cpp
|
| 12050 |
struct B {};
|
| 12051 |
struct B1 : B {};
|
| 12052 |
struct B2 : B {};
|
| 12053 |
struct D : private B1, private B2 {};
|
| 12054 |
|
| 12055 |
+
is_base_of_v<B, D> // true
|
| 12056 |
+
is_base_of_v<const B, D> // true
|
| 12057 |
+
is_base_of_v<B, const D> // true
|
| 12058 |
+
is_base_of_v<B, const B> // true
|
| 12059 |
+
is_base_of_v<D, B> // false
|
| 12060 |
+
is_base_of_v<B&, D&> // false
|
| 12061 |
+
is_base_of_v<B[3], D[3]> // false
|
| 12062 |
+
is_base_of_v<int, int> // false
|
| 12063 |
```
|
| 12064 |
|
| 12065 |
+
— *end example*]
|
| 12066 |
|
| 12067 |
+
The predicate condition for a template specialization
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12068 |
`is_convertible<From, To>` shall be satisfied if and only if the return
|
| 12069 |
expression in the following code would be well-formed, including any
|
| 12070 |
implicit conversions to the return type of the function:
|
| 12071 |
|
| 12072 |
``` cpp
|
| 12073 |
To test() {
|
| 12074 |
+
return declval<From>();
|
| 12075 |
}
|
| 12076 |
```
|
| 12077 |
|
| 12078 |
+
[*Note 2*: This requirement gives well defined results for reference
|
| 12079 |
+
types, void types, array types, and function types. — *end note*]
|
| 12080 |
+
|
| 12081 |
+
Access checking is performed in a context unrelated to `To` and `From`.
|
| 12082 |
+
Only the validity of the immediate context of the *expression* of the
|
| 12083 |
+
`return` statement (including initialization of the returned object or
|
| 12084 |
+
reference) is considered.
|
| 12085 |
+
|
| 12086 |
+
[*Note 3*: The initialization can result in side effects such as the
|
| 12087 |
+
instantiation of class template specializations and function template
|
| 12088 |
+
specializations, the generation of implicitly-defined functions, and so
|
| 12089 |
+
on. Such side effects are not in the “immediate context” and can result
|
| 12090 |
+
in the program being ill-formed. — *end note*]
|
| 12091 |
|
| 12092 |
### Transformations between types <a id="meta.trans">[[meta.trans]]</a>
|
| 12093 |
|
| 12094 |
+
This subclause contains templates that may be used to transform one type
|
| 12095 |
+
to another following some predefined rule.
|
| 12096 |
|
| 12097 |
Each of the templates in this subclause shall be a
|
| 12098 |
+
`TransformationTrait` ([[meta.rqmts]]).
|
| 12099 |
|
| 12100 |
#### Const-volatile modifications <a id="meta.trans.cv">[[meta.trans.cv]]</a>
|
| 12101 |
|
| 12102 |
+
[*Example 1*: `remove_const_t<const volatile int>` evaluates to
|
| 12103 |
+
`volatile int`, whereas `remove_const_t<const int*>` evaluates to
|
| 12104 |
+
`const int*`. — *end example*]
|
| 12105 |
+
|
| 12106 |
#### Reference modifications <a id="meta.trans.ref">[[meta.trans.ref]]</a>
|
| 12107 |
|
| 12108 |
+
[*Note 1*: This rule reflects the semantics of reference collapsing (
|
| 12109 |
+
[[dcl.ref]]). — *end note*]
|
| 12110 |
+
|
| 12111 |
#### Sign modifications <a id="meta.trans.sign">[[meta.trans.sign]]</a>
|
| 12112 |
|
| 12113 |
#### Array modifications <a id="meta.trans.arr">[[meta.trans.arr]]</a>
|
| 12114 |
|
| 12115 |
+
[*Note 1*: For multidimensional arrays, only the first array dimension
|
| 12116 |
+
is removed. For a type “array of `const U`”, the resulting type is
|
| 12117 |
+
`const U`. — *end note*]
|
| 12118 |
+
|
| 12119 |
+
[*Example 1*:
|
| 12120 |
+
|
| 12121 |
``` cpp
|
| 12122 |
// the following assertions hold:
|
| 12123 |
+
assert((is_same_v<remove_extent_t<int>, int>));
|
| 12124 |
+
assert((is_same_v<remove_extent_t<int[2]>, int>));
|
| 12125 |
+
assert((is_same_v<remove_extent_t<int[2][3]>, int[3]>));
|
| 12126 |
+
assert((is_same_v<remove_extent_t<int[][3]>, int[3]>));
|
| 12127 |
```
|
| 12128 |
|
| 12129 |
+
— *end example*]
|
| 12130 |
+
|
| 12131 |
+
[*Example 2*:
|
| 12132 |
+
|
| 12133 |
``` cpp
|
| 12134 |
// the following assertions hold:
|
| 12135 |
+
assert((is_same_v<remove_all_extents_t<int>, int>));
|
| 12136 |
+
assert((is_same_v<remove_all_extents_t<int[2]>, int>));
|
| 12137 |
+
assert((is_same_v<remove_all_extents_t<int[2][3]>, int>));
|
| 12138 |
+
assert((is_same_v<remove_all_extents_t<int[][3]>, int>));
|
| 12139 |
```
|
| 12140 |
|
| 12141 |
+
— *end example*]
|
| 12142 |
+
|
| 12143 |
#### Pointer modifications <a id="meta.trans.ptr">[[meta.trans.ptr]]</a>
|
| 12144 |
|
| 12145 |
#### Other transformations <a id="meta.trans.other">[[meta.trans.other]]</a>
|
| 12146 |
|
| 12147 |
+
[*Note 1*: This behavior is similar to the lvalue-to-rvalue (
|
| 12148 |
+
[[conv.lval]]), array-to-pointer ([[conv.array]]), and
|
| 12149 |
+
function-to-pointer ([[conv.func]]) conversions applied when an lvalue
|
| 12150 |
+
expression is used as an rvalue, but also strips cv-qualifiers from
|
| 12151 |
+
class types in order to more closely model by-value argument
|
| 12152 |
+
passing. — *end note*]
|
| 12153 |
+
|
| 12154 |
+
[*Note 2*:
|
| 12155 |
+
|
| 12156 |
A typical implementation would define `aligned_storage` as:
|
| 12157 |
|
| 12158 |
``` cpp
|
| 12159 |
+
template <size_t Len, size_t Alignment>
|
| 12160 |
struct aligned_storage {
|
| 12161 |
typedef struct {
|
| 12162 |
alignas(Alignment) unsigned char __data[Len];
|
| 12163 |
} type;
|
| 12164 |
};
|
| 12165 |
```
|
| 12166 |
|
| 12167 |
+
— *end note*]
|
| 12168 |
+
|
| 12169 |
It is *implementation-defined* whether any extended alignment is
|
| 12170 |
supported ([[basic.align]]).
|
| 12171 |
|
| 12172 |
+
Note A: For the `common_type` trait applied to a parameter pack `T` of
|
| 12173 |
+
types, the member `type` shall be either defined or not present as
|
| 12174 |
+
follows:
|
| 12175 |
|
| 12176 |
+
- If `sizeof...(T)` is zero, there shall be no member `type`.
|
| 12177 |
+
- If `sizeof...(T)` is one, let `T0` denote the sole type constituting
|
| 12178 |
+
the pack `T`. The member *typedef-name* `type` shall denote the same
|
| 12179 |
+
type, if any, as `common_type_t<T0, T0>`; otherwise there shall be no
|
| 12180 |
+
member `type`.
|
| 12181 |
+
- If `sizeof...(T)` is two, let the first and second types constituting
|
| 12182 |
+
`T` be denoted by `T1` and `T2`, respectively, and let `D1` and `D2`
|
| 12183 |
+
denote the same types as `decay_t<T1>` and `decay_t<T2>`,
|
| 12184 |
+
respectively.
|
| 12185 |
+
- If `is_same_v<T1, D1>` is `false` or `is_same_v<T2, D2>` is `false`,
|
| 12186 |
+
let `C` denote the same type, if any, as `common_type_t<D1, D2>`.
|
| 12187 |
+
- Otherwise, let `C` denote the same type, if any, as
|
| 12188 |
``` cpp
|
| 12189 |
+
decay_t<decltype(false ? declval<D1>() : declval<D2>())>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12190 |
```
|
| 12191 |
|
| 12192 |
+
\[*Note 3*: This will not apply if there is a specialization
|
| 12193 |
+
`common_type<D1, D2>`. — *end note*]
|
| 12194 |
+
|
| 12195 |
+
In either case, the member *typedef-name* `type` shall denote the same
|
| 12196 |
+
type, if any, as `C`. Otherwise, there shall be no member `type`.
|
| 12197 |
+
- If `sizeof...(T)` is greater than two, let `T1`, `T2`, and `R`,
|
| 12198 |
+
respectively, denote the first, second, and (pack of) remaining types
|
| 12199 |
+
constituting `T`. Let `C` denote the same type, if any, as
|
| 12200 |
+
`common_type_t<T1, T2>`. If there is such a type `C`, the member
|
| 12201 |
+
*typedef-name* `type` shall denote the same type, if any, as
|
| 12202 |
+
`common_type_t<C, R...>`. Otherwise, there shall be no member `type`.
|
| 12203 |
+
|
| 12204 |
+
Note B: Notwithstanding the provisions of [[meta.type.synop]], and
|
| 12205 |
+
pursuant to [[namespace.std]], a program may specialize
|
| 12206 |
+
`common_type<T1, T2>` for types `T1` and `T2` such that
|
| 12207 |
+
`is_same_v<T1, decay_t<T1>>` and `is_same_v<T2, decay_t<T2>>` are each
|
| 12208 |
+
`true`.
|
| 12209 |
+
|
| 12210 |
+
[*Note 4*: Such specializations are needed when only explicit
|
| 12211 |
+
conversions are desired between the template arguments. — *end note*]
|
| 12212 |
+
|
| 12213 |
+
Such a specialization need not have a member named `type`, but if it
|
| 12214 |
+
does, that member shall be a *typedef-name* for an accessible and
|
| 12215 |
+
unambiguous cv-unqualified non-reference type `C` to which each of the
|
| 12216 |
+
types `T1` and `T2` is explicitly convertible. Moreover,
|
| 12217 |
+
`common_type_t<T1, T2>` shall denote the same type, if any, as does
|
| 12218 |
+
`common_type_t<T2, T1>`. No diagnostic is required for a violation of
|
| 12219 |
+
this Note’s rules.
|
| 12220 |
+
|
| 12221 |
+
[*Example 1*:
|
| 12222 |
+
|
| 12223 |
Given these definitions:
|
| 12224 |
|
| 12225 |
``` cpp
|
| 12226 |
+
using PF1 = bool (&)();
|
| 12227 |
+
using PF2 = short (*)(long);
|
| 12228 |
|
| 12229 |
struct S {
|
| 12230 |
operator PF2() const;
|
| 12231 |
double operator()(char, int&);
|
| 12232 |
void fn(long) const;
|
| 12233 |
char data;
|
| 12234 |
};
|
| 12235 |
|
| 12236 |
+
using PMF = void (S::*)(long) const;
|
| 12237 |
+
using PMD = char S::*;
|
| 12238 |
```
|
| 12239 |
|
| 12240 |
the following assertions will hold:
|
| 12241 |
|
| 12242 |
``` cpp
|
| 12243 |
+
static_assert(is_same_v<invoke_result_t<S, int>, short>);
|
| 12244 |
+
static_assert(is_same_v<invoke_result_t<S&, unsigned char, int&>, double>);
|
| 12245 |
+
static_assert(is_same_v<invoke_result_t<PF1>, bool>);
|
| 12246 |
+
static_assert(is_same_v<invoke_result_t<PMF, unique_ptr<S>, int>, void>);
|
| 12247 |
+
static_assert(is_same_v<invoke_result_t<PMD, S>, char&&>);
|
| 12248 |
+
static_assert(is_same_v<invoke_result_t<PMD, const S*>, const char&>);
|
| 12249 |
```
|
| 12250 |
|
| 12251 |
+
— *end example*]
|
| 12252 |
+
|
| 12253 |
+
### Logical operator traits <a id="meta.logical">[[meta.logical]]</a>
|
| 12254 |
+
|
| 12255 |
+
This subclause describes type traits for applying logical operators to
|
| 12256 |
+
other type traits.
|
| 12257 |
+
|
| 12258 |
+
``` cpp
|
| 12259 |
+
template<class... B> struct conjunction : see below { };
|
| 12260 |
+
```
|
| 12261 |
+
|
| 12262 |
+
The class template `conjunction` forms the logical conjunction of its
|
| 12263 |
+
template type arguments.
|
| 12264 |
+
|
| 12265 |
+
For a specialization `conjunction<B1, ..., BN>`, if there is a template
|
| 12266 |
+
type argument `Bi` for which `bool(Bi::value)` is `false`, then
|
| 12267 |
+
instantiating `conjunction<B1, ..., BN>::value` does not require the
|
| 12268 |
+
instantiation of `Bj::value` for `j > i`.
|
| 12269 |
+
|
| 12270 |
+
[*Note 1*: This is analogous to the short-circuiting behavior of the
|
| 12271 |
+
built-in operator `&&`. — *end note*]
|
| 12272 |
+
|
| 12273 |
+
Every template type argument for which `Bi::value` is instantiated shall
|
| 12274 |
+
be usable as a base class and shall have a member `value` which is
|
| 12275 |
+
convertible to `bool`, is not hidden, and is unambiguously available in
|
| 12276 |
+
the type.
|
| 12277 |
+
|
| 12278 |
+
The specialization `conjunction<B1, ..., BN>` has a public and
|
| 12279 |
+
unambiguous base that is either
|
| 12280 |
+
|
| 12281 |
+
- the first type `Bi` in the list `true_type, B1, ..., BN` for which
|
| 12282 |
+
`bool(Bi::value)` is `false`, or
|
| 12283 |
+
- if there is no such `Bi`, the last type in the list.
|
| 12284 |
+
|
| 12285 |
+
[*Note 2*: This means a specialization of `conjunction` does not
|
| 12286 |
+
necessarily inherit from either `true_type` or
|
| 12287 |
+
`false_type`. — *end note*]
|
| 12288 |
+
|
| 12289 |
+
The member names of the base class, other than `conjunction` and
|
| 12290 |
+
`operator=`, shall not be hidden and shall be unambiguously available in
|
| 12291 |
+
`conjunction`.
|
| 12292 |
+
|
| 12293 |
+
``` cpp
|
| 12294 |
+
template<class... B> struct disjunction : see below { };
|
| 12295 |
+
```
|
| 12296 |
+
|
| 12297 |
+
The class template `disjunction` forms the logical disjunction of its
|
| 12298 |
+
template type arguments.
|
| 12299 |
+
|
| 12300 |
+
For a specialization `disjunction<B1, ..., BN>`, if there is a template
|
| 12301 |
+
type argument `Bi` for which `bool(Bi::value)` is `true`, then
|
| 12302 |
+
instantiating `disjunction<B1, ..., BN>::value` does not require the
|
| 12303 |
+
instantiation of `Bj::value` for `j > i`.
|
| 12304 |
+
|
| 12305 |
+
[*Note 3*: This is analogous to the short-circuiting behavior of the
|
| 12306 |
+
built-in operator `||`. — *end note*]
|
| 12307 |
+
|
| 12308 |
+
Every template type argument for which `Bi::value` is instantiated shall
|
| 12309 |
+
be usable as a base class and shall have a member `value` which is
|
| 12310 |
+
convertible to `bool`, is not hidden, and is unambiguously available in
|
| 12311 |
+
the type.
|
| 12312 |
+
|
| 12313 |
+
The specialization `disjunction<B1, ..., BN>` has a public and
|
| 12314 |
+
unambiguous base that is either
|
| 12315 |
+
|
| 12316 |
+
- the first type `Bi` in the list `false_type, B1, ..., BN` for which
|
| 12317 |
+
`bool(Bi::value)` is `true`, or
|
| 12318 |
+
- if there is no such `Bi`, the last type in the list.
|
| 12319 |
+
|
| 12320 |
+
[*Note 4*: This means a specialization of `disjunction` does not
|
| 12321 |
+
necessarily inherit from either `true_type` or
|
| 12322 |
+
`false_type`. — *end note*]
|
| 12323 |
+
|
| 12324 |
+
The member names of the base class, other than `disjunction` and
|
| 12325 |
+
`operator=`, shall not be hidden and shall be unambiguously available in
|
| 12326 |
+
`disjunction`.
|
| 12327 |
+
|
| 12328 |
+
``` cpp
|
| 12329 |
+
template<class B> struct negation : see below { };
|
| 12330 |
+
```
|
| 12331 |
+
|
| 12332 |
+
The class template `negation` forms the logical negation of its template
|
| 12333 |
+
type argument. The type `negation<B>` is a `UnaryTypeTrait` with a base
|
| 12334 |
+
characteristic of `bool_constant<!bool(B::value)>`.
|
| 12335 |
+
|
| 12336 |
## Compile-time rational arithmetic <a id="ratio">[[ratio]]</a>
|
| 12337 |
|
| 12338 |
### In general <a id="ratio.general">[[ratio.general]]</a>
|
| 12339 |
|
| 12340 |
This subclause describes the ratio library. It provides a class template
|
|
|
|
| 12366 |
template <class R1, class R2> struct ratio_less;
|
| 12367 |
template <class R1, class R2> struct ratio_less_equal;
|
| 12368 |
template <class R1, class R2> struct ratio_greater;
|
| 12369 |
template <class R1, class R2> struct ratio_greater_equal;
|
| 12370 |
|
| 12371 |
+
template <class R1, class R2>
|
| 12372 |
+
inline constexpr bool ratio_equal_v = ratio_equal<R1, R2>::value;
|
| 12373 |
+
template <class R1, class R2>
|
| 12374 |
+
inline constexpr bool ratio_not_equal_v = ratio_not_equal<R1, R2>::value;
|
| 12375 |
+
template <class R1, class R2>
|
| 12376 |
+
inline constexpr bool ratio_less_v = ratio_less<R1, R2>::value;
|
| 12377 |
+
template <class R1, class R2>
|
| 12378 |
+
inline constexpr bool ratio_less_equal_v = ratio_less_equal<R1, R2>::value;
|
| 12379 |
+
template <class R1, class R2>
|
| 12380 |
+
inline constexpr bool ratio_greater_v = ratio_greater<R1, R2>::value;
|
| 12381 |
+
template <class R1, class R2>
|
| 12382 |
+
inline constexpr bool ratio_greater_equal_v = ratio_greater_equal<R1, R2>::value;
|
| 12383 |
+
|
| 12384 |
// [ratio.si], convenience SI typedefs
|
| 12385 |
+
using yocto = ratio<1, 1'000'000'000'000'000'000'000'000>; // see below
|
| 12386 |
+
using zepto = ratio<1, 1'000'000'000'000'000'000'000>; // see below
|
| 12387 |
+
using atto = ratio<1, 1'000'000'000'000'000'000>;
|
| 12388 |
+
using femto = ratio<1, 1'000'000'000'000'000>;
|
| 12389 |
+
using pico = ratio<1, 1'000'000'000'000>;
|
| 12390 |
+
using nano = ratio<1, 1'000'000'000>;
|
| 12391 |
+
using micro = ratio<1, 1'000'000>;
|
| 12392 |
+
using milli = ratio<1, 1'000>;
|
| 12393 |
+
using centi = ratio<1, 100>;
|
| 12394 |
+
using deci = ratio<1, 10>;
|
| 12395 |
+
using deca = ratio< 10, 1>;
|
| 12396 |
+
using hecto = ratio< 100, 1>;
|
| 12397 |
+
using kilo = ratio< 1'000, 1>;
|
| 12398 |
+
using mega = ratio< 1'000'000, 1>;
|
| 12399 |
+
using giga = ratio< 1'000'000'000, 1>;
|
| 12400 |
+
using tera = ratio< 1'000'000'000'000, 1>;
|
| 12401 |
+
using peta = ratio< 1'000'000'000'000'000, 1>;
|
| 12402 |
+
using exa = ratio< 1'000'000'000'000'000'000, 1>;
|
| 12403 |
+
using zetta = ratio< 1'000'000'000'000'000'000'000, 1>; // see below
|
| 12404 |
+
using yotta = ratio<1'000'000'000'000'000'000'000'000, 1>; // see below
|
| 12405 |
}
|
| 12406 |
```
|
| 12407 |
|
| 12408 |
### Class template `ratio` <a id="ratio.ratio">[[ratio.ratio]]</a>
|
| 12409 |
|
|
|
|
| 12412 |
template <intmax_t N, intmax_t D = 1>
|
| 12413 |
class ratio {
|
| 12414 |
public:
|
| 12415 |
static constexpr intmax_t num;
|
| 12416 |
static constexpr intmax_t den;
|
| 12417 |
+
using type = ratio<num, den>;
|
| 12418 |
};
|
| 12419 |
}
|
| 12420 |
```
|
| 12421 |
|
| 12422 |
If the template argument `D` is zero or the absolute values of either of
|
| 12423 |
the template arguments `N` and `D` is not representable by type
|
| 12424 |
+
`intmax_t`, the program is ill-formed.
|
| 12425 |
+
|
| 12426 |
+
[*Note 1*: These rules ensure that infinite ratios are avoided and that
|
| 12427 |
+
for any negative input, there exists a representable value of its
|
| 12428 |
+
absolute value which is positive. In a two’s complement representation,
|
| 12429 |
+
this excludes the most negative value. — *end note*]
|
| 12430 |
|
| 12431 |
The static data members `num` and `den` shall have the following values,
|
| 12432 |
where `gcd` represents the greatest common divisor of the absolute
|
| 12433 |
values of `N` and `D`:
|
| 12434 |
|
|
|
|
| 12461 |
| | `R2::num * R1::den` | |
|
| 12462 |
| `ratio_multiply<R1, R2>` | `R1::num * R2::num` | `R1::den * R2::den` |
|
| 12463 |
| `ratio_divide<R1, R2>` | `R1::num * R2::den` | `R1::den * R2::num` |
|
| 12464 |
|
| 12465 |
|
| 12466 |
+
[*Example 1*:
|
| 12467 |
+
|
| 12468 |
``` cpp
|
| 12469 |
static_assert(ratio_add<ratio<1, 3>, ratio<1, 6>>::num == 1, "1/3+1/6 == 1/2");
|
| 12470 |
static_assert(ratio_add<ratio<1, 3>, ratio<1, 6>>::den == 2, "1/3+1/6 == 1/2");
|
| 12471 |
static_assert(ratio_multiply<ratio<1, 3>, ratio<3, 2>>::num == 1, "1/3*3/2 == 1/2");
|
| 12472 |
static_assert(ratio_multiply<ratio<1, 3>, ratio<3, 2>>::den == 2, "1/3*3/2 == 1/2");
|
|
|
|
| 12480 |
"1/MAX * MAX/2 == 1/2");
|
| 12481 |
static_assert(ratio_multiply<ratio<1, INT_MAX>, ratio<INT_MAX, 2>>::den == 2,
|
| 12482 |
"1/MAX * MAX/2 == 1/2");
|
| 12483 |
```
|
| 12484 |
|
| 12485 |
+
— *end example*]
|
| 12486 |
+
|
| 12487 |
### Comparison of `ratio`s <a id="ratio.comparison">[[ratio.comparison]]</a>
|
| 12488 |
|
| 12489 |
``` cpp
|
| 12490 |
+
template <class R1, class R2>
|
| 12491 |
+
struct ratio_equal : bool_constant<R1::num == R2::num && R1::den == R2::den> { };
|
| 12492 |
```
|
| 12493 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12494 |
``` cpp
|
| 12495 |
+
template <class R1, class R2>
|
| 12496 |
+
struct ratio_not_equal : bool_constant<!ratio_equal_v<R1, R2>> { };
|
| 12497 |
```
|
| 12498 |
|
| 12499 |
``` cpp
|
| 12500 |
+
template <class R1, class R2>
|
| 12501 |
+
struct ratio_less : bool_constant<see below> { };
|
| 12502 |
```
|
| 12503 |
|
| 12504 |
+
If `R1::num` × `R2::den` is less than `R2::num` × `R1::den`,
|
| 12505 |
+
`ratio_less<R1, R2>` shall be derived from `bool_constant<true>`;
|
| 12506 |
+
otherwise it shall be derived from `bool_constant<false>`.
|
| 12507 |
+
Implementations may use other algorithms to compute this relationship to
|
| 12508 |
+
avoid overflow. If overflow occurs, the program is ill-formed.
|
| 12509 |
|
| 12510 |
``` cpp
|
| 12511 |
+
template <class R1, class R2>
|
| 12512 |
+
struct ratio_less_equal : bool_constant<!ratio_less_v<R2, R1>> { };
|
| 12513 |
```
|
| 12514 |
|
| 12515 |
``` cpp
|
| 12516 |
+
template <class R1, class R2>
|
| 12517 |
+
struct ratio_greater : bool_constant<ratio_less_v<R2, R1>> { };
|
| 12518 |
```
|
| 12519 |
|
| 12520 |
``` cpp
|
| 12521 |
+
template <class R1, class R2>
|
| 12522 |
+
struct ratio_greater_equal : bool_constant<!ratio_less_v<R1, R2>> { };
|
| 12523 |
```
|
| 12524 |
|
| 12525 |
### SI types for `ratio` <a id="ratio.si">[[ratio.si]]</a>
|
| 12526 |
|
| 12527 |
+
For each of the *typedef-name*s `yocto`, `zepto`, `zetta`, and `yotta`,
|
| 12528 |
+
if both of the constants used in its specification are representable by
|
| 12529 |
`intmax_t`, the typedef shall be defined; if either of the constants is
|
| 12530 |
not representable by `intmax_t`, the typedef shall not be defined.
|
| 12531 |
|
| 12532 |
## Time utilities <a id="time">[[time]]</a>
|
| 12533 |
|
| 12534 |
### In general <a id="time.general">[[time.general]]</a>
|
| 12535 |
|
| 12536 |
This subclause describes the chrono library ([[time.syn]]) and various
|
| 12537 |
+
C functions ([[ctime.syn]]) that provide generally useful time
|
| 12538 |
utilities.
|
| 12539 |
|
| 12540 |
### Header `<chrono>` synopsis <a id="time.syn">[[time.syn]]</a>
|
| 12541 |
|
| 12542 |
``` cpp
|
| 12543 |
namespace std {
|
| 12544 |
namespace chrono {
|
|
|
|
| 12545 |
// [time.duration], class template duration
|
| 12546 |
template <class Rep, class Period = ratio<1>> class duration;
|
| 12547 |
|
| 12548 |
// [time.point], class template time_point
|
| 12549 |
template <class Clock, class Duration = typename Clock::duration> class time_point;
|
| 12550 |
+
}
|
| 12551 |
|
| 12552 |
+
// [time.traits.specializations], common_type specializations
|
|
|
|
|
|
|
| 12553 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12554 |
+
struct common_type<chrono::duration<Rep1, Period1>,
|
| 12555 |
+
chrono::duration<Rep2, Period2>>;
|
| 12556 |
|
| 12557 |
template <class Clock, class Duration1, class Duration2>
|
| 12558 |
+
struct common_type<chrono::time_point<Clock, Duration1>,
|
| 12559 |
+
chrono::time_point<Clock, Duration2>>;
|
| 12560 |
|
| 12561 |
namespace chrono {
|
|
|
|
| 12562 |
// [time.traits], customization traits
|
| 12563 |
template <class Rep> struct treat_as_floating_point;
|
| 12564 |
template <class Rep> struct duration_values;
|
| 12565 |
+
template <class Rep> inline constexpr bool treat_as_floating_point_v
|
| 12566 |
+
= treat_as_floating_point<Rep>::value;
|
| 12567 |
|
| 12568 |
// [time.duration.nonmember], duration arithmetic
|
| 12569 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12570 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 12571 |
+
constexpr operator+(const duration<Rep1, Period1>& lhs,
|
| 12572 |
+
const duration<Rep2, Period2>& rhs);
|
| 12573 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12574 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 12575 |
+
constexpr operator-(const duration<Rep1, Period1>& lhs,
|
| 12576 |
+
const duration<Rep2, Period2>& rhs);
|
| 12577 |
template <class Rep1, class Period, class Rep2>
|
| 12578 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 12579 |
constexpr operator*(const duration<Rep1, Period>& d, const Rep2& s);
|
| 12580 |
template <class Rep1, class Rep2, class Period>
|
| 12581 |
duration<common_type_t<Rep1, Rep2>, Period>
|
|
|
|
| 12583 |
template <class Rep1, class Period, class Rep2>
|
| 12584 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 12585 |
constexpr operator/(const duration<Rep1, Period>& d, const Rep2& s);
|
| 12586 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12587 |
common_type_t<Rep1, Rep2>
|
| 12588 |
+
constexpr operator/(const duration<Rep1, Period1>& lhs,
|
| 12589 |
+
const duration<Rep2, Period2>& rhs);
|
| 12590 |
template <class Rep1, class Period, class Rep2>
|
| 12591 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 12592 |
constexpr operator%(const duration<Rep1, Period>& d, const Rep2& s);
|
| 12593 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12594 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 12595 |
+
constexpr operator%(const duration<Rep1, Period1>& lhs,
|
| 12596 |
+
const duration<Rep2, Period2>& rhs);
|
| 12597 |
|
| 12598 |
// [time.duration.comparisons], duration comparisons
|
| 12599 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12600 |
constexpr bool operator==(const duration<Rep1, Period1>& lhs,
|
| 12601 |
const duration<Rep2, Period2>& rhs);
|
|
|
|
| 12616 |
const duration<Rep2, Period2>& rhs);
|
| 12617 |
|
| 12618 |
// [time.duration.cast], duration_cast
|
| 12619 |
template <class ToDuration, class Rep, class Period>
|
| 12620 |
constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
|
| 12621 |
+
template <class ToDuration, class Rep, class Period>
|
| 12622 |
+
constexpr ToDuration floor(const duration<Rep, Period>& d);
|
| 12623 |
+
template <class ToDuration, class Rep, class Period>
|
| 12624 |
+
constexpr ToDuration ceil(const duration<Rep, Period>& d);
|
| 12625 |
+
template <class ToDuration, class Rep, class Period>
|
| 12626 |
+
constexpr ToDuration round(const duration<Rep, Period>& d);
|
| 12627 |
|
| 12628 |
// convenience typedefs
|
| 12629 |
+
using nanoseconds = duration<signed integer type of at least 64 bits, nano>;
|
| 12630 |
+
using microseconds = duration<signed integer type of at least 55 bits, micro>;
|
| 12631 |
+
using milliseconds = duration<signed integer type of at least 45 bits, milli>;
|
| 12632 |
+
using seconds = duration<signed integer type of at least 35 bits>;
|
| 12633 |
+
using minutes = duration<signed integer type of at least 29 bits, ratio< 60>>;
|
| 12634 |
+
using hours = duration<signed integer type of at least 23 bits, ratio<3600>>;
|
| 12635 |
|
| 12636 |
// [time.point.nonmember], time_point arithmetic
|
| 12637 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 12638 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 12639 |
+
operator+(const time_point<Clock, Duration1>& lhs,
|
| 12640 |
+
const duration<Rep2, Period2>& rhs);
|
| 12641 |
template <class Rep1, class Period1, class Clock, class Duration2>
|
| 12642 |
constexpr time_point<Clock, common_type_t<duration<Rep1, Period1>, Duration2>>
|
| 12643 |
+
operator+(const duration<Rep1, Period1>& lhs,
|
| 12644 |
+
const time_point<Clock, Duration2>& rhs);
|
| 12645 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 12646 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 12647 |
+
operator-(const time_point<Clock, Duration1>& lhs,
|
| 12648 |
+
const duration<Rep2, Period2>& rhs);
|
| 12649 |
template <class Clock, class Duration1, class Duration2>
|
| 12650 |
constexpr common_type_t<Duration1, Duration2>
|
| 12651 |
+
operator-(const time_point<Clock, Duration1>& lhs,
|
| 12652 |
+
const time_point<Clock, Duration2>& rhs);
|
| 12653 |
|
| 12654 |
+
// [time.point.comparisons], time_point comparisons
|
| 12655 |
template <class Clock, class Duration1, class Duration2>
|
| 12656 |
constexpr bool operator==(const time_point<Clock, Duration1>& lhs,
|
| 12657 |
const time_point<Clock, Duration2>& rhs);
|
| 12658 |
template <class Clock, class Duration1, class Duration2>
|
| 12659 |
constexpr bool operator!=(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 12673 |
|
| 12674 |
// [time.point.cast], time_point_cast
|
| 12675 |
template <class ToDuration, class Clock, class Duration>
|
| 12676 |
constexpr time_point<Clock, ToDuration>
|
| 12677 |
time_point_cast(const time_point<Clock, Duration>& t);
|
| 12678 |
+
template <class ToDuration, class Clock, class Duration>
|
| 12679 |
+
constexpr time_point<Clock, ToDuration>
|
| 12680 |
+
floor(const time_point<Clock, Duration>& tp);
|
| 12681 |
+
template <class ToDuration, class Clock, class Duration>
|
| 12682 |
+
constexpr time_point<Clock, ToDuration>
|
| 12683 |
+
ceil(const time_point<Clock, Duration>& tp);
|
| 12684 |
+
template <class ToDuration, class Clock, class Duration>
|
| 12685 |
+
constexpr time_point<Clock, ToDuration>
|
| 12686 |
+
round(const time_point<Clock, Duration>& tp);
|
| 12687 |
+
|
| 12688 |
+
// [time.duration.alg], specialized algorithms
|
| 12689 |
+
template <class Rep, class Period>
|
| 12690 |
+
constexpr duration<Rep, Period> abs(duration<Rep, Period> d);
|
| 12691 |
|
| 12692 |
// [time.clock], clocks
|
| 12693 |
class system_clock;
|
| 12694 |
class steady_clock;
|
| 12695 |
class high_resolution_clock;
|
| 12696 |
+
}
|
|
|
|
| 12697 |
|
| 12698 |
inline namespace literals {
|
| 12699 |
inline namespace chrono_literals {
|
| 12700 |
+
// [time.duration.literals], suffixes for duration literals
|
|
|
|
| 12701 |
constexpr chrono::hours operator""h(unsigned long long);
|
| 12702 |
constexpr chrono::duration<unspecified, ratio<3600,1>> operator""h(long double);
|
| 12703 |
constexpr chrono::minutes operator""min(unsigned long long);
|
| 12704 |
constexpr chrono::duration<unspecified, ratio<60,1>> operator""min(long double);
|
| 12705 |
constexpr chrono::seconds operator""s(unsigned long long);
|
|
|
|
| 12708 |
constexpr chrono::duration<unspecified, milli> operator""ms(long double);
|
| 12709 |
constexpr chrono::microseconds operator""us(unsigned long long);
|
| 12710 |
constexpr chrono::duration<unspecified, micro> operator""us(long double);
|
| 12711 |
constexpr chrono::nanoseconds operator""ns(unsigned long long);
|
| 12712 |
constexpr chrono::duration<unspecified, nano> operator""ns(long double);
|
| 12713 |
+
}
|
| 12714 |
+
}
|
|
|
|
| 12715 |
|
| 12716 |
namespace chrono {
|
|
|
|
| 12717 |
using namespace literals::chrono_literals;
|
| 12718 |
+
}
|
| 12719 |
+
}
|
|
|
|
|
|
|
| 12720 |
```
|
| 12721 |
|
| 12722 |
### Clock requirements <a id="time.clock.req">[[time.clock.req]]</a>
|
| 12723 |
|
| 12724 |
A clock is a bundle consisting of a `duration`, a `time_point`, and a
|
|
|
|
| 12727 |
shall meet the requirements in Table [[tab:time.clock]].
|
| 12728 |
|
| 12729 |
In Table [[tab:time.clock]] `C1` and `C2` denote clock types. `t1` and
|
| 12730 |
`t2` are values returned by `C1::now()` where the call returning `t1`
|
| 12731 |
happens before ([[intro.multithread]]) the call returning `t2` and both
|
| 12732 |
+
of these calls occur before `C1::time_point::max()`.
|
|
|
|
| 12733 |
|
| 12734 |
+
[*Note 1*: This means `C1` did not wrap around between `t1` and
|
| 12735 |
+
`t2`. — *end note*]
|
| 12736 |
+
|
| 12737 |
+
[*Note 2*: The relative difference in durations between those reported
|
| 12738 |
+
by a given clock and the SI definition is a measure of the quality of
|
| 12739 |
+
implementation. — *end note*]
|
| 12740 |
|
| 12741 |
A type `TC` meets the `TrivialClock` requirements if:
|
| 12742 |
|
| 12743 |
- `TC` satisfies the `Clock` requirements ([[time.clock.req]]),
|
| 12744 |
- the types `TC::rep`, `TC::duration`, and `TC::time_point` satisfy the
|
| 12745 |
+
requirements of `EqualityComparable` (Table
|
| 12746 |
+
[[tab:equalitycomparable]]), `LessThanComparable` (Table
|
| 12747 |
+
[[tab:lessthancomparable]]), `DefaultConstructible` (Table
|
| 12748 |
+
[[tab:defaultconstructible]]), `CopyConstructible` (Table
|
| 12749 |
+
[[tab:copyconstructible]]), `CopyAssignable` (Table
|
| 12750 |
+
[[tab:copyassignable]]), `Destructible` (Table [[tab:destructible]]),
|
| 12751 |
and the requirements of numeric types ([[numeric.requirements]]).
|
| 12752 |
+
\[*Note 3*: This means, in particular, that operations on these types
|
| 12753 |
+
will not throw exceptions. — *end note*]
|
| 12754 |
- lvalues of the types `TC::rep`, `TC::duration`, and `TC::time_point`
|
| 12755 |
are swappable ([[swappable.requirements]]),
|
| 12756 |
- the function `TC::now()` does not throw exceptions, and
|
| 12757 |
- the type `TC::time_point::clock` meets the `TrivialClock`
|
| 12758 |
requirements, recursively.
|
|
|
|
| 12766 |
: is_floating_point<Rep> { };
|
| 12767 |
```
|
| 12768 |
|
| 12769 |
The `duration` template uses the `treat_as_floating_point` trait to help
|
| 12770 |
determine if a `duration` object can be converted to another `duration`
|
| 12771 |
+
with a different tick `period`. If `treat_as_floating_point_v<Rep>` is
|
| 12772 |
+
`true`, then implicit conversions are allowed among `duration`s.
|
| 12773 |
Otherwise, the implicit convertibility depends on the tick `period`s of
|
| 12774 |
+
the `duration`s.
|
| 12775 |
+
|
| 12776 |
+
[*Note 1*: The intention of this trait is to indicate whether a given
|
| 12777 |
+
class behaves like a floating-point type, and thus allows division of
|
| 12778 |
+
one value by another with acceptable loss of precision. If
|
| 12779 |
+
`treat_as_floating_point_v<Rep>` is `false`, `Rep` will be treated as if
|
| 12780 |
+
it behaved like an integral type for the purpose of these
|
| 12781 |
+
conversions. — *end note*]
|
| 12782 |
|
| 12783 |
#### `duration_values` <a id="time.traits.duration_values">[[time.traits.duration_values]]</a>
|
| 12784 |
|
| 12785 |
``` cpp
|
| 12786 |
template <class Rep>
|
|
|
|
| 12801 |
|
| 12802 |
``` cpp
|
| 12803 |
static constexpr Rep zero();
|
| 12804 |
```
|
| 12805 |
|
| 12806 |
+
*Returns:* `Rep(0)`.
|
|
|
|
| 12807 |
|
| 12808 |
+
[*Note 1*: `Rep(0)` is specified instead of `Rep()` because `Rep()` may
|
| 12809 |
+
have some other meaning, such as an uninitialized value. — *end note*]
|
| 12810 |
+
|
| 12811 |
+
*Remarks:* The value returned shall be the additive identity.
|
| 12812 |
|
| 12813 |
``` cpp
|
| 12814 |
static constexpr Rep min();
|
| 12815 |
```
|
| 12816 |
|
| 12817 |
*Returns:* `numeric_limits<Rep>::lowest()`.
|
| 12818 |
|
| 12819 |
+
*Remarks:* The value returned shall compare less than or equal to
|
| 12820 |
+
`zero()`.
|
| 12821 |
|
| 12822 |
``` cpp
|
| 12823 |
static constexpr Rep max();
|
| 12824 |
```
|
| 12825 |
|
| 12826 |
*Returns:* `numeric_limits<Rep>::max()`.
|
| 12827 |
|
| 12828 |
+
*Remarks:* The value returned shall compare greater than `zero()`.
|
| 12829 |
|
| 12830 |
#### Specializations of `common_type` <a id="time.traits.specializations">[[time.traits.specializations]]</a>
|
| 12831 |
|
| 12832 |
``` cpp
|
| 12833 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12834 |
struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>> {
|
| 12835 |
+
using type = chrono::duration<common_type_t<Rep1, Rep2>, see below>;
|
| 12836 |
};
|
| 12837 |
```
|
| 12838 |
|
| 12839 |
The `period` of the `duration` indicated by this specialization of
|
| 12840 |
`common_type` shall be the greatest common divisor of `Period1` and
|
| 12841 |
+
`Period2`.
|
| 12842 |
+
|
| 12843 |
+
[*Note 1*: This can be computed by forming a ratio of the greatest
|
| 12844 |
common divisor of `Period1::num` and `Period2::num` and the least common
|
| 12845 |
+
multiple of `Period1::den` and `Period2::den`. — *end note*]
|
| 12846 |
|
| 12847 |
+
[*Note 2*: The `typedef` name `type` is a synonym for the `duration`
|
| 12848 |
+
with the largest tick `period` possible where both `duration` arguments
|
| 12849 |
+
will convert to it without requiring a division operation. The
|
| 12850 |
+
representation of this type is intended to be able to hold any value
|
| 12851 |
+
resulting from this conversion with no truncation error, although
|
| 12852 |
+
floating-point durations may have round-off errors. — *end note*]
|
| 12853 |
|
| 12854 |
``` cpp
|
| 12855 |
template <class Clock, class Duration1, class Duration2>
|
| 12856 |
struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>> {
|
| 12857 |
+
using type = chrono::time_point<Clock, common_type_t<Duration1, Duration2>>;
|
| 12858 |
};
|
| 12859 |
```
|
| 12860 |
|
| 12861 |
The common type of two `time_point` types is a `time_point` with the
|
| 12862 |
same clock as the two types and the common type of their two
|
|
|
|
| 12872 |
|
| 12873 |
``` cpp
|
| 12874 |
template <class Rep, class Period = ratio<1>>
|
| 12875 |
class duration {
|
| 12876 |
public:
|
| 12877 |
+
using rep = Rep;
|
| 12878 |
+
using period = typename Period::type;
|
| 12879 |
private:
|
| 12880 |
rep rep_; // exposition only
|
| 12881 |
public:
|
| 12882 |
+
// [time.duration.cons], construct/copy/destroy
|
| 12883 |
constexpr duration() = default;
|
| 12884 |
template <class Rep2>
|
| 12885 |
constexpr explicit duration(const Rep2& r);
|
| 12886 |
template <class Rep2, class Period2>
|
| 12887 |
constexpr duration(const duration<Rep2, Period2>& d);
|
| 12888 |
~duration() = default;
|
| 12889 |
duration(const duration&) = default;
|
| 12890 |
duration& operator=(const duration&) = default;
|
| 12891 |
|
| 12892 |
+
// [time.duration.observer], observer
|
| 12893 |
constexpr rep count() const;
|
| 12894 |
|
| 12895 |
+
// [time.duration.arithmetic], arithmetic
|
| 12896 |
+
constexpr common_type_t<duration> operator+() const;
|
| 12897 |
+
constexpr common_type_t<duration> operator-() const;
|
| 12898 |
+
constexpr duration& operator++();
|
| 12899 |
+
constexpr duration operator++(int);
|
| 12900 |
+
constexpr duration& operator--();
|
| 12901 |
+
constexpr duration operator--(int);
|
| 12902 |
|
| 12903 |
+
constexpr duration& operator+=(const duration& d);
|
| 12904 |
+
constexpr duration& operator-=(const duration& d);
|
| 12905 |
|
| 12906 |
+
constexpr duration& operator*=(const rep& rhs);
|
| 12907 |
+
constexpr duration& operator/=(const rep& rhs);
|
| 12908 |
+
constexpr duration& operator%=(const rep& rhs);
|
| 12909 |
+
constexpr duration& operator%=(const duration& rhs);
|
| 12910 |
|
| 12911 |
+
// [time.duration.special], special values
|
| 12912 |
static constexpr duration zero();
|
| 12913 |
static constexpr duration min();
|
| 12914 |
static constexpr duration max();
|
| 12915 |
};
|
| 12916 |
```
|
| 12917 |
|
| 12918 |
+
`Rep` shall be an arithmetic type or a class emulating an arithmetic
|
| 12919 |
+
type. If `duration` is instantiated with a `duration` type as the
|
| 12920 |
+
argument for the template parameter `Rep`, the program is ill-formed.
|
| 12921 |
|
| 12922 |
+
If `Period` is not a specialization of `ratio`, the program is
|
| 12923 |
+
ill-formed. If `Period::num` is not positive, the program is ill-formed.
|
| 12924 |
|
| 12925 |
+
Members of `duration` shall not throw exceptions other than those thrown
|
| 12926 |
+
by the indicated operations on their representations.
|
| 12927 |
|
| 12928 |
+
The defaulted copy constructor of duration shall be a constexpr function
|
| 12929 |
+
if and only if the required initialization of the member `rep_` for copy
|
| 12930 |
+
and move, respectively, would satisfy the requirements for a constexpr
|
| 12931 |
+
function.
|
| 12932 |
|
| 12933 |
+
[*Example 1*:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12934 |
|
| 12935 |
``` cpp
|
| 12936 |
duration<long, ratio<60>> d0; // holds a count of minutes using a long
|
| 12937 |
duration<long long, milli> d1; // holds a count of milliseconds using a long long
|
| 12938 |
duration<double, ratio<1, 30>> d2; // holds a count with a tick period of $\frac{1}{30}$ of a second
|
| 12939 |
// (30 Hz) using a double
|
| 12940 |
```
|
| 12941 |
|
| 12942 |
+
— *end example*]
|
| 12943 |
+
|
| 12944 |
#### `duration` constructors <a id="time.duration.cons">[[time.duration.cons]]</a>
|
| 12945 |
|
| 12946 |
``` cpp
|
| 12947 |
template <class Rep2>
|
| 12948 |
constexpr explicit duration(const Rep2& r);
|
| 12949 |
```
|
| 12950 |
|
| 12951 |
*Remarks:* This constructor shall not participate in overload resolution
|
| 12952 |
unless `Rep2` is implicitly convertible to `rep` and
|
| 12953 |
|
| 12954 |
+
- `treat_as_floating_point_v<rep>` is `true` or
|
| 12955 |
+
- `treat_as_floating_point_v<Rep2>` is `false`.
|
| 12956 |
+
|
| 12957 |
+
[*Example 1*:
|
| 12958 |
|
| 12959 |
``` cpp
|
| 12960 |
duration<int, milli> d(3); // OK
|
| 12961 |
duration<int, milli> d(3.5); // error
|
| 12962 |
```
|
| 12963 |
|
| 12964 |
+
— *end example*]
|
| 12965 |
+
|
| 12966 |
*Effects:* Constructs an object of type `duration`.
|
| 12967 |
|
| 12968 |
+
*Postconditions:* `count() == static_cast<rep>(r)`.
|
| 12969 |
|
| 12970 |
``` cpp
|
| 12971 |
template <class Rep2, class Period2>
|
| 12972 |
constexpr duration(const duration<Rep2, Period2>& d);
|
| 12973 |
```
|
| 12974 |
|
| 12975 |
*Remarks:* This constructor shall not participate in overload resolution
|
| 12976 |
unless no overflow is induced in the conversion and
|
| 12977 |
+
`treat_as_floating_point_v<rep>` is `true` or both
|
| 12978 |
`ratio_divide<Period2, period>::den` is `1` and
|
| 12979 |
+
`treat_as_floating_point_v<Rep2>` is `false`.
|
| 12980 |
+
|
| 12981 |
+
[*Note 1*: This requirement prevents implicit truncation error when
|
| 12982 |
+
converting between integral-based `duration` types. Such a construction
|
| 12983 |
+
could easily lead to confusion about the value of the
|
| 12984 |
+
`duration`. — *end note*]
|
| 12985 |
+
|
| 12986 |
+
[*Example 2*:
|
| 12987 |
|
| 12988 |
``` cpp
|
| 12989 |
duration<int, milli> ms(3);
|
| 12990 |
duration<int, micro> us = ms; // OK
|
| 12991 |
duration<int, milli> ms2 = us; // error
|
| 12992 |
```
|
| 12993 |
|
| 12994 |
+
— *end example*]
|
| 12995 |
+
|
| 12996 |
*Effects:* Constructs an object of type `duration`, constructing `rep_`
|
| 12997 |
from
|
| 12998 |
`duration_cast<duration>(d).count()`.
|
| 12999 |
|
| 13000 |
#### `duration` observer <a id="time.duration.observer">[[time.duration.observer]]</a>
|
|
|
|
| 13006 |
*Returns:* `rep_`.
|
| 13007 |
|
| 13008 |
#### `duration` arithmetic <a id="time.duration.arithmetic">[[time.duration.arithmetic]]</a>
|
| 13009 |
|
| 13010 |
``` cpp
|
| 13011 |
+
constexpr common_type_t<duration> operator+() const;
|
| 13012 |
```
|
| 13013 |
|
| 13014 |
+
*Returns:* `common_type_t<duration>(*this)`.
|
| 13015 |
|
| 13016 |
``` cpp
|
| 13017 |
+
constexpr common_type_t<duration> operator-() const;
|
| 13018 |
```
|
| 13019 |
|
| 13020 |
+
*Returns:* `common_type_t<duration>(-rep_)`.
|
| 13021 |
|
| 13022 |
``` cpp
|
| 13023 |
+
constexpr duration& operator++();
|
| 13024 |
```
|
| 13025 |
|
| 13026 |
+
*Effects:* As if by `++rep_`.
|
| 13027 |
|
| 13028 |
*Returns:* `*this`.
|
| 13029 |
|
| 13030 |
``` cpp
|
| 13031 |
+
constexpr duration operator++(int);
|
| 13032 |
```
|
| 13033 |
|
| 13034 |
+
*Returns:* `duration(rep_++)`.
|
| 13035 |
|
| 13036 |
``` cpp
|
| 13037 |
+
constexpr duration& operator--();
|
| 13038 |
```
|
| 13039 |
|
| 13040 |
+
*Effects:* As if by `–rep_`.
|
| 13041 |
|
| 13042 |
*Returns:* `*this`.
|
| 13043 |
|
| 13044 |
``` cpp
|
| 13045 |
+
constexpr duration operator--(int);
|
| 13046 |
```
|
| 13047 |
|
| 13048 |
+
*Returns:* `duration(rep_--)`.
|
| 13049 |
|
| 13050 |
``` cpp
|
| 13051 |
+
constexpr duration& operator+=(const duration& d);
|
| 13052 |
```
|
| 13053 |
|
| 13054 |
+
*Effects:* As if by: `rep_ += d.count();`
|
| 13055 |
|
| 13056 |
*Returns:* `*this`.
|
| 13057 |
|
| 13058 |
``` cpp
|
| 13059 |
+
constexpr duration& operator-=(const duration& d);
|
| 13060 |
```
|
| 13061 |
|
| 13062 |
+
*Effects:* As if by: `rep_ -= d.count();`
|
| 13063 |
|
| 13064 |
*Returns:* `*this`.
|
| 13065 |
|
| 13066 |
``` cpp
|
| 13067 |
+
constexpr duration& operator*=(const rep& rhs);
|
| 13068 |
```
|
| 13069 |
|
| 13070 |
+
*Effects:* As if by: `rep_ *= rhs;`
|
| 13071 |
|
| 13072 |
*Returns:* `*this`.
|
| 13073 |
|
| 13074 |
``` cpp
|
| 13075 |
+
constexpr duration& operator/=(const rep& rhs);
|
| 13076 |
```
|
| 13077 |
|
| 13078 |
+
*Effects:* As if by: `rep_ /= rhs;`
|
| 13079 |
|
| 13080 |
*Returns:* `*this`.
|
| 13081 |
|
| 13082 |
``` cpp
|
| 13083 |
+
constexpr duration& operator%=(const rep& rhs);
|
| 13084 |
```
|
| 13085 |
|
| 13086 |
+
*Effects:* As if by: `rep_ %= rhs;`
|
| 13087 |
|
| 13088 |
*Returns:* `*this`.
|
| 13089 |
|
| 13090 |
``` cpp
|
| 13091 |
+
constexpr duration& operator%=(const duration& rhs);
|
| 13092 |
```
|
| 13093 |
|
| 13094 |
+
*Effects:* As if by: `rep_ %= rhs.count();`
|
| 13095 |
|
| 13096 |
*Returns:* `*this`.
|
| 13097 |
|
| 13098 |
#### `duration` special values <a id="time.duration.special">[[time.duration.special]]</a>
|
| 13099 |
|
|
|
|
| 13124 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 13125 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 13126 |
operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 13127 |
```
|
| 13128 |
|
| 13129 |
+
*Returns:* `CD(CD(lhs).count() + CD(rhs).count())`.
|
| 13130 |
|
| 13131 |
``` cpp
|
| 13132 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 13133 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 13134 |
operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 13135 |
```
|
| 13136 |
|
| 13137 |
+
*Returns:* `CD(CD(lhs).count() - CD(rhs).count())`.
|
| 13138 |
|
| 13139 |
``` cpp
|
| 13140 |
template <class Rep1, class Period, class Rep2>
|
| 13141 |
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 13142 |
operator*(const duration<Rep1, Period>& d, const Rep2& s);
|
| 13143 |
```
|
| 13144 |
|
| 13145 |
*Remarks:* This operator shall not participate in overload resolution
|
| 13146 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)`.
|
| 13147 |
|
| 13148 |
+
*Returns:* `CD(CD(d).count() * s)`.
|
| 13149 |
|
| 13150 |
``` cpp
|
| 13151 |
template <class Rep1, class Rep2, class Period>
|
| 13152 |
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 13153 |
operator*(const Rep1& s, const duration<Rep2, Period>& d);
|
|
|
|
| 13164 |
operator/(const duration<Rep1, Period>& d, const Rep2& s);
|
| 13165 |
```
|
| 13166 |
|
| 13167 |
*Remarks:* This operator shall not participate in overload resolution
|
| 13168 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
|
| 13169 |
+
is not a specialization of `duration`.
|
| 13170 |
|
| 13171 |
+
*Returns:* `CD(CD(d).count() / s)`.
|
| 13172 |
|
| 13173 |
``` cpp
|
| 13174 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 13175 |
constexpr common_type_t<Rep1, Rep2>
|
| 13176 |
operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
|
|
| 13184 |
operator%(const duration<Rep1, Period>& d, const Rep2& s);
|
| 13185 |
```
|
| 13186 |
|
| 13187 |
*Remarks:* This operator shall not participate in overload resolution
|
| 13188 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
|
| 13189 |
+
is not a specialization of `duration`.
|
| 13190 |
|
| 13191 |
+
*Returns:* `CD(CD(d).count() % s)`.
|
| 13192 |
|
| 13193 |
``` cpp
|
| 13194 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 13195 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 13196 |
operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 13197 |
```
|
| 13198 |
|
| 13199 |
+
*Returns:* `CD(CD(lhs).count() % CD(rhs).count())`.
|
| 13200 |
|
| 13201 |
#### `duration` comparisons <a id="time.duration.comparisons">[[time.duration.comparisons]]</a>
|
| 13202 |
|
| 13203 |
In the function descriptions that follow, `CT` represents
|
| 13204 |
`common_type_t<A, B>`, where `A` and `B` are the types of the two
|
| 13205 |
arguments to the function.
|
| 13206 |
|
| 13207 |
``` cpp
|
| 13208 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 13209 |
+
constexpr bool operator==(const duration<Rep1, Period1>& lhs,
|
| 13210 |
+
const duration<Rep2, Period2>& rhs);
|
| 13211 |
```
|
| 13212 |
|
| 13213 |
+
*Returns:* *`CT`*`(lhs).count() == `*`CT`*`(rhs).count()`.
|
| 13214 |
|
| 13215 |
``` cpp
|
| 13216 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 13217 |
+
constexpr bool operator!=(const duration<Rep1, Period1>& lhs,
|
| 13218 |
+
const duration<Rep2, Period2>& rhs);
|
| 13219 |
```
|
| 13220 |
|
| 13221 |
*Returns:* `!(lhs == rhs)`.
|
| 13222 |
|
| 13223 |
``` cpp
|
| 13224 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 13225 |
+
constexpr bool operator<(const duration<Rep1, Period1>& lhs,
|
| 13226 |
+
const duration<Rep2, Period2>& rhs);
|
| 13227 |
```
|
| 13228 |
|
| 13229 |
+
*Returns:* *`CT`*`(lhs).count() < `*`CT`*`(rhs).count()`.
|
| 13230 |
|
| 13231 |
``` cpp
|
| 13232 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 13233 |
+
constexpr bool operator<=(const duration<Rep1, Period1>& lhs,
|
| 13234 |
+
const duration<Rep2, Period2>& rhs);
|
| 13235 |
```
|
| 13236 |
|
| 13237 |
*Returns:* `!(rhs < lhs)`.
|
| 13238 |
|
| 13239 |
``` cpp
|
| 13240 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 13241 |
+
constexpr bool operator>(const duration<Rep1, Period1>& lhs,
|
| 13242 |
+
const duration<Rep2, Period2>& rhs);
|
| 13243 |
```
|
| 13244 |
|
| 13245 |
*Returns:* `rhs < lhs`.
|
| 13246 |
|
| 13247 |
``` cpp
|
| 13248 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 13249 |
+
constexpr bool operator>=(const duration<Rep1, Period1>& lhs,
|
| 13250 |
+
const duration<Rep2, Period2>& rhs);
|
| 13251 |
```
|
| 13252 |
|
| 13253 |
*Returns:* `!(lhs < rhs)`.
|
| 13254 |
|
| 13255 |
#### `duration_cast` <a id="time.duration.cast">[[time.duration.cast]]</a>
|
|
|
|
| 13258 |
template <class ToDuration, class Rep, class Period>
|
| 13259 |
constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
|
| 13260 |
```
|
| 13261 |
|
| 13262 |
*Remarks:* This function shall not participate in overload resolution
|
| 13263 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 13264 |
|
| 13265 |
*Returns:* Let `CF` be
|
| 13266 |
`ratio_divide<Period, typename ToDuration::period>`, and `CR` be
|
| 13267 |
+
`common_type<` `typename ToDuration::rep, Rep, intmax_t>::type`.
|
| 13268 |
|
| 13269 |
- If `CF::num == 1` and `CF::den == 1`, returns
|
| 13270 |
``` cpp
|
| 13271 |
ToDuration(static_cast<typename ToDuration::rep>(d.count()))
|
| 13272 |
```
|
|
|
|
| 13284 |
``` cpp
|
| 13285 |
ToDuration(static_cast<typename ToDuration::rep>(
|
| 13286 |
static_cast<CR>(d.count()) * static_cast<CR>(CF::num) / static_cast<CR>(CF::den)))
|
| 13287 |
```
|
| 13288 |
|
| 13289 |
+
[*Note 1*: This function does not use any implicit conversions; all
|
| 13290 |
conversions are done with `static_cast`. It avoids multiplications and
|
| 13291 |
divisions when it is known at compile time that one or more arguments
|
| 13292 |
is 1. Intermediate computations are carried out in the widest
|
| 13293 |
representation and only converted to the destination representation at
|
| 13294 |
+
the final step. — *end note*]
|
| 13295 |
+
|
| 13296 |
+
``` cpp
|
| 13297 |
+
template <class ToDuration, class Rep, class Period>
|
| 13298 |
+
constexpr ToDuration floor(const duration<Rep, Period>& d);
|
| 13299 |
+
```
|
| 13300 |
+
|
| 13301 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 13302 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 13303 |
+
|
| 13304 |
+
*Returns:* The greatest result `t` representable in `ToDuration` for
|
| 13305 |
+
which `t <= d`.
|
| 13306 |
+
|
| 13307 |
+
``` cpp
|
| 13308 |
+
template <class ToDuration, class Rep, class Period>
|
| 13309 |
+
constexpr ToDuration ceil(const duration<Rep, Period>& d);
|
| 13310 |
+
```
|
| 13311 |
+
|
| 13312 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 13313 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 13314 |
+
|
| 13315 |
+
*Returns:* The least result `t` representable in `ToDuration` for which
|
| 13316 |
+
`t >= d`.
|
| 13317 |
+
|
| 13318 |
+
``` cpp
|
| 13319 |
+
template <class ToDuration, class Rep, class Period>
|
| 13320 |
+
constexpr ToDuration round(const duration<Rep, Period>& d);
|
| 13321 |
+
```
|
| 13322 |
+
|
| 13323 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 13324 |
+
unless `ToDuration` is a specialization of `duration`, and
|
| 13325 |
+
`treat_as_floating_point_v<typename ToDuration::rep>` is `false`.
|
| 13326 |
+
|
| 13327 |
+
*Returns:* The value of `ToDuration` that is closest to `d`. If there
|
| 13328 |
+
are two closest values, then return the value `t` for which
|
| 13329 |
+
`t % 2 == 0`.
|
| 13330 |
|
| 13331 |
#### Suffixes for duration literals <a id="time.duration.literals">[[time.duration.literals]]</a>
|
| 13332 |
|
| 13333 |
This section describes literal suffixes for constructing duration
|
| 13334 |
literals. The suffixes `h`, `min`, `s`, `ms`, `us`, `ns` denote duration
|
| 13335 |
values of the corresponding types `hours`, `minutes`, `seconds`,
|
| 13336 |
`milliseconds`, `microseconds`, and `nanoseconds` respectively if they
|
| 13337 |
are applied to integral literals.
|
| 13338 |
|
| 13339 |
+
If any of these suffixes are applied to a floating-point literal the
|
| 13340 |
+
result is a `chrono::duration` literal with an unspecified
|
| 13341 |
+
floating-point representation.
|
| 13342 |
|
| 13343 |
If any of these suffixes are applied to an integer literal and the
|
| 13344 |
resulting `chrono::duration` value cannot be represented in the result
|
| 13345 |
type because of overflow, the program is ill-formed.
|
| 13346 |
|
| 13347 |
+
[*Example 1*:
|
| 13348 |
+
|
| 13349 |
The following code shows some duration literals.
|
| 13350 |
|
| 13351 |
``` cpp
|
| 13352 |
using namespace std::chrono_literals;
|
| 13353 |
auto constexpr aday=24h;
|
| 13354 |
auto constexpr lesson=45min;
|
| 13355 |
auto constexpr halfanhour=0.5h;
|
| 13356 |
```
|
| 13357 |
|
| 13358 |
+
— *end example*]
|
| 13359 |
+
|
| 13360 |
``` cpp
|
| 13361 |
constexpr chrono::hours operator""h(unsigned long long hours);
|
| 13362 |
constexpr chrono::duration<unspecified, ratio<3600, 1>> operator""h(long double hours);
|
| 13363 |
```
|
| 13364 |
|
|
|
|
| 13370 |
```
|
| 13371 |
|
| 13372 |
*Returns:* A `duration` literal representing `minutes` minutes.
|
| 13373 |
|
| 13374 |
``` cpp
|
| 13375 |
+
constexpr chrono::seconds \itcorr operator""s(unsigned long long sec);
|
| 13376 |
constexpr chrono::duration<unspecified> operator""s(long double sec);
|
| 13377 |
```
|
| 13378 |
|
| 13379 |
*Returns:* A `duration` literal representing `sec` seconds.
|
| 13380 |
|
| 13381 |
+
[*Note 1*: The same suffix `s` is used for `basic_string` but there is
|
| 13382 |
+
no conflict, since duration suffixes apply to numbers and string literal
|
| 13383 |
+
suffixes apply to character array literals. — *end note*]
|
| 13384 |
|
| 13385 |
``` cpp
|
| 13386 |
constexpr chrono::milliseconds operator""ms(unsigned long long msec);
|
| 13387 |
constexpr chrono::duration<unspecified, milli> operator""ms(long double msec);
|
| 13388 |
```
|
|
|
|
| 13401 |
constexpr chrono::duration<unspecified, nano> operator""ns(long double nsec);
|
| 13402 |
```
|
| 13403 |
|
| 13404 |
*Returns:* A `duration` literal representing `nsec` nanoseconds.
|
| 13405 |
|
| 13406 |
+
#### `duration` algorithms <a id="time.duration.alg">[[time.duration.alg]]</a>
|
| 13407 |
+
|
| 13408 |
+
``` cpp
|
| 13409 |
+
template <class Rep, class Period>
|
| 13410 |
+
constexpr duration<Rep, Period> abs(duration<Rep, Period> d);
|
| 13411 |
+
```
|
| 13412 |
+
|
| 13413 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 13414 |
+
unless `numeric_limits<Rep>::is_signed` is `true`.
|
| 13415 |
+
|
| 13416 |
+
*Returns:* If `d >= d.zero()`, return `d`, otherwise return `-d`.
|
| 13417 |
+
|
| 13418 |
### Class template `time_point` <a id="time.point">[[time.point]]</a>
|
| 13419 |
|
| 13420 |
``` cpp
|
| 13421 |
template <class Clock, class Duration = typename Clock::duration>
|
| 13422 |
class time_point {
|
| 13423 |
public:
|
| 13424 |
+
using clock = Clock;
|
| 13425 |
+
using duration = Duration;
|
| 13426 |
+
using rep = typename duration::rep;
|
| 13427 |
+
using period = typename duration::period;
|
| 13428 |
private:
|
| 13429 |
duration d_; // exposition only
|
| 13430 |
|
| 13431 |
public:
|
| 13432 |
+
// [time.point.cons], construct
|
| 13433 |
constexpr time_point(); // has value epoch
|
| 13434 |
constexpr explicit time_point(const duration& d); // same as time_point() + d
|
| 13435 |
template <class Duration2>
|
| 13436 |
constexpr time_point(const time_point<clock, Duration2>& t);
|
| 13437 |
|
| 13438 |
+
// [time.point.observer], observer
|
| 13439 |
constexpr duration time_since_epoch() const;
|
| 13440 |
|
| 13441 |
+
// [time.point.arithmetic], arithmetic
|
| 13442 |
+
constexpr time_point& operator+=(const duration& d);
|
| 13443 |
+
constexpr time_point& operator-=(const duration& d);
|
| 13444 |
|
| 13445 |
+
// [time.point.special], special values
|
| 13446 |
static constexpr time_point min();
|
| 13447 |
static constexpr time_point max();
|
| 13448 |
};
|
| 13449 |
```
|
| 13450 |
|
| 13451 |
+
`Clock` shall meet the Clock requirements ([[time.clock.req]]).
|
| 13452 |
|
| 13453 |
If `Duration` is not an instance of `duration`, the program is
|
| 13454 |
ill-formed.
|
| 13455 |
|
| 13456 |
#### `time_point` constructors <a id="time.point.cons">[[time.point.cons]]</a>
|
|
|
|
| 13490 |
*Returns:* `d_`.
|
| 13491 |
|
| 13492 |
#### `time_point` arithmetic <a id="time.point.arithmetic">[[time.point.arithmetic]]</a>
|
| 13493 |
|
| 13494 |
``` cpp
|
| 13495 |
+
constexpr time_point& operator+=(const duration& d);
|
| 13496 |
```
|
| 13497 |
|
| 13498 |
+
*Effects:* As if by: `d_ += d;`
|
| 13499 |
|
| 13500 |
*Returns:* `*this`.
|
| 13501 |
|
| 13502 |
``` cpp
|
| 13503 |
+
constexpr time_point& operator-=(const duration& d);
|
| 13504 |
```
|
| 13505 |
|
| 13506 |
+
*Effects:* As if by: `d_ -= d;`
|
| 13507 |
|
| 13508 |
*Returns:* `*this`.
|
| 13509 |
|
| 13510 |
#### `time_point` special values <a id="time.point.special">[[time.point.special]]</a>
|
| 13511 |
|
|
|
|
| 13527 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 13528 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 13529 |
operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 13530 |
```
|
| 13531 |
|
| 13532 |
+
*Returns:* *`CT`*`(lhs.time_since_epoch() + rhs)`, where *`CT`* is the
|
| 13533 |
+
type of the return value.
|
| 13534 |
|
| 13535 |
``` cpp
|
| 13536 |
template <class Rep1, class Period1, class Clock, class Duration2>
|
| 13537 |
constexpr time_point<Clock, common_type_t<duration<Rep1, Period1>, Duration2>>
|
| 13538 |
operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
|
|
| 13544 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 13545 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 13546 |
operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 13547 |
```
|
| 13548 |
|
| 13549 |
+
*Returns:* *`CT`*`(lhs.time_since_epoch() - rhs)`, where *`CT`* is the
|
| 13550 |
+
type of the return value.
|
| 13551 |
|
| 13552 |
``` cpp
|
| 13553 |
template <class Clock, class Duration1, class Duration2>
|
| 13554 |
constexpr common_type_t<Duration1, Duration2>
|
| 13555 |
operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
|
|
| 13559 |
|
| 13560 |
#### `time_point` comparisons <a id="time.point.comparisons">[[time.point.comparisons]]</a>
|
| 13561 |
|
| 13562 |
``` cpp
|
| 13563 |
template <class Clock, class Duration1, class Duration2>
|
| 13564 |
+
constexpr bool operator==(const time_point<Clock, Duration1>& lhs,
|
| 13565 |
+
const time_point<Clock, Duration2>& rhs);
|
| 13566 |
```
|
| 13567 |
|
| 13568 |
*Returns:* `lhs.time_since_epoch() == rhs.time_since_epoch()`.
|
| 13569 |
|
| 13570 |
``` cpp
|
| 13571 |
template <class Clock, class Duration1, class Duration2>
|
| 13572 |
+
constexpr bool operator!=(const time_point<Clock, Duration1>& lhs,
|
| 13573 |
+
const time_point<Clock, Duration2>& rhs);
|
| 13574 |
```
|
| 13575 |
|
| 13576 |
*Returns:* `!(lhs == rhs)`.
|
| 13577 |
|
| 13578 |
``` cpp
|
| 13579 |
template <class Clock, class Duration1, class Duration2>
|
| 13580 |
+
constexpr bool operator<(const time_point<Clock, Duration1>& lhs,
|
| 13581 |
+
const time_point<Clock, Duration2>& rhs);
|
| 13582 |
```
|
| 13583 |
|
| 13584 |
*Returns:* `lhs.time_since_epoch() < rhs.time_since_epoch()`.
|
| 13585 |
|
| 13586 |
``` cpp
|
| 13587 |
template <class Clock, class Duration1, class Duration2>
|
| 13588 |
+
constexpr bool operator<=(const time_point<Clock, Duration1>& lhs,
|
| 13589 |
+
const time_point<Clock, Duration2>& rhs);
|
| 13590 |
```
|
| 13591 |
|
| 13592 |
*Returns:* `!(rhs < lhs)`.
|
| 13593 |
|
| 13594 |
``` cpp
|
| 13595 |
template <class Clock, class Duration1, class Duration2>
|
| 13596 |
+
constexpr bool operator>(const time_point<Clock, Duration1>& lhs,
|
| 13597 |
+
const time_point<Clock, Duration2>& rhs);
|
| 13598 |
```
|
| 13599 |
|
| 13600 |
*Returns:* `rhs < lhs`.
|
| 13601 |
|
| 13602 |
``` cpp
|
| 13603 |
template <class Clock, class Duration1, class Duration2>
|
| 13604 |
+
constexpr bool operator>=(const time_point<Clock, Duration1>& lhs,
|
| 13605 |
+
const time_point<Clock, Duration2>& rhs);
|
| 13606 |
```
|
| 13607 |
|
| 13608 |
*Returns:* `!(lhs < rhs)`.
|
| 13609 |
|
| 13610 |
#### `time_point_cast` <a id="time.point.cast">[[time.point.cast]]</a>
|
|
|
|
| 13614 |
constexpr time_point<Clock, ToDuration>
|
| 13615 |
time_point_cast(const time_point<Clock, Duration>& t);
|
| 13616 |
```
|
| 13617 |
|
| 13618 |
*Remarks:* This function shall not participate in overload resolution
|
| 13619 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 13620 |
|
| 13621 |
*Returns:*
|
| 13622 |
+
|
| 13623 |
+
``` cpp
|
| 13624 |
+
time_point<Clock, ToDuration>(duration_cast<ToDuration>(t.time_since_epoch()))
|
| 13625 |
+
```
|
| 13626 |
+
|
| 13627 |
+
``` cpp
|
| 13628 |
+
template <class ToDuration, class Clock, class Duration>
|
| 13629 |
+
constexpr time_point<Clock, ToDuration>
|
| 13630 |
+
floor(const time_point<Clock, Duration>& tp);
|
| 13631 |
+
```
|
| 13632 |
+
|
| 13633 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 13634 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 13635 |
+
|
| 13636 |
+
*Returns:*
|
| 13637 |
+
`time_point<Clock, ToDuration>(floor<ToDuration>(tp.time_since_epoch()))`.
|
| 13638 |
+
|
| 13639 |
+
``` cpp
|
| 13640 |
+
template <class ToDuration, class Clock, class Duration>
|
| 13641 |
+
constexpr time_point<Clock, ToDuration>
|
| 13642 |
+
ceil(const time_point<Clock, Duration>& tp);
|
| 13643 |
+
```
|
| 13644 |
+
|
| 13645 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 13646 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 13647 |
+
|
| 13648 |
+
*Returns:*
|
| 13649 |
+
`time_point<Clock, ToDuration>(ceil<ToDuration>(tp.time_since_epoch()))`.
|
| 13650 |
+
|
| 13651 |
+
``` cpp
|
| 13652 |
+
template <class ToDuration, class Clock, class Duration>
|
| 13653 |
+
constexpr time_point<Clock, ToDuration>
|
| 13654 |
+
round(const time_point<Clock, Duration>& tp);
|
| 13655 |
+
```
|
| 13656 |
+
|
| 13657 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 13658 |
+
unless `ToDuration` is a specialization of `duration`, and
|
| 13659 |
+
`treat_as_floating_point_v<typename ToDuration::rep>` is `false`.
|
| 13660 |
+
|
| 13661 |
+
*Returns:*
|
| 13662 |
+
`time_point<Clock, ToDuration>(round<ToDuration>(tp.time_since_epoch()))`.
|
| 13663 |
|
| 13664 |
### Clocks <a id="time.clock">[[time.clock]]</a>
|
| 13665 |
|
| 13666 |
The types defined in this subclause shall satisfy the `TrivialClock`
|
| 13667 |
requirements ([[time.clock.req]]).
|
|
|
|
| 13672 |
system-wide realtime clock.
|
| 13673 |
|
| 13674 |
``` cpp
|
| 13675 |
class system_clock {
|
| 13676 |
public:
|
| 13677 |
+
using rep = see below;
|
| 13678 |
+
using period = ratio<unspecified, unspecified{}>;
|
| 13679 |
+
using duration = chrono::duration<rep, period>;
|
| 13680 |
+
using time_point = chrono::time_point<system_clock>;
|
| 13681 |
static constexpr bool is_steady = unspecified;
|
| 13682 |
|
| 13683 |
static time_point now() noexcept;
|
| 13684 |
|
| 13685 |
// Map to C API
|
|
|
|
| 13687 |
static time_point from_time_t(time_t t) noexcept;
|
| 13688 |
};
|
| 13689 |
```
|
| 13690 |
|
| 13691 |
``` cpp
|
| 13692 |
+
using system_clock::rep = unspecified;
|
| 13693 |
```
|
| 13694 |
|
| 13695 |
*Requires:*
|
| 13696 |
`system_clock::duration::min() < system_clock::duration::zero()` shall
|
| 13697 |
+
be `true`.
|
| 13698 |
+
|
| 13699 |
+
[*Note 1*: This implies that `rep` is a signed type. — *end note*]
|
| 13700 |
|
| 13701 |
``` cpp
|
| 13702 |
static time_t to_time_t(const time_point& t) noexcept;
|
| 13703 |
```
|
| 13704 |
|
| 13705 |
*Returns:* A `time_t` object that represents the same point in time as
|
| 13706 |
`t` when both values are restricted to the coarser of the precisions of
|
| 13707 |
+
`time_t` and `time_point`. It is *implementation-defined* whether values
|
| 13708 |
are rounded or truncated to the required precision.
|
| 13709 |
|
| 13710 |
``` cpp
|
| 13711 |
static time_point from_time_t(time_t t) noexcept;
|
| 13712 |
```
|
| 13713 |
|
| 13714 |
*Returns:* A `time_point` object that represents the same point in time
|
| 13715 |
as `t` when both values are restricted to the coarser of the precisions
|
| 13716 |
+
of `time_t` and `time_point`. It is *implementation-defined* whether
|
| 13717 |
values are rounded or truncated to the required precision.
|
| 13718 |
|
| 13719 |
#### Class `steady_clock` <a id="time.clock.steady">[[time.clock.steady]]</a>
|
| 13720 |
|
| 13721 |
Objects of class `steady_clock` represent clocks for which values of
|
|
|
|
| 13724 |
That is, the clock may not be adjusted.
|
| 13725 |
|
| 13726 |
``` cpp
|
| 13727 |
class steady_clock {
|
| 13728 |
public:
|
| 13729 |
+
using rep = unspecified;
|
| 13730 |
+
using period = ratio<unspecified, unspecified{}>;
|
| 13731 |
+
using duration = chrono::duration<rep, period>;
|
| 13732 |
+
using time_point = chrono::time_point<unspecified, duration>;
|
| 13733 |
static constexpr bool is_steady = true;
|
| 13734 |
|
| 13735 |
static time_point now() noexcept;
|
| 13736 |
};
|
| 13737 |
```
|
|
|
|
| 13743 |
`system_clock` or `steady_clock`.
|
| 13744 |
|
| 13745 |
``` cpp
|
| 13746 |
class high_resolution_clock {
|
| 13747 |
public:
|
| 13748 |
+
using rep = unspecified;
|
| 13749 |
+
using period = ratio<unspecified, unspecified{}>;
|
| 13750 |
+
using duration = chrono::duration<rep, period>;
|
| 13751 |
+
using time_point = chrono::time_point<unspecified, duration>;
|
| 13752 |
static constexpr bool is_steady = unspecified;
|
| 13753 |
|
| 13754 |
static time_point now() noexcept;
|
| 13755 |
};
|
| 13756 |
```
|
| 13757 |
|
| 13758 |
+
### Header `<ctime>` synopsis <a id="ctime.syn">[[ctime.syn]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13759 |
|
| 13760 |
``` cpp
|
| 13761 |
+
#define NULL see [support.types.nullptr]
|
| 13762 |
+
#define CLOCKS_PER_SEC see below
|
| 13763 |
+
#define TIME_UTC see below
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13764 |
|
|
|
|
| 13765 |
namespace std {
|
| 13766 |
+
using size_t = see [support.types.layout];
|
| 13767 |
+
using clock_t = see below;
|
| 13768 |
+
using time_t = see below;
|
| 13769 |
+
|
| 13770 |
+
struct timespec;
|
| 13771 |
+
struct tm;
|
| 13772 |
+
|
| 13773 |
+
clock_t clock();
|
| 13774 |
+
double difftime(time_t time1, time_t time0);
|
| 13775 |
+
time_t mktime(struct tm* timeptr);
|
| 13776 |
+
time_t time(time_t* timer);
|
| 13777 |
+
int timespec_get(timespec* ts, int base);
|
| 13778 |
+
char* asctime(const struct tm* timeptr);
|
| 13779 |
+
char* ctime(const time_t* timer);
|
| 13780 |
+
struct tm* gmtime(const time_t* timer);
|
| 13781 |
+
struct tm* localtime(const time_t* timer);
|
| 13782 |
+
size_t strftime(char* s, size_t maxsize, const char* format, const struct tm* timeptr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13783 |
}
|
| 13784 |
```
|
| 13785 |
|
| 13786 |
+
The contents of the header `<ctime>` are the same as the C standard
|
| 13787 |
+
library header `<time.h>`. [^3]
|
| 13788 |
|
| 13789 |
+
The functions `asctime`, `ctime`, `gmtime`, and `localtime` are not
|
| 13790 |
+
required to avoid data races ([[res.on.data.races]]).
|
|
|
|
| 13791 |
|
| 13792 |
+
ISO C 7.27.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13793 |
|
| 13794 |
## Class `type_index` <a id="type.index">[[type.index]]</a>
|
| 13795 |
|
| 13796 |
### Header `<typeindex>` synopsis <a id="type.index.synopsis">[[type.index.synopsis]]</a>
|
| 13797 |
|
|
|
|
| 13835 |
|
| 13836 |
``` cpp
|
| 13837 |
type_index(const type_info& rhs) noexcept;
|
| 13838 |
```
|
| 13839 |
|
| 13840 |
+
*Effects:* Constructs a `type_index` object, the equivalent of
|
| 13841 |
`target = &rhs`.
|
| 13842 |
|
| 13843 |
``` cpp
|
| 13844 |
bool operator==(const type_index& rhs) const noexcept;
|
| 13845 |
```
|
| 13846 |
|
| 13847 |
+
*Returns:* `*target == *rhs.target`.
|
| 13848 |
|
| 13849 |
``` cpp
|
| 13850 |
bool operator!=(const type_index& rhs) const noexcept;
|
| 13851 |
```
|
| 13852 |
|
| 13853 |
+
*Returns:* `*target != *rhs.target`.
|
| 13854 |
|
| 13855 |
``` cpp
|
| 13856 |
bool operator<(const type_index& rhs) const noexcept;
|
| 13857 |
```
|
| 13858 |
|
| 13859 |
+
*Returns:* `target->before(*rhs.target)`.
|
| 13860 |
|
| 13861 |
``` cpp
|
| 13862 |
bool operator<=(const type_index& rhs) const noexcept;
|
| 13863 |
```
|
| 13864 |
|
| 13865 |
+
*Returns:* `!rhs.target->before(*target)`.
|
| 13866 |
|
| 13867 |
``` cpp
|
| 13868 |
bool operator>(const type_index& rhs) const noexcept;
|
| 13869 |
```
|
| 13870 |
|
| 13871 |
+
*Returns:* `rhs.target->before(*target)`.
|
| 13872 |
|
| 13873 |
``` cpp
|
| 13874 |
bool operator>=(const type_index& rhs) const noexcept;
|
| 13875 |
```
|
| 13876 |
|
| 13877 |
+
*Returns:* `!target->before(*rhs.target)`.
|
| 13878 |
|
| 13879 |
``` cpp
|
| 13880 |
size_t hash_code() const noexcept;
|
| 13881 |
```
|
| 13882 |
|
| 13883 |
+
*Returns:* `target->hash_code()`.
|
| 13884 |
|
| 13885 |
``` cpp
|
| 13886 |
const char* name() const noexcept;
|
| 13887 |
```
|
| 13888 |
|
| 13889 |
+
*Returns:* `target->name()`.
|
| 13890 |
|
| 13891 |
### Hash support <a id="type.index.hash">[[type.index.hash]]</a>
|
| 13892 |
|
| 13893 |
``` cpp
|
| 13894 |
template <> struct hash<type_index>;
|
| 13895 |
```
|
| 13896 |
|
| 13897 |
+
For an object `index` of type `type_index`, `hash<type_index>()(index)`
|
| 13898 |
+
shall evaluate to the same result as `index.hash_code()`.
|
| 13899 |
+
|
| 13900 |
+
## Execution policies <a id="execpol">[[execpol]]</a>
|
| 13901 |
+
|
| 13902 |
+
### In general <a id="execpol.general">[[execpol.general]]</a>
|
| 13903 |
+
|
| 13904 |
+
This subclause describes classes that are *execution policy* types. An
|
| 13905 |
+
object of an execution policy type indicates the kinds of parallelism
|
| 13906 |
+
allowed in the execution of an algorithm and expresses the consequent
|
| 13907 |
+
requirements on the element access functions.
|
| 13908 |
+
|
| 13909 |
+
[*Example 1*:
|
| 13910 |
+
|
| 13911 |
+
``` cpp
|
| 13912 |
+
using namespace std;
|
| 13913 |
+
vector<int> v = ...;
|
| 13914 |
+
|
| 13915 |
+
// standard sequential sort
|
| 13916 |
+
sort(v.begin(), v.end());
|
| 13917 |
+
|
| 13918 |
+
// explicitly sequential sort
|
| 13919 |
+
sort(execution::seq, v.begin(), v.end());
|
| 13920 |
+
|
| 13921 |
+
// permitting parallel execution
|
| 13922 |
+
sort(execution::par, v.begin(), v.end());
|
| 13923 |
+
|
| 13924 |
+
// permitting vectorization as well
|
| 13925 |
+
sort(execution::par_unseq, v.begin(), v.end());
|
| 13926 |
+
```
|
| 13927 |
+
|
| 13928 |
+
— *end example*]
|
| 13929 |
+
|
| 13930 |
+
[*Note 1*: Because different parallel architectures may require
|
| 13931 |
+
idiosyncratic parameters for efficient execution, implementations may
|
| 13932 |
+
provide additional execution policies to those described in this
|
| 13933 |
+
standard as extensions. — *end note*]
|
| 13934 |
+
|
| 13935 |
+
### Header `<execution>` synopsis <a id="execution.syn">[[execution.syn]]</a>
|
| 13936 |
+
|
| 13937 |
+
``` cpp
|
| 13938 |
+
namespace std {
|
| 13939 |
+
// [execpol.type], execution policy type trait
|
| 13940 |
+
template<class T> struct is_execution_policy;
|
| 13941 |
+
template<class T> inline constexpr bool is_execution_policy_v = is_execution_policy<T>::value;
|
| 13942 |
+
}
|
| 13943 |
+
|
| 13944 |
+
namespace std::execution {
|
| 13945 |
+
// [execpol.seq], sequenced execution policy
|
| 13946 |
+
class sequenced_policy;
|
| 13947 |
+
|
| 13948 |
+
// [execpol.par], parallel execution policy
|
| 13949 |
+
class parallel_policy;
|
| 13950 |
+
|
| 13951 |
+
// [execpol.parunseq], parallel and unsequenced execution policy
|
| 13952 |
+
class parallel_unsequenced_policy;
|
| 13953 |
+
|
| 13954 |
+
// [execpol.objects], execution policy objects
|
| 13955 |
+
inline constexpr sequenced_policy seq{ unspecified };
|
| 13956 |
+
inline constexpr parallel_policy par{ unspecified };
|
| 13957 |
+
inline constexpr parallel_unsequenced_policy par_unseq{ unspecified };
|
| 13958 |
+
}
|
| 13959 |
+
```
|
| 13960 |
+
|
| 13961 |
+
### Execution policy type trait <a id="execpol.type">[[execpol.type]]</a>
|
| 13962 |
+
|
| 13963 |
+
``` cpp
|
| 13964 |
+
template<class T> struct is_execution_policy { see below };
|
| 13965 |
+
```
|
| 13966 |
+
|
| 13967 |
+
`is_execution_policy` can be used to detect execution policies for the
|
| 13968 |
+
purpose of excluding function signatures from otherwise ambiguous
|
| 13969 |
+
overload resolution participation.
|
| 13970 |
+
|
| 13971 |
+
`is_execution_policy<T>` shall be a `UnaryTypeTrait` with a base
|
| 13972 |
+
characteristic of `true_type` if `T` is the type of a standard or
|
| 13973 |
+
*implementation-defined* execution policy, otherwise `false_type`.
|
| 13974 |
+
|
| 13975 |
+
[*Note 1*: This provision reserves the privilege of creating
|
| 13976 |
+
non-standard execution policies to the library
|
| 13977 |
+
implementation. — *end note*]
|
| 13978 |
+
|
| 13979 |
+
The behavior of a program that adds specializations for
|
| 13980 |
+
`is_execution_policy` is undefined.
|
| 13981 |
+
|
| 13982 |
+
### Sequenced execution policy <a id="execpol.seq">[[execpol.seq]]</a>
|
| 13983 |
+
|
| 13984 |
+
``` cpp
|
| 13985 |
+
class execution::sequenced_policy { unspecified };
|
| 13986 |
+
```
|
| 13987 |
+
|
| 13988 |
+
The class `execution::sequenced_policy` is an execution policy type used
|
| 13989 |
+
as a unique type to disambiguate parallel algorithm overloading and
|
| 13990 |
+
require that a parallel algorithm’s execution may not be parallelized.
|
| 13991 |
+
|
| 13992 |
+
During the execution of a parallel algorithm with the
|
| 13993 |
+
`execution::sequenced_policy` policy, if the invocation of an element
|
| 13994 |
+
access function exits via an uncaught exception, `terminate()` shall be
|
| 13995 |
+
called.
|
| 13996 |
+
|
| 13997 |
+
### Parallel execution policy <a id="execpol.par">[[execpol.par]]</a>
|
| 13998 |
+
|
| 13999 |
+
``` cpp
|
| 14000 |
+
class execution::parallel_policy { unspecified };
|
| 14001 |
+
```
|
| 14002 |
+
|
| 14003 |
+
The class `execution::parallel_policy` is an execution policy type used
|
| 14004 |
+
as a unique type to disambiguate parallel algorithm overloading and
|
| 14005 |
+
indicate that a parallel algorithm’s execution may be parallelized.
|
| 14006 |
+
|
| 14007 |
+
During the execution of a parallel algorithm with the
|
| 14008 |
+
`execution::parallel_policy` policy, if the invocation of an element
|
| 14009 |
+
access function exits via an uncaught exception, `terminate()` shall be
|
| 14010 |
+
called.
|
| 14011 |
+
|
| 14012 |
+
### Parallel and unsequenced execution policy <a id="execpol.parunseq">[[execpol.parunseq]]</a>
|
| 14013 |
+
|
| 14014 |
+
``` cpp
|
| 14015 |
+
class execution::parallel_unsequenced_policy { unspecified };
|
| 14016 |
+
```
|
| 14017 |
+
|
| 14018 |
+
The class `execution::parallel_unsequenced_policy` is an execution
|
| 14019 |
+
policy type used as a unique type to disambiguate parallel algorithm
|
| 14020 |
+
overloading and indicate that a parallel algorithm’s execution may be
|
| 14021 |
+
parallelized and vectorized.
|
| 14022 |
+
|
| 14023 |
+
During the execution of a parallel algorithm with the
|
| 14024 |
+
`execution::parallel_unsequenced_policy` policy, if the invocation of an
|
| 14025 |
+
element access function exits via an uncaught exception, `terminate()`
|
| 14026 |
+
shall be called.
|
| 14027 |
+
|
| 14028 |
+
### Execution policy objects <a id="execpol.objects">[[execpol.objects]]</a>
|
| 14029 |
+
|
| 14030 |
+
``` cpp
|
| 14031 |
+
inline constexpr execution::sequenced_policy execution::seq{ unspecified };
|
| 14032 |
+
inline constexpr execution::parallel_policy execution::par{ unspecified };
|
| 14033 |
+
inline constexpr execution::parallel_unsequenced_policy execution::par_unseq{ unspecified };
|
| 14034 |
+
```
|
| 14035 |
+
|
| 14036 |
+
The header `<execution>` declares global objects associated with each
|
| 14037 |
+
type of execution policy.
|
| 14038 |
|
| 14039 |
<!-- Link reference definitions -->
|
| 14040 |
[alg.sorting]: algorithms.md#alg.sorting
|
| 14041 |
[algorithms]: algorithms.md#algorithms
|
| 14042 |
+
[algorithms.general]: algorithms.md#algorithms.general
|
| 14043 |
[allocator.adaptor]: #allocator.adaptor
|
| 14044 |
[allocator.adaptor.cnstr]: #allocator.adaptor.cnstr
|
| 14045 |
[allocator.adaptor.members]: #allocator.adaptor.members
|
| 14046 |
[allocator.adaptor.syn]: #allocator.adaptor.syn
|
| 14047 |
[allocator.adaptor.types]: #allocator.adaptor.types
|
| 14048 |
[allocator.globals]: #allocator.globals
|
| 14049 |
[allocator.members]: #allocator.members
|
| 14050 |
[allocator.requirements]: library.md#allocator.requirements
|
| 14051 |
+
[allocator.requirements.completeness]: library.md#allocator.requirements.completeness
|
| 14052 |
[allocator.tag]: #allocator.tag
|
| 14053 |
[allocator.traits]: #allocator.traits
|
| 14054 |
[allocator.traits.members]: #allocator.traits.members
|
| 14055 |
[allocator.traits.types]: #allocator.traits.types
|
| 14056 |
[allocator.uses]: #allocator.uses
|
| 14057 |
[allocator.uses.construction]: #allocator.uses.construction
|
| 14058 |
[allocator.uses.trait]: #allocator.uses.trait
|
| 14059 |
+
[any]: #any
|
| 14060 |
+
[any.assign]: #any.assign
|
| 14061 |
+
[any.bad_any_cast]: #any.bad_any_cast
|
| 14062 |
+
[any.class]: #any.class
|
| 14063 |
+
[any.cons]: #any.cons
|
| 14064 |
+
[any.modifiers]: #any.modifiers
|
| 14065 |
+
[any.nonmembers]: #any.nonmembers
|
| 14066 |
+
[any.observers]: #any.observers
|
| 14067 |
+
[any.synop]: #any.synop
|
| 14068 |
[arithmetic.operations]: #arithmetic.operations
|
| 14069 |
+
[arithmetic.operations.divides]: #arithmetic.operations.divides
|
| 14070 |
+
[arithmetic.operations.minus]: #arithmetic.operations.minus
|
| 14071 |
+
[arithmetic.operations.modulus]: #arithmetic.operations.modulus
|
| 14072 |
+
[arithmetic.operations.multiplies]: #arithmetic.operations.multiplies
|
| 14073 |
+
[arithmetic.operations.negate]: #arithmetic.operations.negate
|
| 14074 |
+
[arithmetic.operations.plus]: #arithmetic.operations.plus
|
| 14075 |
[array]: containers.md#array
|
| 14076 |
[associative]: containers.md#associative
|
| 14077 |
[atomics.order]: atomics.md#atomics.order
|
| 14078 |
[atomics.types.operations]: atomics.md#atomics.types.operations
|
| 14079 |
[basic.align]: basic.md#basic.align
|
| 14080 |
[basic.compound]: basic.md#basic.compound
|
| 14081 |
[basic.def.odr]: basic.md#basic.def.odr
|
| 14082 |
[basic.fundamental]: basic.md#basic.fundamental
|
| 14083 |
[basic.life]: basic.md#basic.life
|
| 14084 |
+
[basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
|
| 14085 |
[basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
|
|
|
|
| 14086 |
[basic.types]: basic.md#basic.types
|
| 14087 |
+
[bitmask.types]: library.md#bitmask.types
|
| 14088 |
+
[bitset]: #bitset
|
| 14089 |
[bitset.cons]: #bitset.cons
|
| 14090 |
[bitset.hash]: #bitset.hash
|
| 14091 |
[bitset.members]: #bitset.members
|
| 14092 |
[bitset.operators]: #bitset.operators
|
| 14093 |
+
[bitset.syn]: #bitset.syn
|
| 14094 |
[bitwise.operations]: #bitwise.operations
|
| 14095 |
+
[bitwise.operations.and]: #bitwise.operations.and
|
| 14096 |
+
[bitwise.operations.not]: #bitwise.operations.not
|
| 14097 |
+
[bitwise.operations.or]: #bitwise.operations.or
|
| 14098 |
+
[bitwise.operations.xor]: #bitwise.operations.xor
|
| 14099 |
[c.malloc]: #c.malloc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14100 |
[comparisons]: #comparisons
|
| 14101 |
+
[comparisons.equal_to]: #comparisons.equal_to
|
| 14102 |
+
[comparisons.greater]: #comparisons.greater
|
| 14103 |
+
[comparisons.greater_equal]: #comparisons.greater_equal
|
| 14104 |
+
[comparisons.less]: #comparisons.less
|
| 14105 |
+
[comparisons.less_equal]: #comparisons.less_equal
|
| 14106 |
+
[comparisons.not_equal_to]: #comparisons.not_equal_to
|
| 14107 |
[conv.array]: conv.md#conv.array
|
| 14108 |
[conv.func]: conv.md#conv.func
|
| 14109 |
[conv.lval]: conv.md#conv.lval
|
| 14110 |
[conv.rank]: conv.md#conv.rank
|
| 14111 |
+
[csignal.syn]: language.md#csignal.syn
|
| 14112 |
+
[cstdlib.syn]: language.md#cstdlib.syn
|
| 14113 |
+
[ctime.syn]: #ctime.syn
|
| 14114 |
[dcl.array]: dcl.md#dcl.array
|
| 14115 |
+
[dcl.constexpr]: dcl.md#dcl.constexpr
|
| 14116 |
[dcl.ref]: dcl.md#dcl.ref
|
| 14117 |
[declval]: #declval
|
| 14118 |
[default.allocator]: #default.allocator
|
| 14119 |
+
[defns.const.subexpr]: library.md#defns.const.subexpr
|
| 14120 |
+
[defns.referenceable]: library.md#defns.referenceable
|
| 14121 |
+
[execpol]: #execpol
|
| 14122 |
+
[execpol.general]: #execpol.general
|
| 14123 |
+
[execpol.objects]: #execpol.objects
|
| 14124 |
+
[execpol.par]: #execpol.par
|
| 14125 |
+
[execpol.parunseq]: #execpol.parunseq
|
| 14126 |
+
[execpol.seq]: #execpol.seq
|
| 14127 |
+
[execpol.type]: #execpol.type
|
| 14128 |
+
[execution.syn]: #execution.syn
|
| 14129 |
[expr]: expr.md#expr
|
| 14130 |
[expr.add]: expr.md#expr.add
|
| 14131 |
[expr.alignof]: expr.md#expr.alignof
|
| 14132 |
[expr.bit.and]: expr.md#expr.bit.and
|
| 14133 |
[expr.call]: expr.md#expr.call
|
|
|
|
| 14135 |
[expr.log.and]: expr.md#expr.log.and
|
| 14136 |
[expr.log.or]: expr.md#expr.log.or
|
| 14137 |
[expr.mul]: expr.md#expr.mul
|
| 14138 |
[expr.or]: expr.md#expr.or
|
| 14139 |
[expr.rel]: expr.md#expr.rel
|
|
|
|
| 14140 |
[expr.unary.op]: expr.md#expr.unary.op
|
| 14141 |
[expr.xor]: expr.md#expr.xor
|
| 14142 |
[forward]: #forward
|
| 14143 |
[forward.iterators]: iterators.md#forward.iterators
|
| 14144 |
[func.bind]: #func.bind
|
| 14145 |
[func.bind.bind]: #func.bind.bind
|
| 14146 |
[func.bind.isbind]: #func.bind.isbind
|
| 14147 |
[func.bind.isplace]: #func.bind.isplace
|
| 14148 |
[func.bind.place]: #func.bind.place
|
| 14149 |
[func.def]: #func.def
|
| 14150 |
+
[func.invoke]: #func.invoke
|
| 14151 |
[func.memfn]: #func.memfn
|
| 14152 |
+
[func.not_fn]: #func.not_fn
|
| 14153 |
[func.require]: #func.require
|
| 14154 |
+
[func.search]: #func.search
|
| 14155 |
+
[func.search.bm]: #func.search.bm
|
| 14156 |
+
[func.search.bmh]: #func.search.bmh
|
| 14157 |
+
[func.search.default]: #func.search.default
|
| 14158 |
[func.wrap]: #func.wrap
|
| 14159 |
[func.wrap.badcall]: #func.wrap.badcall
|
| 14160 |
[func.wrap.badcall.const]: #func.wrap.badcall.const
|
| 14161 |
[func.wrap.func]: #func.wrap.func
|
| 14162 |
[func.wrap.func.alg]: #func.wrap.func.alg
|
|
|
|
| 14165 |
[func.wrap.func.inv]: #func.wrap.func.inv
|
| 14166 |
[func.wrap.func.mod]: #func.wrap.func.mod
|
| 14167 |
[func.wrap.func.nullptr]: #func.wrap.func.nullptr
|
| 14168 |
[func.wrap.func.targ]: #func.wrap.func.targ
|
| 14169 |
[function.objects]: #function.objects
|
| 14170 |
+
[functional.syn]: #functional.syn
|
| 14171 |
[hash.requirements]: library.md#hash.requirements
|
| 14172 |
[input.iterators]: iterators.md#input.iterators
|
| 14173 |
[intro.multithread]: intro.md#intro.multithread
|
| 14174 |
[intseq]: #intseq
|
| 14175 |
[intseq.general]: #intseq.general
|
| 14176 |
[intseq.intseq]: #intseq.intseq
|
| 14177 |
[intseq.make]: #intseq.make
|
| 14178 |
[invalid.argument]: diagnostics.md#invalid.argument
|
| 14179 |
[iostate.flags]: input.md#iostate.flags
|
| 14180 |
[istream.formatted]: input.md#istream.formatted
|
| 14181 |
+
[locale.codecvt]: localization.md#locale.codecvt
|
| 14182 |
[logical.operations]: #logical.operations
|
| 14183 |
+
[logical.operations.and]: #logical.operations.and
|
| 14184 |
+
[logical.operations.not]: #logical.operations.not
|
| 14185 |
+
[logical.operations.or]: #logical.operations.or
|
| 14186 |
+
[mem.poly.allocator.class]: #mem.poly.allocator.class
|
| 14187 |
+
[mem.poly.allocator.ctor]: #mem.poly.allocator.ctor
|
| 14188 |
+
[mem.poly.allocator.eq]: #mem.poly.allocator.eq
|
| 14189 |
+
[mem.poly.allocator.mem]: #mem.poly.allocator.mem
|
| 14190 |
+
[mem.res]: #mem.res
|
| 14191 |
+
[mem.res.class]: #mem.res.class
|
| 14192 |
+
[mem.res.eq]: #mem.res.eq
|
| 14193 |
+
[mem.res.global]: #mem.res.global
|
| 14194 |
+
[mem.res.monotonic.buffer]: #mem.res.monotonic.buffer
|
| 14195 |
+
[mem.res.monotonic.buffer.ctor]: #mem.res.monotonic.buffer.ctor
|
| 14196 |
+
[mem.res.monotonic.buffer.mem]: #mem.res.monotonic.buffer.mem
|
| 14197 |
+
[mem.res.pool]: #mem.res.pool
|
| 14198 |
+
[mem.res.pool.ctor]: #mem.res.pool.ctor
|
| 14199 |
+
[mem.res.pool.mem]: #mem.res.pool.mem
|
| 14200 |
+
[mem.res.pool.options]: #mem.res.pool.options
|
| 14201 |
+
[mem.res.pool.overview]: #mem.res.pool.overview
|
| 14202 |
+
[mem.res.private]: #mem.res.private
|
| 14203 |
+
[mem.res.public]: #mem.res.public
|
| 14204 |
+
[mem.res.syn]: #mem.res.syn
|
| 14205 |
[memory]: #memory
|
| 14206 |
[memory.general]: #memory.general
|
| 14207 |
[memory.syn]: #memory.syn
|
| 14208 |
[meta]: #meta
|
| 14209 |
[meta.help]: #meta.help
|
| 14210 |
+
[meta.logical]: #meta.logical
|
| 14211 |
[meta.rel]: #meta.rel
|
| 14212 |
[meta.rqmts]: #meta.rqmts
|
| 14213 |
[meta.trans]: #meta.trans
|
| 14214 |
[meta.trans.arr]: #meta.trans.arr
|
| 14215 |
[meta.trans.cv]: #meta.trans.cv
|
|
|
|
| 14221 |
[meta.unary]: #meta.unary
|
| 14222 |
[meta.unary.cat]: #meta.unary.cat
|
| 14223 |
[meta.unary.comp]: #meta.unary.comp
|
| 14224 |
[meta.unary.prop]: #meta.unary.prop
|
| 14225 |
[meta.unary.prop.query]: #meta.unary.prop.query
|
| 14226 |
+
[multibyte.strings]: library.md#multibyte.strings
|
| 14227 |
+
[namespace.std]: library.md#namespace.std
|
|
|
|
| 14228 |
[new.delete]: language.md#new.delete
|
| 14229 |
[nullablepointer.requirements]: library.md#nullablepointer.requirements
|
| 14230 |
[numeric.requirements]: numerics.md#numeric.requirements
|
| 14231 |
[operators]: #operators
|
| 14232 |
+
[optional]: #optional
|
| 14233 |
+
[optional.assign]: #optional.assign
|
| 14234 |
+
[optional.bad.access]: #optional.bad.access
|
| 14235 |
+
[optional.comp_with_t]: #optional.comp_with_t
|
| 14236 |
+
[optional.ctor]: #optional.ctor
|
| 14237 |
+
[optional.dtor]: #optional.dtor
|
| 14238 |
+
[optional.general]: #optional.general
|
| 14239 |
+
[optional.hash]: #optional.hash
|
| 14240 |
+
[optional.mod]: #optional.mod
|
| 14241 |
+
[optional.nullops]: #optional.nullops
|
| 14242 |
+
[optional.nullopt]: #optional.nullopt
|
| 14243 |
+
[optional.observe]: #optional.observe
|
| 14244 |
+
[optional.optional]: #optional.optional
|
| 14245 |
+
[optional.relops]: #optional.relops
|
| 14246 |
+
[optional.specalg]: #optional.specalg
|
| 14247 |
+
[optional.swap]: #optional.swap
|
| 14248 |
+
[optional.syn]: #optional.syn
|
| 14249 |
[ostream.formatted]: input.md#ostream.formatted
|
| 14250 |
[out.of.range]: diagnostics.md#out.of.range
|
|
|
|
| 14251 |
[over.match.call]: over.md#over.match.call
|
| 14252 |
+
[over.match.class.deduct]: over.md#over.match.class.deduct
|
| 14253 |
[overflow.error]: diagnostics.md#overflow.error
|
| 14254 |
[pair.astuple]: #pair.astuple
|
| 14255 |
[pair.piecewise]: #pair.piecewise
|
| 14256 |
[pairs]: #pairs
|
| 14257 |
[pairs.general]: #pairs.general
|
|
|
|
| 14278 |
[scoped.adaptor.operators]: #scoped.adaptor.operators
|
| 14279 |
[smartptr]: #smartptr
|
| 14280 |
[special]: special.md#special
|
| 14281 |
[specialized.addressof]: #specialized.addressof
|
| 14282 |
[specialized.algorithms]: #specialized.algorithms
|
| 14283 |
+
[specialized.destroy]: #specialized.destroy
|
| 14284 |
[stmt.dcl]: stmt.md#stmt.dcl
|
| 14285 |
+
[string.classes]: strings.md#string.classes
|
| 14286 |
[support.dynamic]: language.md#support.dynamic
|
| 14287 |
[swappable.requirements]: library.md#swappable.requirements
|
| 14288 |
+
[tab:copyassignable]: #tab:copyassignable
|
| 14289 |
+
[tab:copyconstructible]: #tab:copyconstructible
|
| 14290 |
+
[tab:defaultconstructible]: #tab:defaultconstructible
|
| 14291 |
+
[tab:destructible]: #tab:destructible
|
| 14292 |
+
[tab:equalitycomparable]: #tab:equalitycomparable
|
| 14293 |
+
[tab:lessthancomparable]: #tab:lessthancomparable
|
| 14294 |
+
[tab:moveassignable]: #tab:moveassignable
|
| 14295 |
+
[tab:moveconstructible]: #tab:moveconstructible
|
| 14296 |
+
[tab:optional.assign.copy]: #tab:optional.assign.copy
|
| 14297 |
+
[tab:optional.assign.copy.templ]: #tab:optional.assign.copy.templ
|
| 14298 |
+
[tab:optional.assign.move]: #tab:optional.assign.move
|
| 14299 |
+
[tab:optional.assign.move.templ]: #tab:optional.assign.move.templ
|
| 14300 |
+
[tab:optional.swap]: #tab:optional.swap
|
| 14301 |
[tab:ratio.arithmetic]: #tab:ratio.arithmetic
|
| 14302 |
[tab:time.clock]: #tab:time.clock
|
|
|
|
|
|
|
|
|
|
| 14303 |
[tab:util.lib.summary]: #tab:util.lib.summary
|
| 14304 |
+
[temp.deduct]: temp.md#temp.deduct
|
| 14305 |
[template.bitset]: #template.bitset
|
|
|
|
| 14306 |
[time]: #time
|
| 14307 |
[time.clock]: #time.clock
|
| 14308 |
[time.clock.hires]: #time.clock.hires
|
| 14309 |
[time.clock.req]: #time.clock.req
|
| 14310 |
[time.clock.steady]: #time.clock.steady
|
| 14311 |
[time.clock.system]: #time.clock.system
|
| 14312 |
[time.duration]: #time.duration
|
| 14313 |
+
[time.duration.alg]: #time.duration.alg
|
| 14314 |
[time.duration.arithmetic]: #time.duration.arithmetic
|
| 14315 |
[time.duration.cast]: #time.duration.cast
|
| 14316 |
[time.duration.comparisons]: #time.duration.comparisons
|
| 14317 |
[time.duration.cons]: #time.duration.cons
|
| 14318 |
[time.duration.literals]: #time.duration.literals
|
|
|
|
| 14332 |
[time.traits]: #time.traits
|
| 14333 |
[time.traits.duration_values]: #time.traits.duration_values
|
| 14334 |
[time.traits.is_fp]: #time.traits.is_fp
|
| 14335 |
[time.traits.specializations]: #time.traits.specializations
|
| 14336 |
[tuple]: #tuple
|
| 14337 |
+
[tuple.apply]: #tuple.apply
|
| 14338 |
[tuple.assign]: #tuple.assign
|
| 14339 |
[tuple.cnstr]: #tuple.cnstr
|
| 14340 |
[tuple.creation]: #tuple.creation
|
| 14341 |
[tuple.elem]: #tuple.elem
|
| 14342 |
[tuple.general]: #tuple.general
|
| 14343 |
[tuple.helper]: #tuple.helper
|
| 14344 |
[tuple.rel]: #tuple.rel
|
| 14345 |
[tuple.special]: #tuple.special
|
| 14346 |
[tuple.swap]: #tuple.swap
|
| 14347 |
+
[tuple.syn]: #tuple.syn
|
| 14348 |
[tuple.traits]: #tuple.traits
|
| 14349 |
[tuple.tuple]: #tuple.tuple
|
| 14350 |
[type.index]: #type.index
|
| 14351 |
[type.index.hash]: #type.index.hash
|
| 14352 |
[type.index.members]: #type.index.members
|
| 14353 |
[type.index.overview]: #type.index.overview
|
| 14354 |
[type.index.synopsis]: #type.index.synopsis
|
| 14355 |
+
[uninitialized.construct.default]: #uninitialized.construct.default
|
| 14356 |
+
[uninitialized.construct.value]: #uninitialized.construct.value
|
| 14357 |
[uninitialized.copy]: #uninitialized.copy
|
| 14358 |
[uninitialized.fill]: #uninitialized.fill
|
| 14359 |
+
[uninitialized.move]: #uninitialized.move
|
| 14360 |
[unique.ptr]: #unique.ptr
|
| 14361 |
[unique.ptr.create]: #unique.ptr.create
|
| 14362 |
[unique.ptr.dltr]: #unique.ptr.dltr
|
| 14363 |
[unique.ptr.dltr.dflt]: #unique.ptr.dltr.dflt
|
| 14364 |
[unique.ptr.dltr.dflt1]: #unique.ptr.dltr.dflt1
|
| 14365 |
[unique.ptr.dltr.general]: #unique.ptr.dltr.general
|
| 14366 |
[unique.ptr.runtime]: #unique.ptr.runtime
|
| 14367 |
+
[unique.ptr.runtime.asgn]: #unique.ptr.runtime.asgn
|
| 14368 |
[unique.ptr.runtime.ctor]: #unique.ptr.runtime.ctor
|
| 14369 |
[unique.ptr.runtime.modifiers]: #unique.ptr.runtime.modifiers
|
| 14370 |
[unique.ptr.runtime.observers]: #unique.ptr.runtime.observers
|
| 14371 |
[unique.ptr.single]: #unique.ptr.single
|
| 14372 |
[unique.ptr.single.asgn]: #unique.ptr.single.asgn
|
|
|
|
| 14395 |
[util.smartptr.shared.mod]: #util.smartptr.shared.mod
|
| 14396 |
[util.smartptr.shared.obs]: #util.smartptr.shared.obs
|
| 14397 |
[util.smartptr.shared.spec]: #util.smartptr.shared.spec
|
| 14398 |
[util.smartptr.weak]: #util.smartptr.weak
|
| 14399 |
[util.smartptr.weak.assign]: #util.smartptr.weak.assign
|
| 14400 |
+
[util.smartptr.weak.bad]: #util.smartptr.weak.bad
|
| 14401 |
[util.smartptr.weak.const]: #util.smartptr.weak.const
|
| 14402 |
[util.smartptr.weak.dest]: #util.smartptr.weak.dest
|
| 14403 |
[util.smartptr.weak.mod]: #util.smartptr.weak.mod
|
| 14404 |
[util.smartptr.weak.obs]: #util.smartptr.weak.obs
|
| 14405 |
[util.smartptr.weak.spec]: #util.smartptr.weak.spec
|
|
|
|
| 14406 |
[utilities]: #utilities
|
| 14407 |
[utilities.general]: #utilities.general
|
| 14408 |
[utility]: #utility
|
| 14409 |
+
[utility.as_const]: #utility.as_const
|
| 14410 |
[utility.exchange]: #utility.exchange
|
| 14411 |
+
[utility.from.chars]: #utility.from.chars
|
| 14412 |
[utility.swap]: #utility.swap
|
| 14413 |
+
[utility.syn]: #utility.syn
|
| 14414 |
+
[utility.to.chars]: #utility.to.chars
|
| 14415 |
+
[variant]: #variant
|
| 14416 |
+
[variant.assign]: #variant.assign
|
| 14417 |
+
[variant.bad.access]: #variant.bad.access
|
| 14418 |
+
[variant.ctor]: #variant.ctor
|
| 14419 |
+
[variant.dtor]: #variant.dtor
|
| 14420 |
+
[variant.general]: #variant.general
|
| 14421 |
+
[variant.get]: #variant.get
|
| 14422 |
+
[variant.hash]: #variant.hash
|
| 14423 |
+
[variant.helper]: #variant.helper
|
| 14424 |
+
[variant.mod]: #variant.mod
|
| 14425 |
+
[variant.monostate]: #variant.monostate
|
| 14426 |
+
[variant.monostate.relops]: #variant.monostate.relops
|
| 14427 |
+
[variant.relops]: #variant.relops
|
| 14428 |
+
[variant.specalg]: #variant.specalg
|
| 14429 |
+
[variant.status]: #variant.status
|
| 14430 |
+
[variant.swap]: #variant.swap
|
| 14431 |
+
[variant.syn]: #variant.syn
|
| 14432 |
+
[variant.traits]: #variant.traits
|
| 14433 |
+
[variant.variant]: #variant.variant
|
| 14434 |
+
[variant.visit]: #variant.visit
|
| 14435 |
|
| 14436 |
[^1]: `pointer_safety::preferred` might be returned to indicate that a
|
| 14437 |
leak detector is running so that the program can avoid spurious leak
|
| 14438 |
reports.
|
| 14439 |
|