- tmp/tmpty587mae/{from.md → to.md} +5797 -5298
tmp/tmpty587mae/{from.md → to.md}
RENAMED
|
@@ -1,68 +1,60 @@
|
|
| 1 |
# General utilities library <a id="utilities">[[utilities]]</a>
|
| 2 |
|
| 3 |
## General <a id="utilities.general">[[utilities.general]]</a>
|
| 4 |
|
| 5 |
-
This Clause describes utilities that are generally useful in
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
[[
|
| 9 |
|
| 10 |
-
**Table: General utilities library summary** <a id="
|
| 11 |
|
| 12 |
| Subclause | | Header |
|
| 13 |
-
| --------------------- | -------------------------------- | -------------------- |
|
| 14 |
| [[utility]] | Utility components | `<utility>` |
|
| 15 |
-
| [[intseq]] | Compile-time integer sequences |
|
| 16 |
-
| [[pairs]] | Pairs |
|
| 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 <
|
|
|
|
| 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>
|
|
@@ -72,22 +64,42 @@ namespace std {
|
|
| 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.
|
| 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 |
|
|
@@ -105,33 +117,26 @@ namespace std {
|
|
| 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
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
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
|
| 128 |
-
template
|
| 129 |
|
| 130 |
template<class T1, class T2> struct tuple_size<pair<T1, T2>>;
|
| 131 |
-
template
|
| 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;
|
|
@@ -159,178 +164,79 @@ namespace std {
|
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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:
|
| 251 |
-
|
| 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 |
-
*
|
| 301 |
-
|
| 302 |
-
`is_move_assignable_v<T>` is `true`. The expression inside `noexcept` is
|
| 303 |
-
equivalent to:
|
| 304 |
|
| 305 |
-
``
|
| 306 |
-
|
| 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 |
-
*
|
| 321 |
-
unless `is_swappable_v<T>` is `true`.
|
| 322 |
|
| 323 |
-
*
|
| 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
|
|
|
|
| 332 |
```
|
| 333 |
|
| 334 |
*Effects:* Equivalent to:
|
| 335 |
|
| 336 |
``` cpp
|
|
@@ -342,22 +248,22 @@ return old_val;
|
|
| 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
|
| 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) {
|
|
@@ -425,30 +331,29 @@ template <class T> constexpr conditional_t<
|
|
| 425 |
move_if_noexcept(T& x) noexcept;
|
| 426 |
```
|
| 427 |
|
| 428 |
*Returns:* `std::move(x)`.
|
| 429 |
|
| 430 |
-
### Function template `as_const` <a id="utility.
|
| 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
|
| 442 |
-
[[expr]]
|
| 443 |
|
| 444 |
``` cpp
|
| 445 |
template<class T> add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
| 446 |
```
|
| 447 |
|
| 448 |
-
*
|
| 449 |
-
program is ill-formed.
|
| 450 |
|
| 451 |
*Remarks:* The template parameter `T` of `declval` may be an incomplete
|
| 452 |
type.
|
| 453 |
|
| 454 |
[*Example 1*:
|
|
@@ -457,214 +362,148 @@ type.
|
|
| 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 |
-
###
|
| 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 |
-
|
|
|
|
| 497 |
```
|
| 498 |
|
| 499 |
-
*
|
|
|
|
| 500 |
|
| 501 |
-
*Effects:*
|
| 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 |
-
|
| 513 |
-
|
| 514 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 526 |
-
|
| 527 |
-
to_chars_result to_chars(char* first, char* last, long double value, chars_format fmt);
|
| 528 |
```
|
| 529 |
|
| 530 |
-
*
|
| 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 |
-
|
| 540 |
-
|
| 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 |
-
*
|
| 548 |
-
|
| 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 |
-
|
| 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 |
-
|
| 575 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 576 |
```
|
| 577 |
|
| 578 |
-
|
|
|
|
|
|
|
|
|
|
| 579 |
|
| 580 |
-
*Effects:*
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 587 |
|
| 588 |
-
*
|
| 589 |
-
unsigned integer types and `char` as the referenced type of the
|
| 590 |
-
parameter `value`.
|
| 591 |
|
| 592 |
``` cpp
|
| 593 |
-
|
| 594 |
-
|
| 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 |
-
*
|
| 602 |
-
`chars_format`.
|
| 603 |
|
| 604 |
-
|
| 605 |
-
|
|
|
|
|
|
|
| 606 |
|
| 607 |
-
|
| 608 |
-
|
| 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 |
-
|
| 619 |
-
values closest to the value of the string matching the pattern.
|
| 620 |
|
| 621 |
-
|
|
|
|
|
|
|
|
|
|
| 622 |
|
| 623 |
-
|
|
|
|
|
|
|
| 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
|
| 631 |
-
pack defining the sequence can be deduced and used in a pack
|
|
|
|
| 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`
|
| 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 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
`
|
|
|
|
| 662 |
`integer_sequence<T, 0, 1, ..., N-1>`.
|
| 663 |
|
| 664 |
-
[*Note 1*: `make_integer_sequence<int, 0>`
|
| 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 |
|
|
@@ -686,122 +525,157 @@ namespace std {
|
|
| 686 |
T1 first;
|
| 687 |
T2 second;
|
| 688 |
|
| 689 |
pair(const pair&) = default;
|
| 690 |
pair(pair&&) = default;
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
|
|
|
|
|
|
|
|
|
| 696 |
template<class... Args1, class... Args2>
|
| 697 |
-
|
|
|
|
| 698 |
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
pair& operator=(pair&
|
| 702 |
-
|
|
|
|
|
|
|
| 703 |
|
| 704 |
-
|
| 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`
|
| 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`
|
| 717 |
-
|
| 718 |
-
initializations for
|
| 719 |
-
requirements for a constexpr function.
|
| 720 |
-
|
|
|
|
| 721 |
`(is_trivially_destructible_v<T1> && is_trivially_destructible_v<T2>)`
|
| 722 |
-
is `true`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 723 |
|
| 724 |
``` cpp
|
| 725 |
-
|
| 726 |
```
|
| 727 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 728 |
*Effects:* Value-initializes `first` and `second`.
|
| 729 |
|
| 730 |
-
*Remarks:*
|
| 731 |
-
|
| 732 |
-
|
| 733 |
|
| 734 |
-
[*Note 1*: This behavior can be implemented
|
| 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 |
-
|
| 746 |
```
|
| 747 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 748 |
*Effects:* Initializes `first` with `x` and `second` with `y`.
|
| 749 |
|
| 750 |
-
*Remarks:*
|
| 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 |
-
|
|
|
|
| 759 |
```
|
| 760 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 761 |
*Effects:* Initializes `first` with `std::forward<U1>(x)` and `second`
|
| 762 |
with `std::forward<U2>(y)`.
|
| 763 |
|
| 764 |
-
*Remarks:*
|
| 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 |
-
|
| 772 |
```
|
| 773 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 774 |
*Effects:* Initializes members from the corresponding members of the
|
| 775 |
argument.
|
| 776 |
|
| 777 |
-
*Remarks:*
|
| 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 |
-
|
| 785 |
```
|
| 786 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 787 |
*Effects:* Initializes `first` with `std::forward<U1>(p.first)` and
|
| 788 |
`second` with `std::forward<U2>(p.second)`.
|
| 789 |
|
| 790 |
-
*Remarks:*
|
| 791 |
-
|
| 792 |
-
`
|
| 793 |
-
|
| 794 |
-
|
| 795 |
|
| 796 |
``` cpp
|
| 797 |
template<class... Args1, class... Args2>
|
| 798 |
-
pair(piecewise_construct_t,
|
|
|
|
| 799 |
```
|
| 800 |
|
| 801 |
-
*
|
| 802 |
-
|
|
|
|
|
|
|
| 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`
|
|
@@ -809,74 +683,76 @@ 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
|
| 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 |
-
*
|
| 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 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 862 |
`second` with
|
| 863 |
-
`std::forward<
|
| 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 |
-
*
|
| 876 |
-
|
| 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 |
|
|
@@ -893,65 +769,44 @@ template <class T1, class T2>
|
|
| 893 |
|
| 894 |
*Returns:* `x.first == y.first && x.second == y.second`.
|
| 895 |
|
| 896 |
``` cpp
|
| 897 |
template<class T1, class T2>
|
| 898 |
-
constexpr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 899 |
```
|
| 900 |
|
| 901 |
*Returns:*
|
| 902 |
-
`x.first < y.first || (!(y.first < x.first) && x.second < y.second)`.
|
| 903 |
|
| 904 |
``` cpp
|
| 905 |
-
|
| 906 |
-
|
| 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
|
|
@@ -972,20 +827,19 @@ a C++program may contain:
|
|
| 972 |
template<class T1, class T2>
|
| 973 |
struct tuple_size<pair<T1, T2>> : integral_constant<size_t, 2> { };
|
| 974 |
```
|
| 975 |
|
| 976 |
``` cpp
|
| 977 |
-
|
|
|
|
|
|
|
|
|
|
| 978 |
```
|
| 979 |
|
| 980 |
-
*
|
| 981 |
|
| 982 |
-
```
|
| 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>
|
|
@@ -994,12 +848,16 @@ 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 |
-
*
|
| 1000 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1001 |
|
| 1002 |
``` cpp
|
| 1003 |
template<class T1, class T2>
|
| 1004 |
constexpr T1& get(pair<T1, T2>& p) noexcept;
|
| 1005 |
template<class T1, class T2>
|
|
@@ -1008,12 +866,11 @@ 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 |
-
*
|
| 1014 |
-
ill-formed.
|
| 1015 |
|
| 1016 |
*Returns:* A reference to `p.first`.
|
| 1017 |
|
| 1018 |
``` cpp
|
| 1019 |
template<class T2, class T1>
|
|
@@ -1024,12 +881,11 @@ 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 |
-
*
|
| 1030 |
-
ill-formed.
|
| 1031 |
|
| 1032 |
*Returns:* A reference to `p.second`.
|
| 1033 |
|
| 1034 |
### Piecewise construction <a id="pair.piecewise">[[pair.piecewise]]</a>
|
| 1035 |
|
|
@@ -1038,42 +894,44 @@ 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
|
| 1044 |
-
|
| 1045 |
Specifically, `pair` has a constructor with `piecewise_construct_t` as
|
| 1046 |
-
the first argument, immediately followed by two `tuple`
|
| 1047 |
arguments used for piecewise construction of the elements of the `pair`
|
| 1048 |
object.
|
| 1049 |
|
| 1050 |
## Tuples <a id="tuple">[[tuple]]</a>
|
| 1051 |
|
| 1052 |
### In general <a id="tuple.general">[[tuple.general]]</a>
|
| 1053 |
|
| 1054 |
-
|
| 1055 |
-
the class template `tuple` that can be instantiated with any
|
| 1056 |
-
arguments. Each template argument specifies the type of an
|
| 1057 |
-
the `tuple`. Consequently, tuples are heterogeneous,
|
| 1058 |
-
collections of values. An instantiation of `tuple` with two
|
| 1059 |
-
similar to an instantiation of `pair` with the same two
|
| 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<
|
| 1075 |
|
| 1076 |
template<class... TTypes>
|
| 1077 |
constexpr tuple<TTypes&&...> forward_as_tuple(TTypes&&...) noexcept;
|
| 1078 |
|
| 1079 |
template<class... TTypes>
|
|
@@ -1088,24 +946,20 @@ namespace std {
|
|
| 1088 |
|
| 1089 |
template<class T, class Tuple>
|
| 1090 |
constexpr T make_from_tuple(Tuple&& t);
|
| 1091 |
|
| 1092 |
// [tuple.helper], tuple helper classes
|
| 1093 |
-
template
|
| 1094 |
-
template
|
| 1095 |
-
template <class T> class tuple_size<volatile T>;
|
| 1096 |
-
template <class T> class tuple_size<const volatile T>;
|
| 1097 |
|
| 1098 |
-
template
|
| 1099 |
|
| 1100 |
-
template
|
| 1101 |
-
template
|
| 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 |
-
|
| 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
|
|
@@ -1128,27 +982,20 @@ namespace std {
|
|
| 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
|
| 1134 |
-
|
| 1135 |
-
constexpr bool operator!=(const tuple<TTypes...>&, const tuple<UTypes...>&);
|
| 1136 |
-
template<class... TTypes, class... UTypes>
|
| 1137 |
-
constexpr bool operator>(const tuple<TTypes...>&, const tuple<UTypes...>&);
|
| 1138 |
-
template<class... TTypes, class... UTypes>
|
| 1139 |
-
constexpr bool operator<=(const tuple<TTypes...>&, const tuple<UTypes...>&);
|
| 1140 |
-
template<class... TTypes, class... UTypes>
|
| 1141 |
-
constexpr bool operator>=(const tuple<TTypes...>&, const tuple<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 |
}
|
|
@@ -1160,64 +1007,71 @@ namespace std {
|
|
| 1160 |
namespace std {
|
| 1161 |
template<class... Types>
|
| 1162 |
class tuple {
|
| 1163 |
public:
|
| 1164 |
// [tuple.cnstr], tuple construction
|
| 1165 |
-
|
| 1166 |
-
|
| 1167 |
template<class... UTypes>
|
| 1168 |
-
|
| 1169 |
|
| 1170 |
tuple(const tuple&) = default;
|
| 1171 |
tuple(tuple&&) = default;
|
| 1172 |
|
| 1173 |
template<class... UTypes>
|
| 1174 |
-
|
| 1175 |
template<class... UTypes>
|
| 1176 |
-
|
| 1177 |
|
| 1178 |
template<class U1, class U2>
|
| 1179 |
-
|
| 1180 |
template<class U1, class U2>
|
| 1181 |
-
|
| 1182 |
|
| 1183 |
// allocator-extended constructors
|
| 1184 |
template<class Alloc>
|
|
|
|
| 1185 |
tuple(allocator_arg_t, const Alloc& a);
|
| 1186 |
template<class Alloc>
|
| 1187 |
-
|
|
|
|
| 1188 |
template<class Alloc, class... UTypes>
|
| 1189 |
-
|
|
|
|
| 1190 |
template<class Alloc>
|
| 1191 |
-
|
| 1192 |
template<class Alloc>
|
| 1193 |
-
|
| 1194 |
template<class Alloc, class... UTypes>
|
| 1195 |
-
|
|
|
|
| 1196 |
template<class Alloc, class... UTypes>
|
| 1197 |
-
|
|
|
|
| 1198 |
template<class Alloc, class U1, class U2>
|
| 1199 |
-
|
|
|
|
| 1200 |
template<class Alloc, class U1, class U2>
|
| 1201 |
-
|
|
|
|
| 1202 |
|
| 1203 |
// [tuple.assign], tuple assignment
|
| 1204 |
-
|
| 1205 |
-
|
| 1206 |
|
| 1207 |
template<class... UTypes>
|
| 1208 |
-
|
| 1209 |
template<class... UTypes>
|
| 1210 |
-
|
| 1211 |
|
| 1212 |
template<class U1, class U2>
|
| 1213 |
-
|
| 1214 |
template<class U1, class U2>
|
| 1215 |
-
|
| 1216 |
|
| 1217 |
// [tuple.swap], tuple swap
|
| 1218 |
-
|
| 1219 |
};
|
| 1220 |
|
| 1221 |
template<class... UTypes>
|
| 1222 |
tuple(UTypes...) -> tuple<UTypes...>;
|
| 1223 |
template<class T1, class T2>
|
|
@@ -1231,186 +1085,211 @@ namespace std {
|
|
| 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`
|
| 1240 |
-
|
| 1241 |
-
initializations for
|
| 1242 |
requirements for a constexpr function. The defaulted move and copy
|
| 1243 |
-
constructor of `tuple<>`
|
| 1244 |
|
| 1245 |
-
|
| 1246 |
-
|
| 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 |
-
|
| 1255 |
```
|
| 1256 |
|
|
|
|
|
|
|
| 1257 |
*Effects:* Value-initializes each element.
|
| 1258 |
|
| 1259 |
-
*Remarks:*
|
| 1260 |
-
|
|
|
|
| 1261 |
|
| 1262 |
-
[*Note 1*: This behavior can be implemented
|
| 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 |
-
|
| 1273 |
```
|
| 1274 |
|
|
|
|
|
|
|
|
|
|
| 1275 |
*Effects:* Initializes each element with the value of the corresponding
|
| 1276 |
parameter.
|
| 1277 |
|
| 1278 |
-
*Remarks:*
|
| 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 |
-
|
| 1285 |
```
|
| 1286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1287 |
*Effects:* Initializes the elements in the tuple with the corresponding
|
| 1288 |
value in `std::forward<UTypes>(u)`.
|
| 1289 |
|
| 1290 |
-
*Remarks:*
|
| 1291 |
-
|
| 1292 |
-
`
|
| 1293 |
-
|
| 1294 |
-
`
|
| 1295 |
|
| 1296 |
``` cpp
|
| 1297 |
tuple(const tuple& u) = default;
|
| 1298 |
```
|
| 1299 |
|
| 1300 |
-
*
|
| 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 |
-
*
|
| 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
|
| 1316 |
```
|
| 1317 |
|
| 1318 |
-
*
|
| 1319 |
-
element of `u`.
|
| 1320 |
|
| 1321 |
-
|
| 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)
|
| 1327 |
-
`UTypes...` expands to `U`)
|
| 1328 |
-
`
|
| 1329 |
-
|
|
|
|
| 1330 |
|
| 1331 |
-
|
| 1332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1333 |
|
| 1334 |
``` cpp
|
| 1335 |
-
template
|
| 1336 |
```
|
| 1337 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1338 |
*Effects:* For all i, initializes the iᵗʰ element of `*this` with
|
| 1339 |
`std::forward<``Uᵢ``>(get<`i`>(u))`.
|
| 1340 |
|
| 1341 |
-
*Remarks:*
|
| 1342 |
-
unless
|
| 1343 |
|
| 1344 |
-
|
| 1345 |
-
|
| 1346 |
-
|
| 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
|
| 1356 |
```
|
| 1357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1358 |
*Effects:* Initializes the first element with `u.first` and the second
|
| 1359 |
element with `u.second`.
|
| 1360 |
|
| 1361 |
-
|
| 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 |
-
|
| 1366 |
-
|
| 1367 |
-
`
|
| 1368 |
|
| 1369 |
``` cpp
|
| 1370 |
-
template
|
| 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 |
-
|
| 1378 |
-
unless `sizeof...(Types) == 2`, `is_constructible_v<``T₀``, U1&&>` is
|
| 1379 |
-
`true` and `is_constructible_v<``T₁``, U2&&>` is `true`.
|
| 1380 |
|
| 1381 |
-
|
| 1382 |
-
|
| 1383 |
-
`
|
| 1384 |
|
| 1385 |
``` cpp
|
| 1386 |
template<class Alloc>
|
|
|
|
| 1387 |
tuple(allocator_arg_t, const Alloc& a);
|
| 1388 |
template<class Alloc>
|
| 1389 |
-
|
|
|
|
| 1390 |
template<class Alloc, class... UTypes>
|
| 1391 |
-
|
|
|
|
| 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 |
-
|
|
|
|
| 1398 |
template<class Alloc, class... UTypes>
|
| 1399 |
-
|
|
|
|
| 1400 |
template<class Alloc, class U1, class U2>
|
| 1401 |
-
|
|
|
|
| 1402 |
template<class Alloc, class U1, class U2>
|
| 1403 |
-
|
|
|
|
| 1404 |
```
|
| 1405 |
|
| 1406 |
-
*
|
| 1407 |
-
|
| 1408 |
|
| 1409 |
*Effects:* Equivalent to the preceding constructors except that each
|
| 1410 |
element is constructed with uses-allocator
|
| 1411 |
-
construction
|
| 1412 |
|
| 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
|
|
@@ -1418,31 +1297,30 @@ 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
|
| 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ᵢ>
|
|
@@ -1451,74 +1329,76 @@ is_nothrow_move_assignable_v<Tᵢ>
|
|
| 1451 |
where Tᵢ is the iᵗʰ type in `Types`.
|
| 1452 |
|
| 1453 |
*Returns:* `*this`.
|
| 1454 |
|
| 1455 |
``` cpp
|
| 1456 |
-
template
|
| 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
|
| 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
|
| 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
|
| 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 |
-
*
|
| 1519 |
-
with
|
| 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
|
|
@@ -1531,27 +1411,23 @@ is_nothrow_swappable_v<Tᵢ>
|
|
| 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 |
-
###
|
| 1537 |
|
| 1538 |
-
In the function descriptions that follow, the members of a
|
| 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<
|
| 1545 |
```
|
| 1546 |
|
| 1547 |
-
|
| 1548 |
-
|
| 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;
|
|
@@ -1567,14 +1443,14 @@ 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
|
| 1573 |
-
|
| 1574 |
-
|
| 1575 |
-
|
| 1576 |
|
| 1577 |
*Returns:* `tuple<TTypes&&...>(std::forward<TTypes>(t)...)`.
|
| 1578 |
|
| 1579 |
``` cpp
|
| 1580 |
template<class... TTypes>
|
|
@@ -1605,22 +1481,22 @@ template <class... Tuples>
|
|
| 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 |
-
*
|
| 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
|
| 1613 |
-
the kᵗʰ type in `Argsᵢ`. For all `A_ik` the following
|
| 1614 |
-
|
| 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`
|
| 1621 |
-
|
| 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
|
|
@@ -1631,35 +1507,35 @@ 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,
|
| 1637 |
-
`pair` and `array`. — *end note*]
|
| 1638 |
|
| 1639 |
-
###
|
| 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 |
-
|
| 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
|
| 1660 |
-
make_index_sequence<tuple_size_v<
|
| 1661 |
```
|
| 1662 |
|
| 1663 |
``` cpp
|
| 1664 |
template<class T, class Tuple>
|
| 1665 |
constexpr T make_from_tuple(Tuple&& t);
|
|
@@ -1667,107 +1543,98 @@ template <class T, class Tuple>
|
|
| 1667 |
|
| 1668 |
*Effects:* Given the exposition-only function:
|
| 1669 |
|
| 1670 |
``` cpp
|
| 1671 |
template<class T, class Tuple, size_t... I>
|
| 1672 |
-
constexpr T
|
| 1673 |
return T(get<I>(std::forward<Tuple>(t))...);
|
| 1674 |
}
|
| 1675 |
```
|
| 1676 |
|
| 1677 |
Equivalent to:
|
| 1678 |
|
| 1679 |
``` cpp
|
| 1680 |
-
return
|
| 1681 |
-
|
|
|
|
| 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 |
-
###
|
| 1689 |
|
| 1690 |
``` cpp
|
| 1691 |
template<class T> struct tuple_size;
|
| 1692 |
```
|
| 1693 |
|
| 1694 |
-
|
| 1695 |
-
|
| 1696 |
-
|
| 1697 |
|
| 1698 |
``` cpp
|
| 1699 |
template<class... Types>
|
| 1700 |
-
|
| 1701 |
```
|
| 1702 |
|
| 1703 |
``` cpp
|
| 1704 |
template<size_t I, class... Types>
|
| 1705 |
-
|
| 1706 |
-
public:
|
| 1707 |
using type = TI;
|
| 1708 |
};
|
| 1709 |
```
|
| 1710 |
|
| 1711 |
-
*
|
| 1712 |
-
out of bounds.
|
| 1713 |
|
| 1714 |
-
*Type:* `TI` is the type of the `I`
|
| 1715 |
is zero-based.
|
| 1716 |
|
| 1717 |
``` cpp
|
| 1718 |
-
template
|
| 1719 |
-
template <class T> class tuple_size<volatile T>;
|
| 1720 |
-
template <class T> class tuple_size<const volatile T>;
|
| 1721 |
```
|
| 1722 |
|
| 1723 |
-
Let
|
| 1724 |
-
expression
|
| 1725 |
-
operand, then each of the
|
| 1726 |
-
|
| 1727 |
characteristic of
|
| 1728 |
|
| 1729 |
``` cpp
|
| 1730 |
integral_constant<size_t, TS::value>
|
| 1731 |
```
|
| 1732 |
|
| 1733 |
-
Otherwise,
|
| 1734 |
|
| 1735 |
-
Access checking is performed as if in a context unrelated to
|
| 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
|
| 1747 |
or `<utility>` are included.
|
| 1748 |
|
| 1749 |
``` cpp
|
| 1750 |
-
template
|
| 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
|
| 1756 |
-
|
| 1757 |
-
|
| 1758 |
-
typedef `type` that names the
|
| 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
|
| 1766 |
or `<utility>` are included.
|
| 1767 |
|
| 1768 |
-
###
|
| 1769 |
|
| 1770 |
``` cpp
|
| 1771 |
template<size_t I, class... Types>
|
| 1772 |
constexpr tuple_element_t<I, tuple<Types...>>&
|
| 1773 |
get(tuple<Types...>& t) noexcept;
|
|
@@ -1779,25 +1646,24 @@ template <size_t I, class... 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 |
-
*
|
| 1785 |
-
out of bounds.
|
| 1786 |
|
| 1787 |
-
*Returns:* A reference to the `I`
|
| 1788 |
zero-based.
|
| 1789 |
|
| 1790 |
-
[*Note 1*: \[Note A\]If a `T` in `Types` is some reference type
|
| 1791 |
-
the return type is `X&`, not `X&&`. However, if the element type
|
| 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
|
| 1795 |
-
reference type `X&`, the return type is `X&`, not `const X&`.
|
| 1796 |
-
if the element type is a non-reference type `T`, the return
|
| 1797 |
-
`const T&`. This is consistent with how constness is defined to
|
| 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>
|
|
@@ -1806,42 +1672,41 @@ 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 |
-
*
|
| 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 |
-
|
| 1822 |
-
|
| 1823 |
-
|
| 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 |
-
###
|
| 1834 |
|
| 1835 |
``` cpp
|
| 1836 |
template<class... TTypes, class... UTypes>
|
| 1837 |
constexpr bool operator==(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
|
| 1838 |
```
|
| 1839 |
|
| 1840 |
-
*
|
| 1841 |
`get<i>(t) == get<i>(u)` is a valid expression returning a type that is
|
| 1842 |
-
convertible to `bool`. `sizeof...(TTypes)`
|
| 1843 |
|
| 1844 |
*Returns:* `true` if `get<i>(t) == get<i>(u)` for all `i`, otherwise
|
| 1845 |
`false`. For any two zero-length tuples `e` and `f`, `e == f` returns
|
| 1846 |
`true`.
|
| 1847 |
|
|
@@ -1849,85 +1714,57 @@ convertible to `bool`. `sizeof...(TTypes)` `==` `sizeof...(UTypes)`.
|
|
| 1849 |
zeroth index upwards. No comparisons or element accesses are performed
|
| 1850 |
after the first equality comparison that evaluates to `false`.
|
| 1851 |
|
| 1852 |
``` cpp
|
| 1853 |
template<class... TTypes, class... UTypes>
|
| 1854 |
-
constexpr
|
|
|
|
| 1855 |
```
|
| 1856 |
|
| 1857 |
-
*
|
| 1858 |
-
|
| 1859 |
-
|
| 1860 |
-
`sizeof...(TTypes)` `==` `sizeof...(UTypes)`.
|
| 1861 |
-
|
| 1862 |
-
*Returns:* The result of a lexicographical comparison between `t` and
|
| 1863 |
-
`u`. The result is defined as:
|
| 1864 |
-
`(bool)(get<0>(t) < get<0>(u)) || (!(bool)(get<0>(u) < get<0>(t)) && t`ₜₐᵢₗ` < u`ₜₐᵢₗ`)`,
|
| 1865 |
-
where `r`ₜₐᵢₗ for some tuple `r` is a tuple containing all but the first
|
| 1866 |
-
element of `r`. For any two zero-length tuples `e` and `f`, `e < f`
|
| 1867 |
-
returns `false`.
|
| 1868 |
-
|
| 1869 |
-
``` cpp
|
| 1870 |
-
template<class... TTypes, class... UTypes>
|
| 1871 |
-
constexpr bool operator!=(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
|
| 1872 |
-
```
|
| 1873 |
-
|
| 1874 |
-
*Returns:* `!(t == u)`.
|
| 1875 |
-
|
| 1876 |
-
``` cpp
|
| 1877 |
-
template<class... TTypes, class... UTypes>
|
| 1878 |
-
constexpr bool operator>(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
|
| 1879 |
-
```
|
| 1880 |
-
|
| 1881 |
-
*Returns:* `u < t`.
|
| 1882 |
-
|
| 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 |
-
|
| 1892 |
-
|
| 1893 |
```
|
| 1894 |
|
| 1895 |
-
|
|
|
|
| 1896 |
|
| 1897 |
-
[*Note 1*: The above
|
| 1898 |
-
|
| 1899 |
-
|
| 1900 |
-
|
| 1901 |
-
|
| 1902 |
-
comparison. — *end note*]
|
| 1903 |
|
| 1904 |
-
###
|
| 1905 |
|
| 1906 |
``` cpp
|
| 1907 |
template<class... Types, class Alloc>
|
| 1908 |
struct uses_allocator<tuple<Types...>, Alloc> : true_type { };
|
| 1909 |
```
|
| 1910 |
|
| 1911 |
-
*
|
| 1912 |
-
|
| 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 |
-
###
|
| 1919 |
|
| 1920 |
``` cpp
|
| 1921 |
template<class... Types>
|
| 1922 |
-
void swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(see below);
|
| 1923 |
```
|
| 1924 |
|
| 1925 |
-
*
|
| 1926 |
-
|
| 1927 |
-
|
| 1928 |
-
equivalent to:
|
| 1929 |
|
| 1930 |
``` cpp
|
| 1931 |
noexcept(x.swap(y))
|
| 1932 |
```
|
| 1933 |
|
|
@@ -1935,21 +1772,23 @@ noexcept(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 |
-
|
| 1941 |
-
optional objects. An *optional object* is an object that
|
| 1942 |
-
storage for another object and manages the lifetime of this
|
| 1943 |
-
object, if any. The contained object may be initialized after
|
| 1944 |
-
optional object has been initialized, and may be destroyed before
|
| 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 |
|
|
@@ -1971,38 +1810,35 @@ namespace std {
|
|
| 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
|
| 1980 |
-
|
| 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.
|
| 1992 |
template<class T, class U> constexpr bool operator==(const optional<T>&, const U&);
|
| 1993 |
-
template
|
| 1994 |
template<class T, class U> constexpr bool operator!=(const optional<T>&, const U&);
|
| 1995 |
-
template
|
| 1996 |
template<class T, class U> constexpr bool operator<(const optional<T>&, const U&);
|
| 1997 |
-
template
|
| 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
|
|
|
|
|
|
|
| 2002 |
template<class T, class U> constexpr bool operator>=(const optional<T>&, const U&);
|
| 2003 |
-
template
|
|
|
|
|
|
|
|
|
|
| 2004 |
|
| 2005 |
// [optional.specalg], specialized algorithms
|
| 2006 |
template<class T>
|
| 2007 |
void swap(optional<T>&, optional<T>&) noexcept(see below);
|
| 2008 |
|
|
@@ -2017,17 +1853,14 @@ namespace std {
|
|
| 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 |
|
|
@@ -2039,23 +1872,23 @@ template <class T>
|
|
| 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 |
-
|
| 2045 |
template<class U>
|
| 2046 |
-
|
| 2047 |
template<class U>
|
| 2048 |
-
|
| 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&&...);
|
|
@@ -2084,11 +1917,13 @@ template <class T>
|
|
| 2084 |
|
| 2085 |
private:
|
| 2086 |
T *val; // exposition only
|
| 2087 |
};
|
| 2088 |
|
| 2089 |
-
template<class 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
|
|
@@ -2102,135 +1937,126 @@ 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
|
| 2108 |
-
|
| 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 |
-
*
|
| 2118 |
|
| 2119 |
*Remarks:* No contained value is initialized. For every object type `T`
|
| 2120 |
-
these constructors
|
| 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 |
-
*
|
| 2131 |
|
| 2132 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2133 |
|
| 2134 |
-
*Remarks:* This constructor
|
| 2135 |
`is_copy_constructible_v<T>` is `true`. If
|
| 2136 |
-
`is_trivially_copy_constructible_v<T>` is `true`, this constructor
|
| 2137 |
-
|
| 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 |
-
*
|
| 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>`.
|
| 2153 |
-
|
| 2154 |
-
|
| 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 |
-
*
|
| 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
|
| 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 |
-
*
|
| 2184 |
|
| 2185 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2186 |
|
| 2187 |
-
*Remarks:*
|
| 2188 |
-
|
| 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
|
| 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 |
-
*
|
| 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
|
| 2212 |
-
|
| 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 |
-
|
| 2220 |
```
|
| 2221 |
|
| 2222 |
-
|
| 2223 |
-
|
| 2224 |
-
|
| 2225 |
-
|
| 2226 |
-
*Postconditions:* `bool(rhs)` == `bool(*this)`.
|
| 2227 |
-
|
| 2228 |
-
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2229 |
|
| 2230 |
-
*
|
| 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`,
|
|
@@ -2238,40 +2064,53 @@ unless
|
|
| 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 |
-
|
| 2244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2245 |
|
| 2246 |
``` cpp
|
| 2247 |
-
template
|
| 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 |
-
*
|
| 2255 |
|
| 2256 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2257 |
|
| 2258 |
-
*Remarks:*
|
| 2259 |
-
unless
|
| 2260 |
|
| 2261 |
-
|
| 2262 |
-
|
| 2263 |
-
|
| 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();
|
|
@@ -2282,72 +2121,77 @@ contains a value, calls
|
|
| 2282 |
|
| 2283 |
``` cpp
|
| 2284 |
val->T::~T()
|
| 2285 |
```
|
| 2286 |
|
| 2287 |
-
*Remarks:* If `is_trivially_destructible_v<T>
|
| 2288 |
-
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 |
-
*
|
| 2300 |
|
| 2301 |
-
*
|
| 2302 |
|
| 2303 |
``` cpp
|
| 2304 |
-
optional<T>& operator=(const optional& rhs);
|
| 2305 |
```
|
| 2306 |
|
| 2307 |
-
*Effects:* See
|
| 2308 |
|
| 2309 |
-
**Table: `optional::operator=(const optional&)` effects** <a id="
|
| 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 |
-
*
|
| 2318 |
|
| 2319 |
-
*
|
| 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
|
| 2327 |
`is_copy_constructible_v<T>` is `true` and `is_copy_assignable_v<T>` is
|
| 2328 |
-
`true`.
|
|
|
|
|
|
|
| 2329 |
|
| 2330 |
``` cpp
|
| 2331 |
-
optional
|
| 2332 |
```
|
| 2333 |
|
| 2334 |
-
*
|
| 2335 |
-
|
| 2336 |
|
| 2337 |
-
*
|
|
|
|
|
|
|
|
|
|
| 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 |
```
|
|
@@ -2356,65 +2200,44 @@ 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.
|
| 2362 |
-
|
| 2363 |
-
|
| 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 |
-
*
|
| 2375 |
|
| 2376 |
-
*
|
| 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 |
-
*
|
| 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`,
|
|
@@ -2427,37 +2250,37 @@ unless
|
|
| 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 |
-
*
|
| 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`,
|
|
@@ -2470,21 +2293,44 @@ unless
|
|
| 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 |
-
*
|
| 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 |
-
*
|
| 2486 |
|
| 2487 |
*Returns:* A reference to the new contained value.
|
| 2488 |
|
| 2489 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2490 |
|
|
@@ -2494,47 +2340,49 @@ constructor, `*this` does not contain a value, and the previous `*val`
|
|
| 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 |
-
*
|
| 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.
|
| 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 |
-
*
|
| 2522 |
-
`is_move_constructible_v<T>` is `true`.
|
| 2523 |
|
| 2524 |
-
*
|
| 2525 |
|
| 2526 |
-
*
|
|
|
|
|
|
|
| 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
|
| 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>
|
|
@@ -2553,55 +2401,55 @@ exception safety guarantee of `T`’s move constructor.
|
|
| 2553 |
``` cpp
|
| 2554 |
constexpr const T* operator->() const;
|
| 2555 |
constexpr T* operator->();
|
| 2556 |
```
|
| 2557 |
|
| 2558 |
-
*
|
| 2559 |
|
| 2560 |
*Returns:* `val`.
|
| 2561 |
|
| 2562 |
*Throws:* Nothing.
|
| 2563 |
|
| 2564 |
-
*Remarks:* These functions
|
| 2565 |
|
| 2566 |
``` cpp
|
| 2567 |
constexpr const T& operator*() const&;
|
| 2568 |
constexpr T& operator*() &;
|
| 2569 |
```
|
| 2570 |
|
| 2571 |
-
*
|
| 2572 |
|
| 2573 |
*Returns:* `*val`.
|
| 2574 |
|
| 2575 |
*Throws:* Nothing.
|
| 2576 |
|
| 2577 |
-
*Remarks:* These functions
|
| 2578 |
|
| 2579 |
``` cpp
|
| 2580 |
constexpr T&& operator*() &&;
|
| 2581 |
constexpr const T&& operator*() const&&;
|
| 2582 |
```
|
| 2583 |
|
| 2584 |
-
*
|
| 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
|
| 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
|
| 2603 |
|
| 2604 |
``` cpp
|
| 2605 |
constexpr const T& value() const&;
|
| 2606 |
constexpr T& value() &;
|
| 2607 |
```
|
|
@@ -2625,349 +2473,317 @@ return bool(*this) ? std::move(*val) : throw bad_optional_access();
|
|
| 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 |
-
*
|
| 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
|
| 2671 |
-
|
| 2672 |
-
|
| 2673 |
-
|
| 2674 |
-
|
| 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 |
-
|
|
|
|
| 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 |
-
|
| 2694 |
```
|
| 2695 |
|
| 2696 |
-
*
|
| 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 |
-
*
|
| 2707 |
-
|
| 2708 |
|
| 2709 |
-
[*Note 1*: `T` need not be
|
| 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
|
| 2716 |
|
| 2717 |
``` cpp
|
| 2718 |
template<class T, class U> constexpr bool operator!=(const optional<T>& x, const optional<U>& y);
|
| 2719 |
```
|
| 2720 |
|
| 2721 |
-
*
|
| 2722 |
-
|
| 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
|
| 2729 |
|
| 2730 |
``` cpp
|
| 2731 |
template<class T, class U> constexpr bool operator<(const optional<T>& x, const optional<U>& y);
|
| 2732 |
```
|
| 2733 |
|
| 2734 |
-
*
|
| 2735 |
-
|
| 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
|
| 2742 |
|
| 2743 |
``` cpp
|
| 2744 |
template<class T, class U> constexpr bool operator>(const optional<T>& x, const optional<U>& y);
|
| 2745 |
```
|
| 2746 |
|
| 2747 |
-
*
|
| 2748 |
-
|
| 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
|
| 2755 |
|
| 2756 |
``` cpp
|
| 2757 |
template<class T, class U> constexpr bool operator<=(const optional<T>& x, const optional<U>& y);
|
| 2758 |
```
|
| 2759 |
|
| 2760 |
-
*
|
| 2761 |
-
|
| 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
|
| 2768 |
|
| 2769 |
``` cpp
|
| 2770 |
template<class T, class U> constexpr bool operator>=(const optional<T>& x, const optional<U>& y);
|
| 2771 |
```
|
| 2772 |
|
| 2773 |
-
*
|
| 2774 |
-
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 2793 |
-
template <class T> constexpr bool operator!=(nullopt_t, const optional<T>& x) noexcept;
|
| 2794 |
```
|
| 2795 |
|
| 2796 |
-
*Returns:* `bool(x)`.
|
| 2797 |
|
| 2798 |
-
``
|
| 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 |
-
*
|
| 2853 |
-
|
| 2854 |
|
| 2855 |
-
[*Note 1*: `T` need not be
|
| 2856 |
|
| 2857 |
*Effects:* Equivalent to: `return bool(x) ? *x == v : false;`
|
| 2858 |
|
| 2859 |
``` cpp
|
| 2860 |
-
template
|
| 2861 |
```
|
| 2862 |
|
| 2863 |
-
*
|
| 2864 |
-
|
| 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 |
-
*
|
| 2873 |
-
|
| 2874 |
|
| 2875 |
*Effects:* Equivalent to: `return bool(x) ? *x != v : true;`
|
| 2876 |
|
| 2877 |
``` cpp
|
| 2878 |
-
template
|
| 2879 |
```
|
| 2880 |
|
| 2881 |
-
*
|
| 2882 |
-
|
| 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 |
-
*
|
| 2891 |
-
|
| 2892 |
|
| 2893 |
*Effects:* Equivalent to: `return bool(x) ? *x < v : true;`
|
| 2894 |
|
| 2895 |
``` cpp
|
| 2896 |
-
template
|
| 2897 |
```
|
| 2898 |
|
| 2899 |
-
*
|
| 2900 |
-
|
| 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 |
-
*
|
| 2927 |
-
|
| 2928 |
|
| 2929 |
*Effects:* Equivalent to: `return bool(x) ? *x > v : false;`
|
| 2930 |
|
| 2931 |
``` cpp
|
| 2932 |
-
template
|
| 2933 |
```
|
| 2934 |
|
| 2935 |
-
*
|
| 2936 |
-
|
| 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 |
-
*
|
| 2945 |
-
|
| 2946 |
|
| 2947 |
*Effects:* Equivalent to: `return bool(x) ? *x >= v : false;`
|
| 2948 |
|
| 2949 |
``` cpp
|
| 2950 |
-
template
|
| 2951 |
```
|
| 2952 |
|
| 2953 |
-
*
|
| 2954 |
-
|
| 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 |
-
*
|
|
|
|
| 2965 |
|
| 2966 |
-
*
|
| 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 |
|
|
@@ -2993,50 +2809,48 @@ template <class T, class U, class... Args>
|
|
| 2993 |
|
| 2994 |
``` cpp
|
| 2995 |
template<class T> struct hash<optional<T>>;
|
| 2996 |
```
|
| 2997 |
|
| 2998 |
-
The specialization `hash<optional<T>>` is enabled
|
| 2999 |
-
|
| 3000 |
object `o` of type `optional<T>`, if `bool(o) == true`, then
|
| 3001 |
-
`hash<optional<T>>()(o)`
|
| 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...>>;
|
|
@@ -3090,25 +2904,26 @@ namespace std {
|
|
| 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
|
| 3110 |
|
| 3111 |
// [variant.specalg], specialized algorithms
|
| 3112 |
template<class... Types>
|
| 3113 |
void swap(variant<Types...>&, variant<Types...>&) noexcept(see below);
|
| 3114 |
|
|
@@ -3117,14 +2932,10 @@ namespace std {
|
|
| 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 |
|
|
@@ -3133,12 +2944,12 @@ namespace std {
|
|
| 3133 |
template<class... Types>
|
| 3134 |
class variant {
|
| 3135 |
public:
|
| 3136 |
// [variant.ctor], constructors
|
| 3137 |
constexpr variant() noexcept(see below);
|
| 3138 |
-
|
| 3139 |
-
|
| 3140 |
|
| 3141 |
template<class T>
|
| 3142 |
constexpr variant(T&&) noexcept(see below);
|
| 3143 |
|
| 3144 |
template<class T, class... Args>
|
|
@@ -3149,36 +2960,16 @@ namespace std {
|
|
| 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 |
-
|
| 3179 |
-
|
| 3180 |
|
| 3181 |
template<class T> variant& operator=(T&&) noexcept(see below);
|
| 3182 |
|
| 3183 |
// [variant.mod], modifiers
|
| 3184 |
template<class T, class... Args>
|
|
@@ -3199,352 +2990,327 @@ namespace std {
|
|
| 3199 |
};
|
| 3200 |
}
|
| 3201 |
```
|
| 3202 |
|
| 3203 |
Any instance of `variant` at any given time either holds a value of one
|
| 3204 |
-
of its alternative types
|
| 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
|
| 3212 |
-
are supported.
|
| 3213 |
|
| 3214 |
-
All types in `Types
|
| 3215 |
-
|
| 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 |
-
*
|
| 3233 |
-
`0`.
|
| 3234 |
|
| 3235 |
*Throws:* Any exception thrown by the value-initialization of `T₀`.
|
| 3236 |
|
| 3237 |
-
*Remarks:* This function
|
| 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₀``>`.
|
| 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
|
| 3259 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 3274 |
-
|
| 3275 |
-
|
| 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ᵢ`
|
| 3283 |
-
|
| 3284 |
-
*FUN*(
|
| 3285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 3292 |
|
| 3293 |
*Throws:* Any exception thrown by the initialization of the selected
|
| 3294 |
alternative `Tⱼ`.
|
| 3295 |
|
| 3296 |
-
*Remarks:*
|
| 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
|
| 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 |
-
*
|
| 3328 |
|
| 3329 |
*Throws:* Any exception thrown by calling the selected constructor of
|
| 3330 |
`T`.
|
| 3331 |
|
| 3332 |
-
*Remarks:*
|
| 3333 |
-
|
| 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 |
-
*
|
| 3348 |
|
| 3349 |
*Throws:* Any exception thrown by calling the selected constructor of
|
| 3350 |
`T`.
|
| 3351 |
|
| 3352 |
-
*Remarks:*
|
| 3353 |
-
|
| 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 |
-
*
|
| 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 |
-
|
| 3378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 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 |
-
|
| 3399 |
-
|
|
|
|
| 3400 |
|
| 3401 |
-
``
|
| 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 |
-
*
|
| 3424 |
-
|
| 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ᵢ``>
|
| 3440 |
-
then this 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 |
-
|
| 3454 |
-
|
| 3455 |
-
|
| 3456 |
-
|
| 3457 |
-
|
| 3458 |
-
|
| 3459 |
-
`
|
| 3460 |
-
|
| 3461 |
-
- equivalent to `operator=(variant(rhs))`.
|
| 3462 |
|
| 3463 |
*Returns:* `*this`.
|
| 3464 |
|
| 3465 |
-
*
|
| 3466 |
|
| 3467 |
-
*Remarks:* This
|
| 3468 |
-
|
| 3469 |
-
`
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 3481 |
-
|
| 3482 |
-
|
| 3483 |
-
|
| 3484 |
-
|
| 3485 |
-
- equivalent to `emplace<`j`>(get<`j`>(std::move(rhs)))`.
|
| 3486 |
|
| 3487 |
*Returns:* `*this`.
|
| 3488 |
|
| 3489 |
-
*Remarks:*
|
| 3490 |
-
|
| 3491 |
-
is `true` for all i
|
|
|
|
|
|
|
| 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()
|
| 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ᵢ`
|
| 3507 |
-
|
| 3508 |
-
*FUN*(
|
| 3509 |
-
|
| 3510 |
-
|
| 3511 |
-
|
| 3512 |
-
|
| 3513 |
-
|
| 3514 |
-
|
| 3515 |
-
-
|
| 3516 |
-
`
|
| 3517 |
-
|
| 3518 |
-
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3546 |
|
| 3547 |
``` cpp
|
| 3548 |
is_nothrow_assignable_v<Tⱼ&, T> && is_nothrow_constructible_v<Tⱼ, T>
|
| 3549 |
```
|
| 3550 |
|
|
@@ -3560,78 +3326,83 @@ is_nothrow_assignable_v<Tⱼ&, T> && is_nothrow_constructible_v<Tⱼ, T>
|
|
| 3560 |
|
| 3561 |
``` cpp
|
| 3562 |
template<class T, class... Args> T& emplace(Args&&... args);
|
| 3563 |
```
|
| 3564 |
|
| 3565 |
-
|
|
|
|
| 3566 |
|
| 3567 |
*Effects:* Equivalent to:
|
| 3568 |
-
`return emplace<`I`>(std::forward<Args>(args)...);`
|
| 3569 |
|
| 3570 |
-
|
| 3571 |
-
|
| 3572 |
-
|
|
|
|
|
|
|
| 3573 |
|
| 3574 |
``` cpp
|
| 3575 |
template<class T, class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
|
| 3576 |
```
|
| 3577 |
|
| 3578 |
-
|
|
|
|
| 3579 |
|
| 3580 |
*Effects:* Equivalent to:
|
| 3581 |
-
`return emplace<`I`>(il, std::forward<Args>(args)...);`
|
| 3582 |
|
| 3583 |
-
|
| 3584 |
-
|
| 3585 |
-
|
|
|
|
|
|
|
| 3586 |
|
| 3587 |
``` cpp
|
| 3588 |
template<size_t I, class... Args>
|
| 3589 |
variant_alternative_t<I, variant<Types...>>& emplace(Args&&... args);
|
| 3590 |
```
|
| 3591 |
|
| 3592 |
-
*
|
|
|
|
|
|
|
| 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 |
-
*
|
| 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:*
|
| 3607 |
-
|
| 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 |
-
*
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 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:*
|
| 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
|
|
@@ -3667,22 +3438,22 @@ alternative of the contained value.
|
|
| 3667 |
|
| 3668 |
``` cpp
|
| 3669 |
void swap(variant& rhs) noexcept(see below);
|
| 3670 |
```
|
| 3671 |
|
| 3672 |
-
*
|
| 3673 |
-
|
| 3674 |
-
|
|
|
|
| 3675 |
|
| 3676 |
*Effects:*
|
| 3677 |
|
| 3678 |
-
-
|
| 3679 |
-
effect.
|
| 3680 |
-
- if `index() == rhs.index()`, calls
|
| 3681 |
`swap(get<`i`>(*this), get<`i`>(rhs))` where i is `index()`.
|
| 3682 |
-
|
| 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()`.
|
|
@@ -3692,75 +3463,66 @@ with i being `index()` and j being `rhs.index()`.
|
|
| 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
|
| 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 |
-
|
| 3708 |
-
|
| 3709 |
-
|
| 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
|
| 3719 |
-
requirements
|
| 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
|
| 3735 |
-
|
| 3736 |
-
typedef `type` that names the
|
| 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 |
-
*
|
| 3747 |
|
| 3748 |
-
*
|
| 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 |
-
*
|
| 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>
|
|
@@ -3769,11 +3531,11 @@ 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 |
-
*
|
| 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 |
|
|
@@ -3782,12 +3544,11 @@ 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 |
-
*
|
| 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
|
|
@@ -3797,11 +3558,11 @@ template <size_t I, class... Types>
|
|
| 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 |
-
*
|
| 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
|
|
@@ -3811,49 +3572,48 @@ template <class T, class... Types>
|
|
| 3811 |
template<class T, class... Types>
|
| 3812 |
constexpr add_pointer_t<const T>
|
| 3813 |
get_if(const variant<Types...>* v) noexcept;
|
| 3814 |
```
|
| 3815 |
|
| 3816 |
-
*
|
| 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 |
-
*
|
| 3830 |
-
|
| 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 |
-
*
|
| 3842 |
-
|
| 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 |
-
*
|
| 3854 |
-
|
| 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()`.
|
|
@@ -3861,12 +3621,12 @@ a type that is convertible to `bool`, for all i.
|
|
| 3861 |
``` cpp
|
| 3862 |
template<class... Types>
|
| 3863 |
constexpr bool operator>(const variant<Types...>& v, const variant<Types...>& w);
|
| 3864 |
```
|
| 3865 |
|
| 3866 |
-
*
|
| 3867 |
-
|
| 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()`.
|
|
@@ -3874,12 +3634,12 @@ a type that is convertible to `bool`, for all i.
|
|
| 3874 |
``` cpp
|
| 3875 |
template<class... Types>
|
| 3876 |
constexpr bool operator<=(const variant<Types...>& v, const variant<Types...>& w);
|
| 3877 |
```
|
| 3878 |
|
| 3879 |
-
*
|
| 3880 |
-
|
| 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
|
|
@@ -3888,43 +3648,77 @@ a type that is convertible to `bool`, for all i.
|
|
| 3888 |
``` cpp
|
| 3889 |
template<class... Types>
|
| 3890 |
constexpr bool operator>=(const variant<Types...>& v, const variant<Types...>& w);
|
| 3891 |
```
|
| 3892 |
|
| 3893 |
-
*
|
| 3894 |
-
|
| 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 |
-
|
| 3910 |
-
|
| 3911 |
-
|
|
|
|
| 3912 |
|
| 3913 |
-
|
| 3914 |
-
|
| 3915 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3916 |
|
| 3917 |
-
*
|
| 3918 |
-
|
|
|
|
| 3919 |
|
| 3920 |
*Throws:* `bad_variant_access` if any `variant` in `vars` is
|
| 3921 |
`valueless_by_exception()`.
|
| 3922 |
|
| 3923 |
-
*Complexity:* For
|
| 3924 |
-
|
| 3925 |
-
|
| 3926 |
the callable object has no complexity requirements.
|
| 3927 |
|
| 3928 |
### Class `monostate` <a id="variant.monostate">[[variant.monostate]]</a>
|
| 3929 |
|
| 3930 |
``` cpp
|
|
@@ -3935,16 +3729,13 @@ 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
|
|
|
|
| 3946 |
```
|
| 3947 |
|
| 3948 |
[*Note 1*: `monostate` objects have only a single state; they thus
|
| 3949 |
always compare equal. — *end note*]
|
| 3950 |
|
|
@@ -3953,36 +3744,32 @@ always compare equal. — *end note*]
|
|
| 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:*
|
| 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 |
-
|
| 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.
|
|
@@ -3991,51 +3778,37 @@ const char* what() const noexcept override;
|
|
| 3991 |
|
| 3992 |
``` cpp
|
| 3993 |
template<class... Types> struct hash<variant<Types...>>;
|
| 3994 |
```
|
| 3995 |
|
| 3996 |
-
The specialization `hash<variant<Types...>>` is
|
| 3997 |
-
|
| 3998 |
-
|
| 3999 |
-
not guaranteed to be `noexcept`.
|
| 4000 |
|
| 4001 |
``` cpp
|
| 4002 |
template<> struct hash<monostate>;
|
| 4003 |
```
|
| 4004 |
|
| 4005 |
-
The specialization is enabled
|
| 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
|
| 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.
|
| 4037 |
class bad_any_cast;
|
| 4038 |
|
| 4039 |
// [any.class], class any
|
| 4040 |
class any;
|
| 4041 |
|
|
@@ -4059,44 +3832,43 @@ namespace std {
|
|
| 4059 |
template<class T>
|
| 4060 |
T* any_cast(any* operand) noexcept;
|
| 4061 |
}
|
| 4062 |
```
|
| 4063 |
|
| 4064 |
-
### Class `bad_any_cast` <a id="any.
|
| 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 |
-
|
|
|
|
| 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&&...);
|
|
@@ -4105,11 +3877,12 @@ public:
|
|
| 4105 |
|
| 4106 |
// [any.assign], assignments
|
| 4107 |
any& operator=(const any& rhs);
|
| 4108 |
any& operator=(any&& rhs) noexcept;
|
| 4109 |
|
| 4110 |
-
|
|
|
|
| 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>
|
|
@@ -4119,124 +3892,119 @@ public:
|
|
| 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
|
| 4127 |
-
|
| 4128 |
-
|
| 4129 |
-
|
| 4130 |
-
|
| 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*:
|
| 4140 |
-
|
| 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 |
-
*
|
| 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(
|
| 4160 |
-
the contained
|
| 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
|
| 4172 |
-
|
| 4173 |
-
considering that contained
|
| 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 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 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 |
-
*
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 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()`.
|
|
@@ -4261,33 +4029,31 @@ any& operator=(any&& rhs) noexcept;
|
|
| 4261 |
|
| 4262 |
*Effects:* As if by `any(std::move(rhs)).swap(*this)`.
|
| 4263 |
|
| 4264 |
*Returns:* `*this`.
|
| 4265 |
|
| 4266 |
-
*
|
| 4267 |
-
|
| 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 |
-
*
|
|
|
|
|
|
|
|
|
|
| 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
|
|
@@ -4295,60 +4061,62 @@ template <class T, class... Args>
|
|
| 4295 |
decay_t<T>& emplace(Args&&... args);
|
| 4296 |
```
|
| 4297 |
|
| 4298 |
Let `VT` be `decay_t<T>`.
|
| 4299 |
|
| 4300 |
-
*
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 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.
|
| 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 |
-
*
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 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.
|
| 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 |
-
*
|
| 4350 |
|
| 4351 |
``` cpp
|
| 4352 |
void swap(any& rhs) noexcept;
|
| 4353 |
```
|
| 4354 |
|
|
@@ -4376,11 +4144,11 @@ time or only at runtime. — *end note*]
|
|
| 4376 |
|
| 4377 |
``` cpp
|
| 4378 |
void swap(any& x, any& y) noexcept;
|
| 4379 |
```
|
| 4380 |
|
| 4381 |
-
*Effects:*
|
| 4382 |
|
| 4383 |
``` cpp
|
| 4384 |
template<class T, class... Args>
|
| 4385 |
any make_any(Args&&... args);
|
| 4386 |
```
|
|
@@ -4403,21 +4171,19 @@ 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 `
|
| 4409 |
|
| 4410 |
-
*
|
| 4411 |
-
`is_constructible_v<
|
| 4412 |
-
overload, `is_constructible_v<
|
| 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<
|
| 4418 |
-
|
| 4419 |
|
| 4420 |
*Throws:* `bad_any_cast` if
|
| 4421 |
`operand.type() != typeid(remove_reference_t<T>)`.
|
| 4422 |
|
| 4423 |
[*Example 1*:
|
|
@@ -4442,12 +4208,11 @@ 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
|
| 4448 |
-
// any_cast away const
|
| 4449 |
```
|
| 4450 |
|
| 4451 |
— *end example*]
|
| 4452 |
|
| 4453 |
``` cpp
|
|
@@ -4472,13 +4237,17 @@ bool is_string(const any& operand) {
|
|
| 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
|
| 4480 |
|
| 4481 |
namespace std {
|
| 4482 |
template<size_t N> class bitset;
|
| 4483 |
|
| 4484 |
// [bitset.operators], bitset operators
|
|
@@ -4495,26 +4264,24 @@ namespace std {
|
|
| 4495 |
basic_ostream<charT, traits>&
|
| 4496 |
operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
|
| 4497 |
}
|
| 4498 |
```
|
| 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
|
| 4511 |
class reference {
|
| 4512 |
friend class bitset;
|
| 4513 |
reference() noexcept;
|
|
|
|
| 4514 |
public:
|
| 4515 |
-
|
|
|
|
| 4516 |
reference& operator=(bool x) noexcept; // for b[i] = x;
|
| 4517 |
reference& operator=(const reference&) noexcept; // for b[i] = b[j];
|
| 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();
|
|
@@ -4525,12 +4292,12 @@ namespace std {
|
|
| 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,
|
|
@@ -4550,11 +4317,11 @@ namespace std {
|
|
| 4550 |
bitset<N>& reset(size_t pos);
|
| 4551 |
bitset<N> operator~() const noexcept;
|
| 4552 |
bitset<N>& flip() noexcept;
|
| 4553 |
bitset<N>& flip(size_t pos);
|
| 4554 |
|
| 4555 |
-
// element access
|
| 4556 |
constexpr bool operator[](size_t pos) const; // for b[i];
|
| 4557 |
reference operator[](size_t pos); // for b[i];
|
| 4558 |
|
| 4559 |
unsigned long to_ulong() const;
|
| 4560 |
unsigned long long to_ullong() const;
|
|
@@ -4565,11 +4332,10 @@ namespace std {
|
|
| 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;
|
| 4572 |
bool all() const noexcept;
|
| 4573 |
bool any() const noexcept;
|
| 4574 |
bool none() const noexcept;
|
| 4575 |
bitset<N> operator<<(size_t pos) const noexcept;
|
|
@@ -4595,89 +4361,82 @@ values.
|
|
| 4595 |
|
| 4596 |
The functions described in this subclause can report three kinds of
|
| 4597 |
errors, each associated with a distinct exception:
|
| 4598 |
|
| 4599 |
- an *invalid-argument* error is associated with exceptions of type
|
| 4600 |
-
`invalid_argument`
|
| 4601 |
- an *out-of-range* error is associated with exceptions of type
|
| 4602 |
-
`out_of_range`
|
| 4603 |
- an *overflow* error is associated with exceptions of type
|
| 4604 |
-
`overflow_error`
|
| 4605 |
|
| 4606 |
-
####
|
| 4607 |
|
| 4608 |
``` cpp
|
| 4609 |
constexpr bitset() noexcept;
|
| 4610 |
```
|
| 4611 |
|
| 4612 |
-
*Effects:*
|
| 4613 |
-
bits to zero.
|
| 4614 |
|
| 4615 |
``` cpp
|
| 4616 |
constexpr bitset(unsigned long long val) noexcept;
|
| 4617 |
```
|
| 4618 |
|
| 4619 |
-
*Effects:*
|
| 4620 |
-
|
| 4621 |
-
the
|
| 4622 |
-
|
| 4623 |
-
the remaining bit positions are initialized to zero.
|
| 4624 |
|
| 4625 |
``` cpp
|
| 4626 |
template<class charT, class traits, class Allocator>
|
| 4627 |
-
explicit
|
| 4628 |
-
|
| 4629 |
typename basic_string<charT, traits, Allocator>::size_type pos = 0,
|
| 4630 |
-
|
| 4631 |
-
|
| 4632 |
-
|
|
|
|
| 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 |
-
|
| 4642 |
-
|
| 4643 |
-
`invalid_argument` if any of the `rlen` characters in `str` beginning at
|
| 4644 |
-
position `pos` is other than `zero` or `one`. The function uses
|
| 4645 |
-
`traits::eq()` to compare the character values.
|
| 4646 |
-
|
| 4647 |
-
Otherwise, the function constructs an object of class `bitset<N>`,
|
| 4648 |
-
initializing the first `M` bit positions to values determined from the
|
| 4649 |
-
corresponding characters in the string `str`. `M` is the smaller of `N`
|
| 4650 |
-
and `rlen`.
|
| 4651 |
|
| 4652 |
An element of the constructed object has value zero if the corresponding
|
| 4653 |
character in `str`, beginning at position `pos`, is `zero`. Otherwise,
|
| 4654 |
the element has the value one. Character position `pos + M - 1`
|
| 4655 |
corresponds to bit position zero. Subsequent decreasing character
|
| 4656 |
positions correspond to increasing bit positions.
|
| 4657 |
|
| 4658 |
If `M < N`, remaining bit positions are initialized to zero.
|
| 4659 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4660 |
``` cpp
|
| 4661 |
template<class charT>
|
| 4662 |
explicit bitset(
|
| 4663 |
const charT* str,
|
| 4664 |
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
|
| 4665 |
-
charT zero = charT('0'),
|
|
|
|
| 4666 |
```
|
| 4667 |
|
| 4668 |
-
*Effects:*
|
| 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 |
-
####
|
| 4679 |
|
| 4680 |
``` cpp
|
| 4681 |
bitset<N>& operator&=(const bitset<N>& rhs) noexcept;
|
| 4682 |
```
|
| 4683 |
|
|
@@ -4740,18 +4499,18 @@ bitset<N>& set() noexcept;
|
|
| 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
|
| 4750 |
|
| 4751 |
*Returns:* `*this`.
|
| 4752 |
|
|
|
|
|
|
|
|
|
|
| 4753 |
``` cpp
|
| 4754 |
bitset<N>& reset() noexcept;
|
| 4755 |
```
|
| 4756 |
|
| 4757 |
*Effects:* Resets all bits in `*this`.
|
|
@@ -4760,17 +4519,17 @@ bitset<N>& reset() noexcept;
|
|
| 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 |
|
| 4770 |
*Returns:* `*this`.
|
| 4771 |
|
|
|
|
|
|
|
|
|
|
| 4772 |
``` cpp
|
| 4773 |
bitset<N> operator~() const noexcept;
|
| 4774 |
```
|
| 4775 |
|
| 4776 |
*Effects:* Constructs an object `x` of class `bitset<N>` and initializes
|
|
@@ -4788,37 +4547,35 @@ bitset<N>& flip() noexcept;
|
|
| 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 |
|
| 4798 |
*Returns:* `*this`.
|
| 4799 |
|
|
|
|
|
|
|
|
|
|
| 4800 |
``` cpp
|
| 4801 |
unsigned long to_ulong() const;
|
| 4802 |
```
|
| 4803 |
|
| 4804 |
-
*Throws:* `overflow_error`
|
| 4805 |
-
|
| 4806 |
-
if the integral value `x` corresponding to the bits in `*this` cannot be
|
| 4807 |
-
represented as type `unsigned long`.
|
| 4808 |
-
|
| 4809 |
*Returns:* `x`.
|
| 4810 |
|
|
|
|
|
|
|
|
|
|
| 4811 |
``` cpp
|
| 4812 |
unsigned long long to_ullong() const;
|
| 4813 |
```
|
| 4814 |
|
|
|
|
|
|
|
| 4815 |
*Throws:* `overflow_error` if the integral value `x` corresponding to
|
| 4816 |
the bits in `*this` cannot be represented as type `unsigned long long`.
|
| 4817 |
|
| 4818 |
-
*Returns:* `x`.
|
| 4819 |
-
|
| 4820 |
``` cpp
|
| 4821 |
template<class charT = char,
|
| 4822 |
class traits = char_traits<charT>,
|
| 4823 |
class Allocator = allocator<charT>>
|
| 4824 |
basic_string<charT, traits, Allocator>
|
|
@@ -4852,26 +4609,20 @@ bool operator==(const bitset<N>& rhs) const noexcept;
|
|
| 4852 |
```
|
| 4853 |
|
| 4854 |
*Returns:* `true` if the value of each bit in `*this` equals the value
|
| 4855 |
of the corresponding bit in `rhs`.
|
| 4856 |
|
| 4857 |
-
``` cpp
|
| 4858 |
-
bool operator!=(const bitset<N>& rhs) const noexcept;
|
| 4859 |
-
```
|
| 4860 |
-
|
| 4861 |
-
*Returns:* `true` if `!(*this == rhs)`.
|
| 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()`.
|
|
@@ -4902,41 +4653,41 @@ bitset<N> operator>>(size_t pos) const noexcept;
|
|
| 4902 |
|
| 4903 |
``` cpp
|
| 4904 |
constexpr bool operator[](size_t pos) const;
|
| 4905 |
```
|
| 4906 |
|
| 4907 |
-
*
|
| 4908 |
|
| 4909 |
*Returns:* `true` if the bit at position `pos` in `*this` has the value
|
| 4910 |
one, otherwise `false`.
|
| 4911 |
|
| 4912 |
*Throws:* Nothing.
|
| 4913 |
|
| 4914 |
``` cpp
|
| 4915 |
bitset<N>::reference operator[](size_t pos);
|
| 4916 |
```
|
| 4917 |
|
| 4918 |
-
*
|
| 4919 |
|
| 4920 |
*Returns:* An object of type `bitset<N>::reference` such that
|
| 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
|
| 4928 |
-
|
| 4929 |
-
|
| 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
|
| 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;
|
|
@@ -4960,11 +4711,11 @@ bitset<N> operator^(const bitset<N>& lhs, const bitset<N>& rhs) noexcept;
|
|
| 4960 |
template<class charT, class traits, size_t N>
|
| 4961 |
basic_istream<charT, traits>&
|
| 4962 |
operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
|
| 4963 |
```
|
| 4964 |
|
| 4965 |
-
A formatted input function
|
| 4966 |
|
| 4967 |
*Effects:* Extracts up to `N` characters from `is`. Stores these
|
| 4968 |
characters in a temporary object `str` of type
|
| 4969 |
`basic_string<charT, traits>`, then evaluates the expression
|
| 4970 |
`x = bitset<N>(str)`. Characters are extracted and stored until any of
|
|
@@ -4973,13 +4724,13 @@ the following occurs:
|
|
| 4973 |
- `N` characters have been extracted and stored;
|
| 4974 |
- end-of-file occurs on the input sequence;
|
| 4975 |
- the next input character is neither `is.widen(’0’)` nor
|
| 4976 |
`is.widen(’1’)` (in which case the input character is not extracted).
|
| 4977 |
|
| 4978 |
-
If no characters are stored in `str`, calls
|
| 4979 |
-
`is.setstate(ios_base::failbit)` (which may throw
|
| 4980 |
-
|
| 4981 |
|
| 4982 |
*Returns:* `is`.
|
| 4983 |
|
| 4984 |
``` cpp
|
| 4985 |
template<class charT, class traits, size_t N>
|
|
@@ -4999,246 +4750,454 @@ os << x.template to_string<charT, traits, allocator<charT>>(
|
|
| 4999 |
|
| 5000 |
## Memory <a id="memory">[[memory]]</a>
|
| 5001 |
|
| 5002 |
### In general <a id="memory.general">[[memory.general]]</a>
|
| 5003 |
|
| 5004 |
-
|
| 5005 |
-
|
| 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 |
-
|
| 5014 |
-
[[specialized.algorithms]]). The header
|
| 5015 |
-
`unique_ptr`, `shared_ptr`, `weak_ptr`, and
|
| 5016 |
-
that operate on objects of these types
|
|
|
|
| 5017 |
|
| 5018 |
``` cpp
|
|
|
|
|
|
|
| 5019 |
namespace std {
|
| 5020 |
// [pointer.traits], pointer traits
|
| 5021 |
template<class Ptr> struct pointer_traits;
|
| 5022 |
template<class T> struct pointer_traits<T*>;
|
| 5023 |
|
| 5024 |
-
// [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5025 |
enum class pointer_safety { relaxed, preferred, strict };
|
| 5026 |
void declare_reachable(void* p);
|
| 5027 |
-
template
|
|
|
|
| 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
|
| 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 |
-
|
| 5050 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5051 |
|
| 5052 |
// [specialized.algorithms], specialized algorithms
|
| 5053 |
-
|
| 5054 |
-
template
|
| 5055 |
-
|
| 5056 |
-
|
| 5057 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5058 |
void uninitialized_default_construct(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5059 |
-
|
| 5060 |
-
|
| 5061 |
-
|
| 5062 |
-
|
| 5063 |
-
|
| 5064 |
-
|
| 5065 |
-
|
| 5066 |
-
|
| 5067 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5068 |
void uninitialized_value_construct(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5069 |
-
|
| 5070 |
-
|
| 5071 |
-
|
| 5072 |
-
|
| 5073 |
-
|
| 5074 |
-
|
| 5075 |
-
|
| 5076 |
-
|
| 5077 |
-
|
| 5078 |
-
|
| 5079 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5080 |
InputIterator first, InputIterator last,
|
| 5081 |
-
|
| 5082 |
-
template
|
| 5083 |
-
|
| 5084 |
-
|
| 5085 |
-
template
|
| 5086 |
-
|
| 5087 |
InputIterator first, Size n,
|
| 5088 |
-
|
| 5089 |
-
|
| 5090 |
-
|
| 5091 |
-
|
| 5092 |
-
|
| 5093 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5094 |
InputIterator first, InputIterator last,
|
| 5095 |
-
|
| 5096 |
-
template
|
| 5097 |
-
pair<InputIterator,
|
| 5098 |
-
uninitialized_move_n(InputIterator first, Size n,
|
| 5099 |
-
template
|
| 5100 |
-
pair<InputIterator,
|
| 5101 |
uninitialized_move_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5102 |
-
InputIterator first, Size n,
|
| 5103 |
-
|
| 5104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5105 |
const T& x);
|
| 5106 |
-
template
|
| 5107 |
void uninitialized_fill(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5108 |
-
|
| 5109 |
const T& x);
|
| 5110 |
-
template
|
| 5111 |
-
|
| 5112 |
-
|
| 5113 |
-
|
| 5114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5115 |
template<class T>
|
| 5116 |
-
void destroy_at(T* location);
|
| 5117 |
-
template
|
| 5118 |
-
void destroy(
|
| 5119 |
-
template
|
| 5120 |
void destroy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5121 |
-
|
| 5122 |
-
template
|
| 5123 |
-
|
| 5124 |
-
template
|
| 5125 |
-
|
| 5126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
| 5134 |
-
template
|
| 5135 |
-
|
| 5136 |
-
template
|
|
|
|
|
|
|
|
|
|
| 5137 |
|
| 5138 |
-
template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5139 |
|
| 5140 |
template<class T1, class D1, class T2, class D2>
|
| 5141 |
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 5142 |
-
template <class T1, class D1, class T2, class D2>
|
| 5143 |
-
bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 5144 |
template<class T1, class D1, class T2, class D2>
|
| 5145 |
bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 5146 |
-
template <class T1, class D1, class T2, class D2>
|
| 5147 |
-
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 5148 |
template<class T1, class D1, class T2, class D2>
|
| 5149 |
bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
|
|
|
|
|
| 5150 |
template<class T1, class D1, class T2, class D2>
|
| 5151 |
bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5152 |
|
| 5153 |
template<class T, class D>
|
| 5154 |
bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
|
| 5155 |
-
template <class T, class D>
|
| 5156 |
-
bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
|
| 5157 |
-
template <class T, class D>
|
| 5158 |
-
bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
|
| 5159 |
-
template <class T, class D>
|
| 5160 |
-
bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
|
| 5161 |
template<class T, class D>
|
| 5162 |
bool operator<(const unique_ptr<T, D>& x, nullptr_t);
|
| 5163 |
template<class T, class D>
|
| 5164 |
bool operator<(nullptr_t, const unique_ptr<T, D>& y);
|
| 5165 |
-
template <class T, class D>
|
| 5166 |
-
bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
|
| 5167 |
-
template <class T, class D>
|
| 5168 |
-
bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
|
| 5169 |
template<class T, class D>
|
| 5170 |
bool operator>(const unique_ptr<T, D>& x, nullptr_t);
|
| 5171 |
template<class T, class D>
|
| 5172 |
bool operator>(nullptr_t, const unique_ptr<T, D>& y);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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 |
-
|
| 5208 |
-
template <class T>
|
| 5209 |
-
bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
|
| 5210 |
-
template <class T>
|
| 5211 |
-
bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
|
| 5212 |
-
template <class T>
|
| 5213 |
-
bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
|
| 5214 |
-
template <class T>
|
| 5215 |
-
bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
|
| 5216 |
-
template <class T>
|
| 5217 |
-
bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
|
| 5218 |
-
template <class T>
|
| 5219 |
-
bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
|
| 5220 |
-
template <class T>
|
| 5221 |
-
bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
|
| 5222 |
-
template <class T>
|
| 5223 |
-
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 |
|
|
@@ -5256,52 +5215,19 @@ namespace std {
|
|
| 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);
|
| 5267 |
-
template<class T>
|
| 5268 |
-
shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
|
| 5269 |
-
|
| 5270 |
-
template<class T>
|
| 5271 |
-
void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
|
| 5272 |
-
template<class T>
|
| 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>
|
| 5284 |
-
bool atomic_compare_exchange_strong(
|
| 5285 |
-
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
|
| 5286 |
-
template<class T>
|
| 5287 |
-
bool atomic_compare_exchange_weak_explicit(
|
| 5288 |
-
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
|
| 5289 |
-
memory_order success, memory_order failure);
|
| 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 |
-
// [
|
| 5301 |
-
template
|
| 5302 |
-
|
|
|
|
| 5303 |
}
|
| 5304 |
```
|
| 5305 |
|
| 5306 |
### Pointer traits <a id="pointer.traits">[[pointer.traits]]</a>
|
| 5307 |
|
|
@@ -5325,61 +5251,97 @@ namespace std {
|
|
| 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 |
};
|
| 5332 |
}
|
| 5333 |
```
|
| 5334 |
|
| 5335 |
-
####
|
| 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
|
| 5343 |
-
|
| 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
|
| 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
|
| 5361 |
-
|
| 5362 |
-
|
| 5363 |
-
|
| 5364 |
-
ill-formed.
|
| 5365 |
|
| 5366 |
-
####
|
| 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 |
-
|
| 5377 |
-
|
| 5378 |
-
|
| 5379 |
-
|
| 5380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
@@ -5388,30 +5350,29 @@ the object.
|
|
| 5388 |
|
| 5389 |
``` cpp
|
| 5390 |
void declare_reachable(void* p);
|
| 5391 |
```
|
| 5392 |
|
| 5393 |
-
*
|
| 5394 |
-
pointer
|
| 5395 |
|
| 5396 |
*Effects:* If `p` is not null, the complete object referenced by `p` is
|
| 5397 |
-
subsequently declared reachable
|
| 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 |
|
| 5406 |
-
*
|
| 5407 |
-
|
| 5408 |
-
|
| 5409 |
-
|
| 5410 |
|
| 5411 |
-
*Returns:* A safely derived copy of `p` which
|
| 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
|
|
@@ -5421,14 +5382,14 @@ matched. — *end note*]
|
|
| 5421 |
|
| 5422 |
``` cpp
|
| 5423 |
void declare_no_pointers(char* p, size_t n);
|
| 5424 |
```
|
| 5425 |
|
| 5426 |
-
*
|
| 5427 |
-
with `declare_no_pointers()`. If the specified range is in an
|
| 5428 |
-
object, then it
|
| 5429 |
-
object
|
| 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*]
|
|
@@ -5449,69 +5410,92 @@ fails. — *end note*]
|
|
| 5449 |
|
| 5450 |
``` cpp
|
| 5451 |
void undeclare_no_pointers(char* p, size_t n);
|
| 5452 |
```
|
| 5453 |
|
| 5454 |
-
*
|
| 5455 |
`declare_no_pointers()`.
|
| 5456 |
|
| 5457 |
*Effects:* Unregisters a range registered with `declare_no_pointers()`
|
| 5458 |
-
for destruction. It
|
| 5459 |
ends.
|
| 5460 |
|
| 5461 |
*Throws:* Nothing.
|
| 5462 |
|
| 5463 |
``` cpp
|
| 5464 |
pointer_safety get_pointer_safety() noexcept;
|
| 5465 |
```
|
| 5466 |
|
| 5467 |
*Returns:* `pointer_safety::strict` if the implementation has strict
|
| 5468 |
-
pointer safety
|
| 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 |
-
###
|
| 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
|
| 5508 |
type to disambiguate constructor and function overloading. Specifically,
|
| 5509 |
several types (see `tuple` [[tuple]]) have constructors with
|
| 5510 |
`allocator_arg_t` as the first argument, immediately followed by an
|
| 5511 |
-
argument of a type that
|
| 5512 |
-
[[
|
| 5513 |
|
| 5514 |
### `uses_allocator` <a id="allocator.uses">[[allocator.uses]]</a>
|
| 5515 |
|
| 5516 |
#### `uses_allocator` trait <a id="allocator.uses.trait">[[allocator.uses.trait]]</a>
|
| 5517 |
|
|
@@ -5519,46 +5503,199 @@ argument of a type that satisfies the `Allocator` requirements (
|
|
| 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 |
-
|
| 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
|
| 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
|
| 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 `
|
| 5541 |
-
construction of an object
|
| 5542 |
-
|
| 5543 |
-
allocator
|
| 5544 |
-
|
| 5545 |
-
|
| 5546 |
-
|
| 5547 |
-
|
| 5548 |
-
|
| 5549 |
-
|
| 5550 |
-
|
| 5551 |
-
|
| 5552 |
-
|
| 5553 |
-
|
| 5554 |
-
|
| 5555 |
-
|
| 5556 |
-
|
| 5557 |
-
|
| 5558 |
-
|
| 5559 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|
|
@@ -5588,484 +5725,266 @@ namespace std {
|
|
| 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);
|
| 5594 |
-
static pointer allocate(Alloc& a, size_type n,
|
|
|
|
| 5595 |
|
| 5596 |
-
static void deallocate(Alloc& a, pointer p, size_type n);
|
| 5597 |
|
| 5598 |
template<class T, class... Args>
|
| 5599 |
-
static void construct(Alloc& a, T* p, Args&&... args);
|
| 5600 |
|
| 5601 |
template<class T>
|
| 5602 |
-
static void destroy(Alloc& a, T* p);
|
| 5603 |
|
| 5604 |
-
static size_type max_size(const Alloc& a) noexcept;
|
| 5605 |
|
| 5606 |
-
static Alloc select_on_container_copy_construction(const Alloc& rhs);
|
| 5607 |
};
|
| 5608 |
}
|
| 5609 |
```
|
| 5610 |
|
| 5611 |
-
####
|
| 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
|
| 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
|
| 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
|
| 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 |
-
|
| 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
|
| 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
|
| 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
|
| 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
|
| 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
|
| 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
|
| 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 |
-
|
| 5700 |
-
|
| 5701 |
-
|
| 5702 |
-
`rebind_alloc` is ill-formed.
|
| 5703 |
|
| 5704 |
-
####
|
| 5705 |
|
| 5706 |
``` cpp
|
| 5707 |
-
static pointer allocate(Alloc& a, size_type n);
|
| 5708 |
```
|
| 5709 |
|
| 5710 |
*Returns:* `a.allocate(n)`.
|
| 5711 |
|
| 5712 |
``` cpp
|
| 5713 |
-
static pointer allocate(Alloc& a, size_type n, const_void_pointer hint);
|
| 5714 |
```
|
| 5715 |
|
| 5716 |
*Returns:* `a.allocate(n, hint)` if that expression is well-formed;
|
| 5717 |
otherwise, `a.allocate(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 |
-
`
|
| 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 `
|
| 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
|
| 5761 |
-
completeness requirements
|
| 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
|
| 5774 |
-
~allocator();
|
|
|
|
| 5775 |
|
| 5776 |
-
T* allocate(size_t n);
|
| 5777 |
-
void deallocate(T* p, size_t n);
|
| 5778 |
};
|
| 5779 |
}
|
| 5780 |
```
|
| 5781 |
|
| 5782 |
-
####
|
| 5783 |
|
| 5784 |
Except for the destructor, member functions of the default allocator
|
| 5785 |
-
shall not introduce data races
|
| 5786 |
concurrent calls to those member functions from different threads. Calls
|
| 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 |
-
*
|
| 5796 |
-
size `n` `* sizeof(T)`, aligned appropriately for objects of type `T`.
|
| 5797 |
|
| 5798 |
-
*
|
| 5799 |
-
`::operator new` ([[new.delete]]), but it is unspecified when or how
|
| 5800 |
-
often this function is called.
|
| 5801 |
|
| 5802 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5803 |
|
| 5804 |
``` cpp
|
| 5805 |
-
void deallocate(T* p, size_t n);
|
| 5806 |
```
|
| 5807 |
|
| 5808 |
-
*
|
| 5809 |
-
|
| 5810 |
allocate which returned `p`.
|
| 5811 |
|
| 5812 |
*Effects:* Deallocates the storage referenced by `p` .
|
| 5813 |
|
| 5814 |
-
*Remarks:* Uses `::operator delete`
|
| 5815 |
unspecified when this function is called.
|
| 5816 |
|
| 5817 |
-
####
|
| 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 |
-
``
|
| 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
|
| 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>`
|
| 6066 |
-
|
| 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);
|
|
@@ -6074,11 +5993,11 @@ void* realloc(void* ptr, size_t size);
|
|
| 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()`
|
| 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.
|
|
@@ -6092,125 +6011,60 @@ implemented with a separate allocation arena, bypassing the normal
|
|
| 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
|
| 6108 |
|
| 6109 |
## Smart pointers <a id="smartptr">[[smartptr]]</a>
|
| 6110 |
|
| 6111 |
### Class template `unique_ptr` <a id="unique.ptr">[[unique.ptr]]</a>
|
| 6112 |
|
| 6113 |
A *unique pointer* is an object that owns another object and manages
|
| 6114 |
that other object through a pointer. More precisely, a unique pointer is
|
| 6115 |
an object *u* that stores a pointer to a second object *p* and will
|
| 6116 |
dispose of *p* when *u* is itself destroyed (e.g., when leaving block
|
| 6117 |
-
scope
|
| 6118 |
|
| 6119 |
The mechanism by which *u* disposes of *p* is known as *p*’s associated
|
| 6120 |
*deleter*, a function object whose correct invocation results in *p*’s
|
| 6121 |
appropriate disposition (typically its deletion).
|
| 6122 |
|
| 6123 |
Let the notation *u.p* denote the pointer stored by *u*, and let *u.d*
|
| 6124 |
denote the associated deleter. Upon request, *u* can *reset* (replace)
|
| 6125 |
-
*u.p* and *u.d* with another pointer and deleter, but
|
| 6126 |
-
|
| 6127 |
-
|
| 6128 |
-
|
| 6129 |
-
Additionally, *u* can, upon request, *transfer ownership* to another
|
| 6130 |
-
unique pointer *u2*. Upon completion of such a transfer, the following
|
| 6131 |
-
postconditions hold:
|
| 6132 |
-
|
| 6133 |
-
- *u2.p* is equal to the pre-transfer *u.p*,
|
| 6134 |
-
- *u.p* is equal to `nullptr`, and
|
| 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
|
| 6149 |
-
but is not
|
| 6150 |
-
parameter `T` of `unique_ptr` may be
|
|
|
|
| 6151 |
|
| 6152 |
-
[*Note
|
| 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[]>;
|
| 6161 |
-
|
| 6162 |
-
template<class T, class D = default_delete<T>> class unique_ptr;
|
| 6163 |
-
template<class T, class D> class unique_ptr<T[], D>;
|
| 6164 |
-
|
| 6165 |
-
template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
|
| 6166 |
-
template<class T> unique_ptr<T> make_unique(size_t n);
|
| 6167 |
-
template<class T, class... Args> unspecified make_unique(Args&&...) = delete;
|
| 6168 |
-
|
| 6169 |
-
template<class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
|
| 6170 |
-
|
| 6171 |
-
template<class T1, class D1, class T2, class D2>
|
| 6172 |
-
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6173 |
-
template<class T1, class D1, class T2, class D2>
|
| 6174 |
-
bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6175 |
-
template<class T1, class D1, class T2, class D2>
|
| 6176 |
-
bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6177 |
-
template<class T1, class D1, class T2, class D2>
|
| 6178 |
-
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6179 |
-
template<class T1, class D1, class T2, class D2>
|
| 6180 |
-
bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6181 |
-
template<class T1, class D1, class T2, class D2>
|
| 6182 |
-
bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6183 |
-
|
| 6184 |
-
template <class T, class D>
|
| 6185 |
-
bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
|
| 6186 |
-
template <class T, class D>
|
| 6187 |
-
bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
|
| 6188 |
-
template <class T, class D>
|
| 6189 |
-
bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
|
| 6190 |
-
template <class T, class D>
|
| 6191 |
-
bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
|
| 6192 |
-
template <class T, class D>
|
| 6193 |
-
bool operator<(const unique_ptr<T, D>& x, nullptr_t);
|
| 6194 |
-
template <class T, class D>
|
| 6195 |
-
bool operator<(nullptr_t, const unique_ptr<T, D>& y);
|
| 6196 |
-
template <class T, class D>
|
| 6197 |
-
bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
|
| 6198 |
-
template <class T, class D>
|
| 6199 |
-
bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
|
| 6200 |
-
template <class T, class D>
|
| 6201 |
-
bool operator>(const unique_ptr<T, D>& x, nullptr_t);
|
| 6202 |
-
template <class T, class D>
|
| 6203 |
-
bool operator>(nullptr_t, const unique_ptr<T, D>& y);
|
| 6204 |
-
template <class T, class D>
|
| 6205 |
-
bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
|
| 6206 |
-
template <class T, class D>
|
| 6207 |
-
bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
|
| 6208 |
-
|
| 6209 |
-
}
|
| 6210 |
-
```
|
| 6211 |
-
|
| 6212 |
#### Default deleters <a id="unique.ptr.dltr">[[unique.ptr.dltr]]</a>
|
| 6213 |
|
| 6214 |
##### In general <a id="unique.ptr.dltr.general">[[unique.ptr.dltr.general]]</a>
|
| 6215 |
|
| 6216 |
The class template `default_delete` serves as the default deleter
|
|
@@ -6233,24 +6087,23 @@ namespace std {
|
|
| 6233 |
|
| 6234 |
``` cpp
|
| 6235 |
template<class U> default_delete(const default_delete<U>& other) noexcept;
|
| 6236 |
```
|
| 6237 |
|
|
|
|
|
|
|
| 6238 |
*Effects:* Constructs a `default_delete` object from another
|
| 6239 |
`default_delete<U>` object.
|
| 6240 |
|
| 6241 |
-
*Remarks:* This constructor shall not participate in overload resolution
|
| 6242 |
-
unless `U*` is implicitly convertible to `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[]> {
|
|
@@ -6263,26 +6116,25 @@ namespace std {
|
|
| 6263 |
|
| 6264 |
``` cpp
|
| 6265 |
template<class U> default_delete(const default_delete<U[]>& other) noexcept;
|
| 6266 |
```
|
| 6267 |
|
| 6268 |
-
*
|
|
|
|
|
|
|
| 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 {
|
|
@@ -6304,11 +6156,12 @@ namespace std {
|
|
| 6304 |
// [unique.ptr.single.dtor], destructor
|
| 6305 |
~unique_ptr();
|
| 6306 |
|
| 6307 |
// [unique.ptr.single.asgn], assignment
|
| 6308 |
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
| 6309 |
-
template
|
|
|
|
| 6310 |
unique_ptr& operator=(nullptr_t) noexcept;
|
| 6311 |
|
| 6312 |
// [unique.ptr.single.observers], observers
|
| 6313 |
add_lvalue_reference_t<T> operator*() const;
|
| 6314 |
pointer operator->() const noexcept;
|
|
@@ -6328,126 +6181,107 @@ namespace std {
|
|
| 6328 |
};
|
| 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]]
|
| 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
|
| 6341 |
-
requirements
|
| 6342 |
|
| 6343 |
If the *qualified-id* `remove_reference_t<D>::pointer` is valid and
|
| 6344 |
-
denotes a type
|
| 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
|
| 6349 |
-
[[
|
| 6350 |
|
| 6351 |
-
[*Example 1*: Given an allocator type `X`
|
| 6352 |
-
|
| 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 |
-
#####
|
| 6358 |
|
| 6359 |
``` cpp
|
| 6360 |
constexpr unique_ptr() noexcept;
|
| 6361 |
constexpr unique_ptr(nullptr_t) noexcept;
|
| 6362 |
```
|
| 6363 |
|
| 6364 |
-
*
|
| 6365 |
-
(
|
| 6366 |
-
|
|
|
|
|
|
|
|
|
|
| 6367 |
|
| 6368 |
*Effects:* Constructs a `unique_ptr` object that owns nothing,
|
| 6369 |
value-initializing the stored pointer and the stored deleter.
|
| 6370 |
|
| 6371 |
-
*
|
| 6372 |
-
|
| 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 |
-
*
|
| 6383 |
-
|
| 6384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 6390 |
-
|
| 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
|
| 6410 |
-
unique_ptr(pointer p,
|
| 6411 |
```
|
| 6412 |
|
| 6413 |
-
|
| 6414 |
|
| 6415 |
-
|
| 6416 |
-
|
| 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 |
-
``
|
| 6423 |
-
|
| 6424 |
-
|
| 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 |
-
*
|
| 6432 |
-
|
|
|
|
| 6433 |
|
| 6434 |
-
*
|
| 6435 |
-
|
| 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
|
| 6448 |
-
unique_ptr<int, D> p2(new int, d); // D must be
|
| 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 |
|
|
@@ -6455,142 +6289,144 @@ unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object comb
|
|
| 6455 |
|
| 6456 |
``` cpp
|
| 6457 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 6458 |
```
|
| 6459 |
|
| 6460 |
-
*
|
| 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 |
-
*
|
| 6466 |
-
|
| 6467 |
-
|
| 6468 |
-
|
| 6469 |
|
| 6470 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6471 |
`std::forward<D>`. — *end note*]
|
| 6472 |
|
| 6473 |
-
*
|
| 6474 |
-
construction. `get_deleter()` returns a reference
|
| 6475 |
-
that was constructed from `u.get_deleter()`. If
|
| 6476 |
-
then `get_deleter()` and `u.get_deleter()` both
|
| 6477 |
-
lvalue deleter.
|
| 6478 |
|
| 6479 |
``` cpp
|
| 6480 |
template<class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
| 6481 |
```
|
| 6482 |
|
| 6483 |
-
*
|
| 6484 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6485 |
exception. Otherwise, `E` is a reference type and construction of the
|
| 6486 |
-
deleter from an lvalue of type `E`
|
| 6487 |
-
|
| 6488 |
|
| 6489 |
-
*
|
| 6490 |
-
|
| 6491 |
-
|
| 6492 |
-
- `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
|
| 6493 |
-
- `U` is not an array type, and
|
| 6494 |
-
- either `D` is a reference type and `E` is the same type as `D`, or `D`
|
| 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 |
-
*
|
| 6506 |
-
construction. `get_deleter()` returns a reference
|
| 6507 |
-
that was constructed from `u.get_deleter()`.
|
| 6508 |
|
| 6509 |
-
#####
|
| 6510 |
|
| 6511 |
``` cpp
|
| 6512 |
~unique_ptr();
|
| 6513 |
```
|
| 6514 |
|
| 6515 |
-
*
|
| 6516 |
-
|
| 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 |
-
#####
|
| 6525 |
|
| 6526 |
``` cpp
|
| 6527 |
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
| 6528 |
```
|
| 6529 |
|
| 6530 |
-
*
|
| 6531 |
-
|
| 6532 |
-
|
|
|
|
|
|
|
| 6533 |
exception. Otherwise, `D` is a reference type; `remove_reference_t<D>`
|
| 6534 |
-
|
| 6535 |
-
deleter from an lvalue of type `D`
|
| 6536 |
|
| 6537 |
-
*Effects:*
|
| 6538 |
-
`reset(u.release())` followed by
|
| 6539 |
`get_deleter() = std::forward<D>(u.get_deleter())`.
|
| 6540 |
|
| 6541 |
*Returns:* `*this`.
|
| 6542 |
|
|
|
|
|
|
|
| 6543 |
``` cpp
|
| 6544 |
template<class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
|
| 6545 |
```
|
| 6546 |
|
| 6547 |
-
*
|
| 6548 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6549 |
exception. Otherwise, `E` is a reference type and assignment of the
|
| 6550 |
-
deleter from an lvalue of type `E`
|
| 6551 |
-
|
| 6552 |
|
| 6553 |
-
*
|
| 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 |
|
| 6565 |
*Returns:* `*this`.
|
| 6566 |
|
|
|
|
|
|
|
| 6567 |
``` cpp
|
| 6568 |
unique_ptr& operator=(nullptr_t) noexcept;
|
| 6569 |
```
|
| 6570 |
|
| 6571 |
*Effects:* As if by `reset()`.
|
| 6572 |
|
| 6573 |
-
*
|
| 6574 |
|
| 6575 |
*Returns:* `*this`.
|
| 6576 |
|
| 6577 |
-
#####
|
| 6578 |
|
| 6579 |
``` cpp
|
| 6580 |
add_lvalue_reference_t<T> operator*() const;
|
| 6581 |
```
|
| 6582 |
|
| 6583 |
-
*
|
| 6584 |
|
| 6585 |
*Returns:* `*get()`.
|
| 6586 |
|
| 6587 |
``` cpp
|
| 6588 |
pointer operator->() const noexcept;
|
| 6589 |
```
|
| 6590 |
|
| 6591 |
-
*
|
| 6592 |
|
| 6593 |
*Returns:* `get()`.
|
| 6594 |
|
| 6595 |
[*Note 4*: The use of this function typically requires that `T` be a
|
| 6596 |
complete type. — *end note*]
|
|
@@ -6612,47 +6448,46 @@ const deleter_type& get_deleter() const noexcept;
|
|
| 6612 |
explicit operator bool() const noexcept;
|
| 6613 |
```
|
| 6614 |
|
| 6615 |
*Returns:* `get() != nullptr`.
|
| 6616 |
|
| 6617 |
-
#####
|
| 6618 |
|
| 6619 |
``` cpp
|
| 6620 |
pointer release() noexcept;
|
| 6621 |
```
|
| 6622 |
|
| 6623 |
-
*
|
| 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 |
-
*
|
| 6632 |
-
|
| 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 |
-
*
|
| 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 |
|
| 6651 |
-
*
|
| 6652 |
-
|
| 6653 |
-
under `swap`.
|
| 6654 |
|
| 6655 |
*Effects:* Invokes `swap` on the stored pointers and on the stored
|
| 6656 |
deleters of `*this` and `u`.
|
| 6657 |
|
| 6658 |
#### `unique_ptr` for array objects with a runtime length <a id="unique.ptr.runtime">[[unique.ptr.runtime]]</a>
|
|
@@ -6720,19 +6555,20 @@ interface.
|
|
| 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 |
-
#####
|
| 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`
|
| 6733 |
-
|
|
|
|
| 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 |
|
|
@@ -6740,70 +6576,68 @@ additionally shall not participate in overload resolution unless
|
|
| 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 |
-
|
| 6747 |
-
|
| 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
|
| 6756 |
-
unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
| 6757 |
```
|
| 6758 |
|
| 6759 |
-
This constructor behaves the same as in the primary template
|
| 6760 |
-
|
| 6761 |
-
|
| 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
|
| 6771 |
-
primary template — *end note*]
|
| 6772 |
|
| 6773 |
-
#####
|
| 6774 |
|
| 6775 |
``` cpp
|
| 6776 |
-
template
|
| 6777 |
-
unique_ptr& operator=(unique_ptr<U, E>&& u)noexcept;
|
| 6778 |
```
|
| 6779 |
|
| 6780 |
-
This operator behaves the same as in the primary template
|
| 6781 |
-
|
| 6782 |
-
|
| 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
|
| 6791 |
-
primary template — *end note*]
|
| 6792 |
|
| 6793 |
-
#####
|
| 6794 |
|
| 6795 |
``` cpp
|
| 6796 |
T& operator[](size_t i) const;
|
| 6797 |
```
|
| 6798 |
|
| 6799 |
-
*
|
| 6800 |
stored pointer points.
|
| 6801 |
|
| 6802 |
*Returns:* `get()[i]`.
|
| 6803 |
|
| 6804 |
-
#####
|
| 6805 |
|
| 6806 |
``` cpp
|
| 6807 |
void reset(nullptr_t p = nullptr) noexcept;
|
| 6808 |
```
|
| 6809 |
|
|
@@ -6812,145 +6646,165 @@ void reset(nullptr_t p = nullptr) noexcept;
|
|
| 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
|
| 6818 |
-
|
|
|
|
| 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 |
-
####
|
| 6825 |
|
| 6826 |
``` cpp
|
| 6827 |
template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
|
| 6828 |
```
|
| 6829 |
|
| 6830 |
-
*
|
| 6831 |
-
unless `T` is not an array.
|
| 6832 |
|
| 6833 |
*Returns:* `unique_ptr<T>(new T(std::forward<Args>(args)...))`.
|
| 6834 |
|
| 6835 |
``` cpp
|
| 6836 |
template<class T> unique_ptr<T> make_unique(size_t n);
|
| 6837 |
```
|
| 6838 |
|
| 6839 |
-
*
|
| 6840 |
-
unless `T` is an array of unknown bound.
|
| 6841 |
|
| 6842 |
*Returns:* `unique_ptr<T>(new remove_extent_t<T>[n]())`.
|
| 6843 |
|
| 6844 |
``` cpp
|
| 6845 |
template<class T, class... Args> unspecified make_unique(Args&&...) = delete;
|
| 6846 |
```
|
| 6847 |
|
| 6848 |
-
*
|
| 6849 |
-
unless `T` is an array of known bound.
|
| 6850 |
|
| 6851 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 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);
|
| 6865 |
```
|
| 6866 |
|
| 6867 |
*Returns:* `x.get() == y.get()`.
|
| 6868 |
|
| 6869 |
-
``` cpp
|
| 6870 |
-
template <class T1, class D1, class T2, class D2>
|
| 6871 |
-
bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6872 |
-
```
|
| 6873 |
-
|
| 6874 |
-
*Returns:* `x.get() != y.get()`.
|
| 6875 |
-
|
| 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 |
-
|
| 6882 |
|
| 6883 |
``` cpp
|
| 6884 |
common_type_t<typename unique_ptr<T1, D1>::pointer,
|
| 6885 |
typename unique_ptr<T2, D2>::pointer>
|
| 6886 |
```
|
| 6887 |
|
| 6888 |
-
|
| 6889 |
-
type ([[function.objects]]) that induces a strict weak
|
| 6890 |
-
ordering ([[alg.sorting]]) on the pointer values.
|
| 6891 |
|
| 6892 |
-
|
|
|
|
| 6893 |
|
| 6894 |
-
*
|
| 6895 |
-
|
| 6896 |
-
|
| 6897 |
|
| 6898 |
-
`
|
| 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 |
-
```
|
| 6902 |
-
|
| 6903 |
-
*Returns:* `!(y < x)`.
|
| 6904 |
|
| 6905 |
``` cpp
|
| 6906 |
template<class T1, class D1, class T2, class D2>
|
| 6907 |
bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6908 |
```
|
| 6909 |
|
| 6910 |
*Returns:* `y < x`.
|
| 6911 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6912 |
``` cpp
|
| 6913 |
template<class T1, class D1, class T2, class D2>
|
| 6914 |
bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6915 |
```
|
| 6916 |
|
| 6917 |
*Returns:* `!(x < y)`.
|
| 6918 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6919 |
``` cpp
|
| 6920 |
template<class T, class D>
|
| 6921 |
bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
|
| 6922 |
-
template <class T, class D>
|
| 6923 |
-
bool operator==(nullptr_t, const unique_ptr<T, D>& x) noexcept;
|
| 6924 |
```
|
| 6925 |
|
| 6926 |
*Returns:* `!x`.
|
| 6927 |
|
| 6928 |
-
``` cpp
|
| 6929 |
-
template <class T, class D>
|
| 6930 |
-
bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
|
| 6931 |
-
template <class T, class D>
|
| 6932 |
-
bool operator!=(nullptr_t, const unique_ptr<T, D>& x) noexcept;
|
| 6933 |
-
```
|
| 6934 |
-
|
| 6935 |
-
*Returns:* `(bool)x`.
|
| 6936 |
-
|
| 6937 |
``` cpp
|
| 6938 |
template<class T, class D>
|
| 6939 |
bool operator<(const unique_ptr<T, D>& x, nullptr_t);
|
| 6940 |
template<class T, class D>
|
| 6941 |
bool operator<(nullptr_t, const unique_ptr<T, D>& x);
|
| 6942 |
```
|
| 6943 |
|
| 6944 |
-
*
|
| 6945 |
-
|
| 6946 |
-
|
| 6947 |
|
| 6948 |
*Returns:* The first function template returns
|
| 6949 |
-
|
| 6950 |
-
`
|
| 6951 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6952 |
|
| 6953 |
``` cpp
|
| 6954 |
template<class T, class D>
|
| 6955 |
bool operator>(const unique_ptr<T, D>& x, nullptr_t);
|
| 6956 |
template<class T, class D>
|
|
@@ -6978,33 +6832,54 @@ template <class T, class D>
|
|
| 6978 |
```
|
| 6979 |
|
| 6980 |
*Returns:* The first function template returns `!(x < nullptr)`. The
|
| 6981 |
second function template returns `!(nullptr < x)`.
|
| 6982 |
|
| 6983 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6984 |
|
| 6985 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6986 |
|
| 6987 |
``` cpp
|
| 6988 |
namespace std {
|
| 6989 |
class bad_weak_ptr : public exception {
|
| 6990 |
public:
|
| 6991 |
-
|
|
|
|
| 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 |
-
|
| 7001 |
```
|
| 7002 |
|
| 7003 |
-
*
|
| 7004 |
|
| 7005 |
-
###
|
| 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.
|
|
@@ -7017,130 +6892,88 @@ namespace std {
|
|
| 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>
|
|
|
|
| 7042 |
shared_ptr& operator=(shared_ptr&& r) noexcept;
|
| 7043 |
-
template<class Y>
|
| 7044 |
-
|
|
|
|
|
|
|
| 7045 |
|
| 7046 |
// [util.smartptr.shared.mod], modifiers
|
| 7047 |
void swap(shared_ptr& r) noexcept;
|
| 7048 |
void reset() noexcept;
|
| 7049 |
-
template<class Y>
|
| 7050 |
-
|
| 7051 |
-
template<class Y, class D
|
|
|
|
|
|
|
|
|
|
| 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>
|
| 7061 |
-
|
|
|
|
|
|
|
| 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>
|
| 7079 |
-
bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 7080 |
-
template<class T, class U>
|
| 7081 |
-
bool operator>(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 7082 |
-
template<class T, class U>
|
| 7083 |
-
bool operator<=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 7084 |
-
template<class T, class U>
|
| 7085 |
-
bool operator>=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 7086 |
-
|
| 7087 |
template<class T>
|
| 7088 |
-
|
| 7089 |
-
template
|
| 7090 |
-
|
| 7091 |
-
template <class T>
|
| 7092 |
-
bool operator!=(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 7093 |
-
template <class T>
|
| 7094 |
-
bool operator!=(nullptr_t, const shared_ptr<T>& b) noexcept;
|
| 7095 |
-
template <class T>
|
| 7096 |
-
bool operator<(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 7097 |
-
template <class T>
|
| 7098 |
-
bool operator<(nullptr_t, const shared_ptr<T>& b) noexcept;
|
| 7099 |
-
template <class T>
|
| 7100 |
-
bool operator<=(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 7101 |
-
template <class T>
|
| 7102 |
-
bool operator<=(nullptr_t, const shared_ptr<T>& b) noexcept;
|
| 7103 |
-
template <class T>
|
| 7104 |
-
bool operator>(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 7105 |
-
template <class T>
|
| 7106 |
-
bool operator>(nullptr_t, const shared_ptr<T>& b) noexcept;
|
| 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
|
| 7137 |
-
|
| 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.
|
| 7141 |
-
|
|
|
|
|
|
|
|
|
|
| 7142 |
|
| 7143 |
[*Example 1*:
|
| 7144 |
|
| 7145 |
``` cpp
|
| 7146 |
if (shared_ptr<X> px = dynamic_pointer_cast<X>(py)) {
|
|
@@ -7154,173 +6987,168 @@ 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 [[
|
| 7160 |
-
|
| 7161 |
convertible to `T*` or `Y` is `U[N]` and `T` is cv `U[]`.
|
| 7162 |
|
| 7163 |
-
####
|
| 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`
|
| 7169 |
-
|
| 7170 |
-
|
| 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 |
-
*
|
| 7186 |
-
|
| 7187 |
-
*Postconditions:* `use_count() == 0 && get() == nullptr`.
|
| 7188 |
|
| 7189 |
``` cpp
|
| 7190 |
template<class Y> explicit shared_ptr(Y* p);
|
| 7191 |
```
|
| 7192 |
|
| 7193 |
-
*
|
| 7194 |
-
|
| 7195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 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 |
-
*
|
| 7225 |
-
|
| 7226 |
-
|
| 7227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 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 |
-
*
|
|
|
|
| 7257 |
|
| 7258 |
[*Note 1*: To avoid the possibility of a dangling pointer, the user of
|
| 7259 |
-
this constructor
|
| 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 |
-
*
|
| 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 |
-
*
|
| 7278 |
|
| 7279 |
``` cpp
|
| 7280 |
shared_ptr(shared_ptr&& r) noexcept;
|
| 7281 |
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
|
| 7282 |
```
|
| 7283 |
|
| 7284 |
-
*
|
| 7285 |
-
resolution unless `Y*` is compatible with `T*`.
|
| 7286 |
|
| 7287 |
*Effects:* Move constructs a `shared_ptr` instance from `r`.
|
| 7288 |
|
| 7289 |
-
*
|
| 7290 |
-
|
| 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 |
-
*
|
| 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 |
-
*
|
| 7312 |
-
|
| 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 |
-
####
|
| 7322 |
|
| 7323 |
``` cpp
|
| 7324 |
~shared_ptr();
|
| 7325 |
```
|
| 7326 |
|
|
@@ -7336,22 +7164,22 @@ thrown, the constructor has no effect.
|
|
| 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 |
-
####
|
| 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
|
| 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:
|
|
@@ -7382,11 +7210,11 @@ template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
|
|
| 7382 |
|
| 7383 |
*Effects:* Equivalent to `shared_ptr(std::move(r)).swap(*this)`.
|
| 7384 |
|
| 7385 |
*Returns:* `*this`.
|
| 7386 |
|
| 7387 |
-
####
|
| 7388 |
|
| 7389 |
``` cpp
|
| 7390 |
void swap(shared_ptr& r) noexcept;
|
| 7391 |
```
|
| 7392 |
|
|
@@ -7414,11 +7242,11 @@ template<class Y, class D> void reset(Y* p, D d);
|
|
| 7414 |
template<class Y, class D, class A> void reset(Y* p, D d, A a);
|
| 7415 |
```
|
| 7416 |
|
| 7417 |
*Effects:* Equivalent to `shared_ptr(p, d, a).swap(*this)`.
|
| 7418 |
|
| 7419 |
-
####
|
| 7420 |
|
| 7421 |
``` cpp
|
| 7422 |
element_type* get() const noexcept;
|
| 7423 |
```
|
| 7424 |
|
|
@@ -7426,45 +7254,45 @@ element_type* get() const noexcept;
|
|
| 7426 |
|
| 7427 |
``` cpp
|
| 7428 |
T& operator*() const noexcept;
|
| 7429 |
```
|
| 7430 |
|
| 7431 |
-
*
|
| 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
|
| 7439 |
-
formed.
|
| 7440 |
|
| 7441 |
``` cpp
|
| 7442 |
T* operator->() const noexcept;
|
| 7443 |
```
|
| 7444 |
|
| 7445 |
-
*
|
| 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
|
| 7453 |
|
| 7454 |
``` cpp
|
| 7455 |
element_type& operator[](ptrdiff_t i) const;
|
| 7456 |
```
|
| 7457 |
|
| 7458 |
-
*
|
| 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
|
| 7466 |
|
| 7467 |
*Throws:* Nothing.
|
| 7468 |
|
| 7469 |
``` cpp
|
| 7470 |
long use_count() const noexcept;
|
|
@@ -7473,17 +7301,17 @@ long use_count() const noexcept;
|
|
| 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
|
| 7479 |
`use_count()`. — *end note*]
|
| 7480 |
|
| 7481 |
-
[*Note
|
| 7482 |
`use_count()`. — *end note*]
|
| 7483 |
|
| 7484 |
-
[*Note
|
| 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 |
|
|
@@ -7505,217 +7333,425 @@ template<class U> bool owner_before(const weak_ptr<U>& b) const noexcept;
|
|
| 7505 |
- under the equivalence relation defined by `owner_before`,
|
| 7506 |
`!a.owner_before(b) && !b.owner_before(a)`, two `shared_ptr` or
|
| 7507 |
`weak_ptr` instances are equivalent if and only if they share
|
| 7508 |
ownership or are both empty.
|
| 7509 |
|
| 7510 |
-
####
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7511 |
|
| 7512 |
``` cpp
|
| 7513 |
-
template<class T,
|
| 7514 |
-
shared_ptr<T> make_shared(
|
| 7515 |
-
template<class T, class A,
|
| 7516 |
-
shared_ptr<T> allocate_shared(const A& a,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7517 |
```
|
| 7518 |
|
| 7519 |
-
*
|
| 7520 |
-
|
| 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
|
| 7526 |
-
|
| 7527 |
-
|
| 7528 |
-
|
| 7529 |
-
|
|
|
|
|
|
|
| 7530 |
|
| 7531 |
*Returns:* A `shared_ptr` instance that stores and owns the address of
|
| 7532 |
-
the newly constructed object
|
| 7533 |
|
| 7534 |
-
*
|
|
|
|
| 7535 |
|
| 7536 |
-
*Throws:* `bad_alloc`, or an exception thrown from `
|
| 7537 |
-
the
|
| 7538 |
|
| 7539 |
-
*Remarks:*
|
| 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 |
-
|
|
|
|
| 7545 |
pointer. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7546 |
|
| 7547 |
-
|
| 7548 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7549 |
reference counts. — *end note*]
|
| 7550 |
|
| 7551 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>
|
| 7574 |
-
bool operator==(nullptr_t, const shared_ptr<T>& a) noexcept;
|
| 7575 |
```
|
| 7576 |
|
| 7577 |
*Returns:* `!a`.
|
| 7578 |
|
| 7579 |
``` cpp
|
| 7580 |
-
template
|
| 7581 |
-
|
| 7582 |
-
template <class T>
|
| 7583 |
-
bool operator!=(nullptr_t, const shared_ptr<T>& a) noexcept;
|
| 7584 |
-
```
|
| 7585 |
-
|
| 7586 |
-
*Returns:* `(bool)a`.
|
| 7587 |
-
|
| 7588 |
-
``` cpp
|
| 7589 |
-
template <class T>
|
| 7590 |
-
bool operator<(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 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>
|
| 7604 |
-
bool operator>(nullptr_t, const shared_ptr<T>& a) noexcept;
|
| 7605 |
```
|
| 7606 |
|
| 7607 |
-
*Returns:*
|
| 7608 |
-
function template returns `a < nullptr`.
|
| 7609 |
-
|
| 7610 |
-
``` cpp
|
| 7611 |
-
template <class T>
|
| 7612 |
-
bool operator<=(const shared_ptr<T>& a, nullptr_t) noexcept;
|
| 7613 |
-
template <class T>
|
| 7614 |
-
bool operator<=(nullptr_t, const shared_ptr<T>& a) noexcept;
|
| 7615 |
-
```
|
| 7616 |
|
| 7617 |
-
*
|
| 7618 |
-
|
| 7619 |
|
| 7620 |
``` cpp
|
| 7621 |
template<class T>
|
| 7622 |
-
|
| 7623 |
-
template <class T>
|
| 7624 |
-
bool operator>=(nullptr_t, const shared_ptr<T>& a) noexcept;
|
| 7625 |
```
|
| 7626 |
|
| 7627 |
-
*Returns:*
|
| 7628 |
-
second function template returns `!(nullptr < a)`.
|
| 7629 |
|
| 7630 |
-
####
|
| 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 |
-
####
|
| 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 |
-
*
|
| 7647 |
-
formed.
|
| 7648 |
|
| 7649 |
*Returns:*
|
| 7650 |
|
| 7651 |
``` cpp
|
| 7652 |
-
shared_ptr<T>(
|
| 7653 |
```
|
| 7654 |
|
| 7655 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 7666 |
-
formed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7667 |
|
| 7668 |
*Returns:*
|
| 7669 |
|
| 7670 |
- When `dynamic_cast<typename shared_ptr<T>::element_type*>(r.get())`
|
| 7671 |
-
returns a
|
|
|
|
| 7672 |
- Otherwise, `shared_ptr<T>()`.
|
| 7673 |
|
| 7674 |
-
[*Note
|
| 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 |
-
*
|
| 7685 |
|
| 7686 |
*Returns:*
|
| 7687 |
|
| 7688 |
``` cpp
|
| 7689 |
-
shared_ptr<T>(
|
| 7690 |
```
|
| 7691 |
|
| 7692 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 7703 |
-
formed.
|
| 7704 |
|
| 7705 |
*Returns:*
|
| 7706 |
|
| 7707 |
``` cpp
|
| 7708 |
-
shared_ptr<T>(
|
| 7709 |
```
|
| 7710 |
|
| 7711 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
####
|
| 7717 |
|
| 7718 |
``` cpp
|
| 7719 |
template<class D, class T>
|
| 7720 |
D* get_deleter(const shared_ptr<T>& p) noexcept;
|
| 7721 |
```
|
|
@@ -7723,139 +7759,147 @@ template<class D, class T>
|
|
| 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
|
| 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 |
-
####
|
| 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 |
-
###
|
| 7745 |
|
| 7746 |
The `weak_ptr` class template stores a weak reference to an object that
|
| 7747 |
is already managed by a `shared_ptr`. To access the object, a `weak_ptr`
|
| 7748 |
can be converted to a `shared_ptr` using the member function `lock`.
|
| 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>
|
|
|
|
| 7759 |
weak_ptr(const weak_ptr& r) noexcept;
|
| 7760 |
-
template<class Y>
|
|
|
|
| 7761 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 7762 |
-
template<class Y>
|
|
|
|
| 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>
|
| 7770 |
-
|
|
|
|
|
|
|
| 7771 |
weak_ptr& operator=(weak_ptr&& r) noexcept;
|
| 7772 |
-
template<class Y>
|
|
|
|
| 7773 |
|
| 7774 |
// [util.smartptr.weak.mod], modifiers
|
| 7775 |
void swap(weak_ptr& r) noexcept;
|
| 7776 |
void reset() 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>
|
| 7783 |
-
|
|
|
|
|
|
|
| 7784 |
};
|
| 7785 |
|
| 7786 |
-
template<class T>
|
| 7787 |
-
|
| 7788 |
|
| 7789 |
// [util.smartptr.weak.spec], specialized algorithms
|
| 7790 |
-
template<class T>
|
|
|
|
| 7791 |
}
|
| 7792 |
```
|
| 7793 |
|
| 7794 |
-
Specializations of `weak_ptr` shall be
|
| 7795 |
-
|
| 7796 |
template parameter `T` of `weak_ptr` may be an incomplete type.
|
| 7797 |
|
| 7798 |
-
####
|
| 7799 |
|
| 7800 |
``` cpp
|
| 7801 |
constexpr weak_ptr() noexcept;
|
| 7802 |
```
|
| 7803 |
|
| 7804 |
*Effects:* Constructs an empty `weak_ptr` object.
|
| 7805 |
|
| 7806 |
-
*
|
| 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 |
-
*
|
| 7815 |
-
|
| 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 |
-
*
|
| 7822 |
|
| 7823 |
``` cpp
|
| 7824 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 7825 |
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
|
| 7826 |
```
|
| 7827 |
|
| 7828 |
-
*
|
| 7829 |
-
resolution unless `Y*` is compatible with `T*`.
|
| 7830 |
|
| 7831 |
*Effects:* Move constructs a `weak_ptr` instance from `r`.
|
| 7832 |
|
| 7833 |
-
*
|
| 7834 |
-
|
| 7835 |
|
| 7836 |
-
####
|
| 7837 |
|
| 7838 |
``` cpp
|
| 7839 |
~weak_ptr();
|
| 7840 |
```
|
| 7841 |
|
| 7842 |
*Effects:* Destroys this `weak_ptr` object but has no effect on the
|
| 7843 |
object its stored pointer points to.
|
| 7844 |
|
| 7845 |
-
####
|
| 7846 |
|
| 7847 |
``` cpp
|
| 7848 |
weak_ptr& operator=(const weak_ptr& r) noexcept;
|
| 7849 |
template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r) noexcept;
|
| 7850 |
template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 7851 |
```
|
| 7852 |
|
| 7853 |
*Effects:* Equivalent to `weak_ptr(r).swap(*this)`.
|
| 7854 |
|
| 7855 |
*Remarks:* The implementation may meet the effects (and the implied
|
| 7856 |
-
guarantees) via different means, without creating a temporary.
|
| 7857 |
|
| 7858 |
*Returns:* `*this`.
|
| 7859 |
|
| 7860 |
``` cpp
|
| 7861 |
weak_ptr& operator=(weak_ptr&& r) noexcept;
|
|
@@ -7864,11 +7908,11 @@ template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
|
|
| 7864 |
|
| 7865 |
*Effects:* Equivalent to `weak_ptr(std::move(r)).swap(*this)`.
|
| 7866 |
|
| 7867 |
*Returns:* `*this`.
|
| 7868 |
|
| 7869 |
-
####
|
| 7870 |
|
| 7871 |
``` cpp
|
| 7872 |
void swap(weak_ptr& r) noexcept;
|
| 7873 |
```
|
| 7874 |
|
|
@@ -7878,11 +7922,11 @@ void swap(weak_ptr& r) noexcept;
|
|
| 7878 |
void reset() noexcept;
|
| 7879 |
```
|
| 7880 |
|
| 7881 |
*Effects:* Equivalent to `weak_ptr().swap(*this)`.
|
| 7882 |
|
| 7883 |
-
####
|
| 7884 |
|
| 7885 |
``` cpp
|
| 7886 |
long use_count() const noexcept;
|
| 7887 |
```
|
| 7888 |
|
|
@@ -7901,12 +7945,12 @@ shared_ptr<T> lock() const noexcept;
|
|
| 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
|
|
@@ -7914,20 +7958,20 @@ template<class U> bool owner_before(const weak_ptr<U>& b) const;
|
|
| 7914 |
- under the equivalence relation defined by `owner_before`,
|
| 7915 |
`!a.owner_before(b) && !b.owner_before(a)`, two `shared_ptr` or
|
| 7916 |
`weak_ptr` instances are equivalent if and only if they share
|
| 7917 |
ownership or are both empty.
|
| 7918 |
|
| 7919 |
-
####
|
| 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 |
-
###
|
| 7929 |
|
| 7930 |
The class template `owner_less` allows ownership-based mixed comparisons
|
| 7931 |
of shared and weak pointers.
|
| 7932 |
|
| 7933 |
``` cpp
|
|
@@ -7959,11 +8003,11 @@ namespace std {
|
|
| 7959 |
using is_transparent = unspecified;
|
| 7960 |
};
|
| 7961 |
}
|
| 7962 |
```
|
| 7963 |
|
| 7964 |
-
`operator()(x, y)`
|
| 7965 |
|
| 7966 |
[*Note 1*:
|
| 7967 |
|
| 7968 |
Note that
|
| 7969 |
|
|
@@ -7974,11 +8018,11 @@ Note that
|
|
| 7974 |
`weak_ptr` instances are equivalent if and only if they share
|
| 7975 |
ownership or are both empty.
|
| 7976 |
|
| 7977 |
— *end note*]
|
| 7978 |
|
| 7979 |
-
###
|
| 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 |
|
|
@@ -8003,15 +8047,17 @@ namespace std {
|
|
| 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 |
```
|
|
@@ -8046,179 +8092,28 @@ 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 |
-
###
|
| 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
|
| 8055 |
-
functions in this section and the instance is passed as their first
|
| 8056 |
-
argument.
|
| 8057 |
-
|
| 8058 |
-
The meaning of the arguments of type `memory_order` is explained in
|
| 8059 |
-
[[atomics.order]].
|
| 8060 |
-
|
| 8061 |
-
``` cpp
|
| 8062 |
-
template<class T>
|
| 8063 |
-
bool atomic_is_lock_free(const shared_ptr<T>* p);
|
| 8064 |
-
```
|
| 8065 |
-
|
| 8066 |
-
*Requires:* `p` shall not be null.
|
| 8067 |
-
|
| 8068 |
-
*Returns:* `true` if atomic access to `*p` is lock-free, `false`
|
| 8069 |
-
otherwise.
|
| 8070 |
-
|
| 8071 |
-
*Throws:* Nothing.
|
| 8072 |
-
|
| 8073 |
-
``` cpp
|
| 8074 |
-
template<class T>
|
| 8075 |
-
shared_ptr<T> atomic_load(const shared_ptr<T>* p);
|
| 8076 |
-
```
|
| 8077 |
-
|
| 8078 |
-
*Requires:* `p` shall not be null.
|
| 8079 |
-
|
| 8080 |
-
*Returns:* `atomic_load_explicit(p, memory_order_seq_cst)`.
|
| 8081 |
-
|
| 8082 |
-
*Throws:* Nothing.
|
| 8083 |
-
|
| 8084 |
-
``` cpp
|
| 8085 |
-
template<class T>
|
| 8086 |
-
shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
|
| 8087 |
-
```
|
| 8088 |
-
|
| 8089 |
-
*Requires:* `p` shall not be null.
|
| 8090 |
-
|
| 8091 |
-
*Requires:* `mo` shall not be `memory_order_release` or
|
| 8092 |
-
`memory_order_acq_rel`.
|
| 8093 |
-
|
| 8094 |
-
*Returns:* `*p`.
|
| 8095 |
-
|
| 8096 |
-
*Throws:* Nothing.
|
| 8097 |
-
|
| 8098 |
-
``` cpp
|
| 8099 |
-
template<class T>
|
| 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>
|
| 8111 |
-
void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
|
| 8112 |
-
```
|
| 8113 |
-
|
| 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>
|
| 8125 |
-
shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
|
| 8126 |
-
```
|
| 8127 |
-
|
| 8128 |
-
*Requires:* `p` shall not be null.
|
| 8129 |
-
|
| 8130 |
-
*Returns:* `atomic_exchange_explicit(p, r, memory_order_seq_cst)`.
|
| 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,
|
| 8177 |
-
memory_order success, memory_order failure);
|
| 8178 |
-
template<class T>
|
| 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
|
| 8209 |
enabled. When enabled, for an object `p` of type `UP`, `hash<UP>()(p)`
|
| 8210 |
-
|
| 8211 |
-
|
| 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 |
-
|
| 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>
|
|
@@ -8227,21 +8122,17 @@ shall evaluate to the same value as
|
|
| 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;
|
|
@@ -8259,80 +8150,84 @@ namespace std::pmr {
|
|
| 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 |
-
|
|
|
|
|
|
|
| 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 |
-
####
|
| 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
|
| 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 |
-
####
|
| 8310 |
|
| 8311 |
``` cpp
|
| 8312 |
virtual void* do_allocate(size_t bytes, size_t alignment) = 0;
|
| 8313 |
```
|
| 8314 |
|
| 8315 |
-
*
|
| 8316 |
|
| 8317 |
*Returns:* A derived class shall implement this function to return a
|
| 8318 |
-
pointer to allocated storage
|
| 8319 |
-
|
| 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 |
-
*
|
| 8332 |
`allocate(bytes, alignment)` on a memory resource equal to `*this`, and
|
| 8333 |
-
the storage at `p`
|
| 8334 |
|
| 8335 |
*Effects:* A derived class shall implement this function to dispose of
|
| 8336 |
allocated storage.
|
| 8337 |
|
| 8338 |
*Throws:* Nothing.
|
|
@@ -8344,42 +8239,40 @@ virtual bool do_is_equal(const memory_resource& other) const noexcept = 0;
|
|
| 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`,
|
| 8350 |
-
|
| 8351 |
`dynamic_cast<const D*>(&other) == nullptr`. — *end note*]
|
| 8352 |
|
| 8353 |
-
####
|
| 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`
|
| 8370 |
-
|
| 8371 |
-
|
| 8372 |
-
|
| 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 |
-
|
| 8380 |
-
class polymorphic_allocator {
|
| 8381 |
memory_resource* memory_rsrc; // exposition only
|
| 8382 |
|
| 8383 |
public:
|
| 8384 |
using value_type = Tp;
|
| 8385 |
|
|
@@ -8390,42 +8283,37 @@ public:
|
|
| 8390 |
polymorphic_allocator(const polymorphic_allocator& other) = default;
|
| 8391 |
|
| 8392 |
template<class U>
|
| 8393 |
polymorphic_allocator(const polymorphic_allocator<U>& other) noexcept;
|
| 8394 |
|
| 8395 |
-
|
| 8396 |
-
operator=(const polymorphic_allocator& rhs) = delete;
|
| 8397 |
|
| 8398 |
// [mem.poly.allocator.mem], member functions
|
| 8399 |
-
|
| 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 |
-
####
|
| 8427 |
|
| 8428 |
``` cpp
|
| 8429 |
polymorphic_allocator() noexcept;
|
| 8430 |
```
|
| 8431 |
|
|
@@ -8433,171 +8321,143 @@ polymorphic_allocator() noexcept;
|
|
| 8433 |
|
| 8434 |
``` cpp
|
| 8435 |
polymorphic_allocator(memory_resource* r);
|
| 8436 |
```
|
| 8437 |
|
| 8438 |
-
*
|
| 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
|
| 8449 |
-
polymorphic_allocator(const polymorphic_allocator<U>& other) noexcept;
|
| 8450 |
```
|
| 8451 |
|
| 8452 |
*Effects:* Sets `memory_rsrc` to `other.resource()`.
|
| 8453 |
|
| 8454 |
-
####
|
| 8455 |
|
| 8456 |
``` cpp
|
| 8457 |
-
Tp* allocate(size_t n);
|
| 8458 |
```
|
| 8459 |
|
| 8460 |
-
*
|
|
|
|
| 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 |
-
*
|
| 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 |
-
*
|
| 8484 |
-
|
| 8485 |
-
|
| 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 |
-
|
| 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 |
|
|
@@ -8615,28 +8475,20 @@ polymorphic_allocator select_on_container_copy_construction() const;
|
|
| 8615 |
memory_resource* resource() const;
|
| 8616 |
```
|
| 8617 |
|
| 8618 |
*Returns:* `memory_rsrc`.
|
| 8619 |
|
| 8620 |
-
####
|
| 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 |
```
|
|
@@ -8668,12 +8520,10 @@ memory_resource* set_default_resource(memory_resource* r) noexcept;
|
|
| 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
|
|
@@ -8719,19 +8569,19 @@ 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 |
-
|
| 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) {}
|
|
@@ -8739,12 +8589,11 @@ public:
|
|
| 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 |
-
|
| 8745 |
-
operator=(const synchronized_pool_resource&) = delete;
|
| 8746 |
|
| 8747 |
void release();
|
| 8748 |
memory_resource* upstream_resource() const;
|
| 8749 |
pool_options options() const;
|
| 8750 |
|
|
@@ -8755,12 +8604,11 @@ protected:
|
|
| 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 |
-
|
| 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) {}
|
|
@@ -8768,12 +8616,11 @@ public:
|
|
| 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 |
-
|
| 8774 |
-
operator=(const unsynchronized_pool_resource&) = delete;
|
| 8775 |
|
| 8776 |
void release();
|
| 8777 |
memory_resource* upstream_resource() const;
|
| 8778 |
pool_options options() const;
|
| 8779 |
|
|
@@ -8781,10 +8628,11 @@ 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
|
|
@@ -8794,11 +8642,11 @@ is described below:
|
|
| 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
|
| 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 |
|
|
@@ -8812,18 +8660,18 @@ 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 |
-
####
|
| 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 |
-
*
|
| 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
|
|
@@ -8845,11 +8693,11 @@ virtual ~synchronized_pool_resource();
|
|
| 8845 |
virtual ~unsynchronized_pool_resource();
|
| 8846 |
```
|
| 8847 |
|
| 8848 |
*Effects:* Calls `release()`.
|
| 8849 |
|
| 8850 |
-
####
|
| 8851 |
|
| 8852 |
``` cpp
|
| 8853 |
void release();
|
| 8854 |
```
|
| 8855 |
|
|
@@ -8879,14 +8727,15 @@ 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
|
| 8885 |
-
|
| 8886 |
-
The size and alignment of the allocated memory shall meet the
|
| 8887 |
-
requirements for a class derived from `memory_resource`
|
|
|
|
| 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
|
|
@@ -8903,24 +8752,14 @@ 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
|
| 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
|
|
@@ -8940,20 +8779,20 @@ memory resource object is destroyed. It has the following qualities:
|
|
| 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 |
-
|
| 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()) {}
|
|
@@ -8962,45 +8801,45 @@ public:
|
|
| 8962 |
|
| 8963 |
monotonic_buffer_resource(const monotonic_buffer_resource&) = delete;
|
| 8964 |
|
| 8965 |
virtual ~monotonic_buffer_resource();
|
| 8966 |
|
| 8967 |
-
|
| 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 |
-
####
|
| 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 |
-
*
|
| 8989 |
-
`initial_size`, if specified,
|
| 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 |
-
*
|
| 9001 |
-
`buffer_size`
|
| 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).
|
|
@@ -9009,11 +8848,11 @@ factor (which need not be integral).
|
|
| 9009 |
~monotonic_buffer_resource();
|
| 9010 |
```
|
| 9011 |
|
| 9012 |
*Effects:* Calls `release()`.
|
| 9013 |
|
| 9014 |
-
####
|
| 9015 |
|
| 9016 |
``` cpp
|
| 9017 |
void release();
|
| 9018 |
```
|
| 9019 |
|
|
@@ -9032,14 +8871,15 @@ memory_resource* upstream_resource() const;
|
|
| 9032 |
|
| 9033 |
``` cpp
|
| 9034 |
void* do_allocate(size_t bytes, size_t alignment) override;
|
| 9035 |
```
|
| 9036 |
|
| 9037 |
-
*Returns:* A pointer to allocated
|
| 9038 |
-
|
| 9039 |
-
The size and alignment of the allocated memory shall meet the
|
| 9040 |
-
requirements for a class derived from `memory_resource`
|
|
|
|
| 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
|
|
@@ -9063,32 +8903,32 @@ 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 |
-
|
|
|
|
| 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 |
-
|
| 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
|
| 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
|
|
@@ -9112,10 +8952,11 @@ 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;
|
|
@@ -9129,12 +8970,11 @@ namespace std {
|
|
| 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
|
| 9135 |
-
struct rebind {
|
| 9136 |
using other = scoped_allocator_adaptor<
|
| 9137 |
OuterTraits::template rebind_alloc<Tp>, InnerAllocs...>;
|
| 9138 |
};
|
| 9139 |
|
| 9140 |
scoped_allocator_adaptor();
|
|
@@ -9160,49 +9000,31 @@ namespace std {
|
|
| 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 |
-
###
|
| 9204 |
|
| 9205 |
``` cpp
|
| 9206 |
using inner_allocator_type = see below;
|
| 9207 |
```
|
| 9208 |
|
|
@@ -9243,33 +9065,31 @@ using is_always_equal = see below;
|
|
| 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 |
-
###
|
| 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
|
|
@@ -9282,38 +9102,36 @@ scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept;
|
|
| 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(
|
| 9288 |
-
|
| 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 |
-
|
| 9307 |
-
unless `is_constructible_v<OuterAlloc, OuterA2>` is `true`.
|
| 9308 |
|
| 9309 |
-
|
| 9310 |
-
|
| 9311 |
-
|
| 9312 |
-
|
| 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*]
|
|
@@ -9337,18 +9155,18 @@ 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 |
|
|
@@ -9368,149 +9186,20 @@ size_type max_size() const;
|
|
| 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 |
-
|
| 9497 |
-
|
| 9498 |
-
|
| 9499 |
-
|
| 9500 |
-
|
| 9501 |
-
|
| 9502 |
-
|
| 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);
|
|
@@ -9526,11 +9215,11 @@ scoped_allocator_adaptor select_on_container_copy_construction() const;
|
|
| 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 |
-
###
|
| 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;
|
|
@@ -9546,49 +9235,40 @@ 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
|
| 9562 |
-
|
| 9563 |
-
[[
|
| 9564 |
-
object
|
| 9565 |
-
|
| 9566 |
-
|
| 9567 |
-
|
| 9568 |
-
|
| 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
|
| 9584 |
-
template
|
| 9585 |
template<class T> void ref(const T&&) = delete;
|
| 9586 |
template<class T> void cref(const T&&) = delete;
|
| 9587 |
|
| 9588 |
-
template
|
| 9589 |
-
template
|
| 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;
|
|
@@ -9614,10 +9294,13 @@ namespace std {
|
|
| 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>;
|
|
@@ -9632,22 +9315,31 @@ namespace std {
|
|
| 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.
|
| 9638 |
-
|
| 9639 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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;
|
|
@@ -9657,11 +9349,11 @@ namespace std {
|
|
| 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
|
|
@@ -9670,16 +9362,10 @@ namespace std {
|
|
| 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 |
|
|
@@ -9691,19 +9377,23 @@ namespace std {
|
|
| 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],
|
| 9697 |
template<class T>
|
| 9698 |
struct hash;
|
| 9699 |
|
| 9700 |
-
|
| 9701 |
-
|
| 9702 |
-
|
| 9703 |
-
|
| 9704 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9705 |
}
|
| 9706 |
```
|
| 9707 |
|
| 9708 |
[*Example 1*:
|
| 9709 |
|
|
@@ -9731,11 +9421,11 @@ transform(a.begin(), a.end(), a.begin(), negate<double>());
|
|
| 9731 |
The following definitions apply to this Clause:
|
| 9732 |
|
| 9733 |
A *call signature* is the name of a return type followed by a
|
| 9734 |
parenthesized comma-separated list of zero or more argument types.
|
| 9735 |
|
| 9736 |
-
A *callable type* is a function object type
|
| 9737 |
pointer to member.
|
| 9738 |
|
| 9739 |
A *callable object* is an object of a callable type.
|
| 9740 |
|
| 9741 |
A *call wrapper type* is a type that holds a callable object and
|
|
@@ -9743,66 +9433,104 @@ supports a call operation that forwards to that object.
|
|
| 9743 |
|
| 9744 |
A *call wrapper* is an object of a call wrapper type.
|
| 9745 |
|
| 9746 |
A *target object* is the callable object held by a call wrapper.
|
| 9747 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9748 |
### Requirements <a id="func.require">[[func.require]]</a>
|
| 9749 |
|
| 9750 |
-
Define `INVOKE(f,
|
| 9751 |
|
| 9752 |
-
- `(
|
| 9753 |
-
class `T` and `is_base_of_v<T,
|
| 9754 |
-
|
| 9755 |
-
|
| 9756 |
-
|
| 9757 |
-
|
| 9758 |
-
|
| 9759 |
-
|
| 9760 |
-
|
| 9761 |
-
|
| 9762 |
-
|
|
|
|
| 9763 |
`reference_wrapper`;
|
| 9764 |
-
- `(*
|
| 9765 |
-
class `T` and `
|
| 9766 |
-
- `f(
|
| 9767 |
|
| 9768 |
-
Define `INVOKE<R>(f,
|
| 9769 |
-
`static_cast<void>(INVOKE(f,
|
| 9770 |
-
otherwise `INVOKE(f,
|
| 9771 |
|
| 9772 |
-
Every call wrapper
|
| 9773 |
-
*
|
| 9774 |
-
|
| 9775 |
-
|
| 9776 |
-
|
| 9777 |
-
|
| 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
|
| 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)...)
|
| 9804 |
|
| 9805 |
### Class template `reference_wrapper` <a id="refwrap">[[refwrap]]</a>
|
| 9806 |
|
| 9807 |
``` cpp
|
| 9808 |
namespace std {
|
|
@@ -9810,109 +9538,130 @@ namespace std {
|
|
| 9810 |
public:
|
| 9811 |
// types
|
| 9812 |
using type = T;
|
| 9813 |
|
| 9814 |
// construct/copy/destroy
|
| 9815 |
-
|
| 9816 |
-
|
| 9817 |
-
reference_wrapper(const reference_wrapper& x) noexcept;
|
| 9818 |
|
| 9819 |
// assignment
|
| 9820 |
-
reference_wrapper& operator=(const reference_wrapper& x) noexcept;
|
| 9821 |
|
| 9822 |
// access
|
| 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(
|
| 9834 |
}
|
| 9835 |
```
|
| 9836 |
|
| 9837 |
-
`reference_wrapper<T>` is a
|
| 9838 |
-
wrapper around a reference to an object or
|
|
|
|
| 9839 |
|
| 9840 |
-
`reference_wrapper<T>`
|
| 9841 |
-
[[basic.types]]).
|
| 9842 |
|
| 9843 |
-
|
|
|
|
|
|
|
|
|
|
| 9844 |
|
| 9845 |
``` cpp
|
| 9846 |
-
|
|
|
|
| 9847 |
```
|
| 9848 |
|
| 9849 |
-
*
|
| 9850 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9851 |
|
| 9852 |
``` cpp
|
| 9853 |
-
reference_wrapper(const reference_wrapper& x) noexcept;
|
| 9854 |
```
|
| 9855 |
|
| 9856 |
*Effects:* Constructs a `reference_wrapper` object that stores a
|
| 9857 |
reference to `x.get()`.
|
| 9858 |
|
| 9859 |
-
####
|
| 9860 |
|
| 9861 |
``` cpp
|
| 9862 |
-
reference_wrapper& operator=(const reference_wrapper& x) noexcept;
|
| 9863 |
```
|
| 9864 |
|
| 9865 |
-
*
|
| 9866 |
|
| 9867 |
-
####
|
| 9868 |
|
| 9869 |
``` cpp
|
| 9870 |
-
operator T& () const noexcept;
|
| 9871 |
```
|
| 9872 |
|
| 9873 |
*Returns:* The stored reference.
|
| 9874 |
|
| 9875 |
``` cpp
|
| 9876 |
-
T& get() const noexcept;
|
| 9877 |
```
|
| 9878 |
|
| 9879 |
*Returns:* The stored reference.
|
| 9880 |
|
| 9881 |
-
####
|
| 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)...).
|
| 9891 |
|
| 9892 |
-
####
|
|
|
|
|
|
|
|
|
|
| 9893 |
|
| 9894 |
``` cpp
|
| 9895 |
-
template
|
| 9896 |
```
|
| 9897 |
|
| 9898 |
*Returns:* `reference_wrapper<T>(t)`.
|
| 9899 |
|
| 9900 |
``` cpp
|
| 9901 |
-
template
|
| 9902 |
```
|
| 9903 |
|
| 9904 |
*Returns:* `ref(t.get())`.
|
| 9905 |
|
| 9906 |
``` cpp
|
| 9907 |
-
template
|
| 9908 |
```
|
| 9909 |
|
| 9910 |
*Returns:* `reference_wrapper <const T>(t)`.
|
| 9911 |
|
| 9912 |
``` cpp
|
| 9913 |
-
template
|
| 9914 |
```
|
| 9915 |
|
| 9916 |
*Returns:* `cref(t.get())`.
|
| 9917 |
|
| 9918 |
### Arithmetic operations <a id="arithmetic.operations">[[arithmetic.operations]]</a>
|
|
@@ -10104,26 +9853,25 @@ template <class T> constexpr auto operator()(T&& t) const
|
|
| 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
|
| 10110 |
-
|
| 10111 |
-
|
| 10112 |
|
| 10113 |
-
[*Note 1*:
|
| 10114 |
-
|
| 10115 |
-
|
| 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 |
-
|
| 10121 |
-
|
| 10122 |
-
operators.
|
| 10123 |
|
| 10124 |
-
#### Class template `equal_to` <a id="comparisons.
|
| 10125 |
|
| 10126 |
``` cpp
|
| 10127 |
template<class T = void> struct equal_to {
|
| 10128 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 10129 |
};
|
|
@@ -10149,11 +9897,11 @@ 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.
|
| 10155 |
|
| 10156 |
``` cpp
|
| 10157 |
template<class T = void> struct not_equal_to {
|
| 10158 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 10159 |
};
|
|
@@ -10239,11 +9987,11 @@ 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.
|
| 10245 |
|
| 10246 |
``` cpp
|
| 10247 |
template<class T = void> struct greater_equal {
|
| 10248 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 10249 |
};
|
|
@@ -10269,11 +10017,11 @@ 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.
|
| 10275 |
|
| 10276 |
``` cpp
|
| 10277 |
template<class T = void> struct less_equal {
|
| 10278 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 10279 |
};
|
|
@@ -10299,10 +10047,182 @@ 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]]).
|
|
@@ -10521,91 +10441,92 @@ template <class T> constexpr auto operator()(T&&) const
|
|
| 10521 |
-> decltype(~std::forward<T>(t));
|
| 10522 |
```
|
| 10523 |
|
| 10524 |
*Returns:* `~std::forward<T>(t)`.
|
| 10525 |
|
| 10526 |
-
###
|
| 10527 |
|
| 10528 |
``` cpp
|
| 10529 |
-
|
| 10530 |
-
|
|
|
|
| 10531 |
|
| 10532 |
-
|
| 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 |
-
|
| 10567 |
```
|
| 10568 |
|
| 10569 |
-
|
| 10570 |
-
`is_constructible_v<FD, F>` shall be `true`. `fd` shall be a callable
|
| 10571 |
-
object ([[func.def]]).
|
| 10572 |
|
| 10573 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10574 |
|
| 10575 |
-
*
|
|
|
|
| 10576 |
|
| 10577 |
-
``
|
| 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 |
-
*
|
|
|
|
| 10587 |
|
| 10588 |
-
``
|
| 10589 |
-
|
| 10590 |
-
``
|
| 10591 |
|
| 10592 |
``` cpp
|
| 10593 |
-
template<class... Args>
|
| 10594 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10602 |
|
| 10603 |
``` cpp
|
| 10604 |
-
|
|
|
|
|
|
|
|
|
|
| 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.
|
| 10611 |
|
|
@@ -10619,18 +10540,18 @@ namespace std {
|
|
| 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 |
-
|
| 10625 |
-
|
| 10626 |
-
|
| 10627 |
-
|
| 10628 |
characteristic of `false_type`. A program may specialize this template
|
| 10629 |
-
for a
|
| 10630 |
-
to indicate that `T` should be treated as a subexpression in
|
| 10631 |
-
call.
|
| 10632 |
|
| 10633 |
#### Class template `is_placeholder` <a id="func.bind.isplace">[[func.bind.isplace]]</a>
|
| 10634 |
|
| 10635 |
``` cpp
|
| 10636 |
namespace std {
|
|
@@ -10640,120 +10561,100 @@ namespace std {
|
|
| 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 |
-
|
| 10646 |
-
|
| 10647 |
-
|
| 10648 |
`integral_constant<int, J>` if `T` is the type of
|
| 10649 |
-
`std::placeholders::_J`, otherwise it
|
| 10650 |
-
|
| 10651 |
-
|
| 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
|
|
|
|
| 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
|
| 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 |
-
*
|
| 10712 |
-
|
| 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 |
-
*
|
| 10719 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10720 |
|
| 10721 |
``` cpp
|
| 10722 |
-
INVOKE
|
|
|
|
| 10723 |
```
|
| 10724 |
|
| 10725 |
-
|
| 10726 |
-
|
| 10727 |
-
|
| 10728 |
-
|
| 10729 |
-
|
|
|
|
| 10730 |
|
| 10731 |
-
|
| 10732 |
-
|
|
|
|
| 10733 |
|
| 10734 |
-
*
|
| 10735 |
-
|
| 10736 |
-
of `CopyConstructible`, then the return type shall satisfy the
|
| 10737 |
-
requirements of `CopyConstructible`.
|
| 10738 |
|
| 10739 |
-
[*Note
|
| 10740 |
-
|
|
|
|
| 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 |
-
`
|
| 10751 |
-
|
|
|
|
|
|
|
|
|
|
| 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 `
|
|
|
|
|
|
|
|
|
|
| 10755 |
|
| 10756 |
#### Placeholders <a id="func.bind.place">[[func.bind.place]]</a>
|
| 10757 |
|
| 10758 |
``` cpp
|
| 10759 |
namespace std::placeholders {
|
|
@@ -10765,68 +10666,68 @@ namespace std::placeholders {
|
|
| 10765 |
.
|
| 10766 |
see below _M;
|
| 10767 |
}
|
| 10768 |
```
|
| 10769 |
|
| 10770 |
-
All placeholder types
|
| 10771 |
-
|
| 10772 |
-
constructors
|
| 10773 |
-
|
| 10774 |
-
|
|
|
|
|
|
|
| 10775 |
|
| 10776 |
Placeholders should be defined as:
|
| 10777 |
|
| 10778 |
``` cpp
|
| 10779 |
inline constexpr unspecified _1{};
|
| 10780 |
```
|
| 10781 |
|
| 10782 |
-
If they are not, they
|
| 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
|
| 10795 |
-
|
| 10796 |
-
|
|
|
|
|
|
|
| 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.
|
| 10802 |
|
| 10803 |
#### Class `bad_function_call` <a id="func.wrap.badcall">[[func.wrap.badcall]]</a>
|
| 10804 |
|
| 10805 |
An exception of type `bad_function_call` is thrown by
|
| 10806 |
-
`function::operator()`
|
| 10807 |
-
|
| 10808 |
|
| 10809 |
``` cpp
|
| 10810 |
namespace std {
|
| 10811 |
class bad_function_call : public exception {
|
| 10812 |
public:
|
| 10813 |
-
// [
|
| 10814 |
-
|
| 10815 |
};
|
| 10816 |
}
|
| 10817 |
```
|
| 10818 |
|
| 10819 |
-
##### `bad_function_call` constructor <a id="func.wrap.badcall.const">[[func.wrap.badcall.const]]</a>
|
| 10820 |
-
|
| 10821 |
``` cpp
|
| 10822 |
-
|
| 10823 |
```
|
| 10824 |
|
| 10825 |
-
*
|
| 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 {
|
|
@@ -10839,11 +10740,11 @@ namespace std {
|
|
| 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;
|
|
@@ -10870,132 +10771,116 @@ namespace std {
|
|
| 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],
|
| 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;
|
| 10881 |
-
|
| 10882 |
-
template <class R, class... ArgTypes>
|
| 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
|
| 10897 |
-
|
| 10898 |
|
| 10899 |
-
A callable type
|
| 10900 |
-
|
| 10901 |
`INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
|
| 10902 |
-
unevaluated operand
|
| 10903 |
-
[[func.require]]).
|
| 10904 |
|
| 10905 |
-
The `function` class template is a call wrapper
|
| 10906 |
-
|
| 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 |
-
#####
|
| 10912 |
|
| 10913 |
``` cpp
|
| 10914 |
function() noexcept;
|
| 10915 |
```
|
| 10916 |
|
| 10917 |
-
*
|
| 10918 |
|
| 10919 |
``` cpp
|
| 10920 |
function(nullptr_t) noexcept;
|
| 10921 |
```
|
| 10922 |
|
| 10923 |
-
*
|
| 10924 |
|
| 10925 |
``` cpp
|
| 10926 |
function(const function& f);
|
| 10927 |
```
|
| 10928 |
|
| 10929 |
-
*
|
| 10930 |
`f.target()`.
|
| 10931 |
|
| 10932 |
-
*Throws:*
|
| 10933 |
-
|
| 10934 |
`bad_alloc` or any exception thrown by the copy constructor of the
|
| 10935 |
stored callable object.
|
| 10936 |
|
| 10937 |
-
[*Note 1*: Implementations
|
| 10938 |
-
|
| 10939 |
-
|
| 10940 |
-
|
| 10941 |
|
| 10942 |
``` cpp
|
| 10943 |
-
function(function&& f);
|
| 10944 |
```
|
| 10945 |
|
| 10946 |
-
*
|
| 10947 |
-
|
| 10948 |
-
|
| 10949 |
|
| 10950 |
-
*
|
| 10951 |
-
|
| 10952 |
-
|
| 10953 |
-
|
| 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 |
-
*
|
|
|
|
| 10965 |
|
| 10966 |
-
*
|
| 10967 |
-
resolution unless `F` is Lvalue-Callable ([[func.wrap.func]]) for
|
| 10968 |
-
argument types `ArgTypes...` and return type `R`.
|
| 10969 |
|
| 10970 |
-
*
|
| 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
|
| 10980 |
-
|
| 10981 |
-
|
| 10982 |
-
|
| 10983 |
|
| 10984 |
-
*Throws:*
|
| 10985 |
-
|
| 10986 |
-
|
| 10987 |
|
| 10988 |
``` cpp
|
| 10989 |
template<class F> function(F) -> function<see below>;
|
| 10990 |
```
|
| 10991 |
|
| 10992 |
-
*
|
| 10993 |
-
|
| 10994 |
-
|
| 10995 |
-
|
| 10996 |
-
deduced type is `function<R(A...)>`.
|
| 10997 |
|
| 10998 |
[*Example 1*:
|
| 10999 |
|
| 11000 |
``` cpp
|
| 11001 |
void f() {
|
|
@@ -11026,26 +10911,25 @@ function& operator=(function&& f);
|
|
| 11026 |
function& operator=(nullptr_t) noexcept;
|
| 11027 |
```
|
| 11028 |
|
| 11029 |
*Effects:* If `*this != nullptr`, destroys the target of `this`.
|
| 11030 |
|
| 11031 |
-
*
|
| 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);`
|
|
@@ -11056,40 +10940,40 @@ template<class F> function& operator=(reference_wrapper<F> f) noexcept;
|
|
| 11056 |
~function();
|
| 11057 |
```
|
| 11058 |
|
| 11059 |
*Effects:* If `*this != nullptr`, destroys the target of `this`.
|
| 11060 |
|
| 11061 |
-
#####
|
| 11062 |
|
| 11063 |
``` cpp
|
| 11064 |
void swap(function& other) noexcept;
|
| 11065 |
```
|
| 11066 |
|
| 11067 |
-
*Effects:*
|
| 11068 |
|
| 11069 |
-
#####
|
| 11070 |
|
| 11071 |
``` cpp
|
| 11072 |
explicit operator bool() const noexcept;
|
| 11073 |
```
|
| 11074 |
|
| 11075 |
*Returns:* `true` if `*this` has a target, otherwise `false`.
|
| 11076 |
|
| 11077 |
-
#####
|
| 11078 |
|
| 11079 |
``` cpp
|
| 11080 |
R operator()(ArgTypes... args) const;
|
| 11081 |
```
|
| 11082 |
|
| 11083 |
*Returns:* *INVOKE*\<R\>(f,
|
| 11084 |
-
std::forward\<ArgTypes\>(args)...)
|
| 11085 |
-
target object
|
| 11086 |
|
| 11087 |
*Throws:* `bad_function_call` if `!*this`; otherwise, any exception
|
| 11088 |
thrown by the wrapped callable object.
|
| 11089 |
|
| 11090 |
-
#####
|
| 11091 |
|
| 11092 |
``` cpp
|
| 11093 |
const type_info& target_type() const noexcept;
|
| 11094 |
```
|
| 11095 |
|
|
@@ -11102,51 +10986,40 @@ 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 |
-
#####
|
| 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>
|
| 11113 |
-
bool operator==(nullptr_t, const function<R(ArgTypes...)>& f) noexcept;
|
| 11114 |
```
|
| 11115 |
|
| 11116 |
*Returns:* `!f`.
|
| 11117 |
|
| 11118 |
-
|
| 11119 |
-
template <class R, class... ArgTypes>
|
| 11120 |
-
bool operator!=(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
|
| 11121 |
-
template <class R, class... ArgTypes>
|
| 11122 |
-
bool operator!=(nullptr_t, const function<R(ArgTypes...)>& f) noexcept;
|
| 11123 |
-
```
|
| 11124 |
-
|
| 11125 |
-
*Returns:* `(bool)f`.
|
| 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
|
| 11139 |
-
|
| 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
|
| 11147 |
-
requirements. Template parameters named
|
| 11148 |
|
| 11149 |
- `ForwardIterator`,
|
| 11150 |
- `ForwardIterator1`,
|
| 11151 |
- `ForwardIterator2`,
|
| 11152 |
- `RandomAccessIterator`,
|
|
@@ -11154,12 +11027,12 @@ requirements. Template parameters named
|
|
| 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
|
| 11160 |
-
|
| 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.
|
|
@@ -11168,26 +11041,26 @@ memory and give better runtime performance than Boyer-Moore-Horspool.
|
|
| 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
|
|
@@ -11196,11 +11069,11 @@ default_searcher(ForwardIterator pat_first, ForwardIterator pat_last,
|
|
| 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 |
|
|
@@ -11238,21 +11111,21 @@ boyer_moore_searcher(RandomAccessIterator1 pat_first,
|
|
| 11238 |
RandomAccessIterator1 pat_last,
|
| 11239 |
Hash hf = Hash(),
|
| 11240 |
BinaryPredicate pred = BinaryPredicate());
|
| 11241 |
```
|
| 11242 |
|
| 11243 |
-
*
|
| 11244 |
-
|
| 11245 |
-
requirements, and the
|
| 11246 |
|
| 11247 |
-
*
|
| 11248 |
-
`iterator_traits<RandomAccessIterator1>::value_type`
|
| 11249 |
-
`pred(A, B) == true`, then `hf(A) == hf(B)`
|
|
|
|
| 11250 |
|
| 11251 |
-
*Effects:*
|
| 11252 |
-
`
|
| 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
|
|
@@ -11263,12 +11136,12 @@ needed for internal data structures cannot be allocated.
|
|
| 11263 |
template<class RandomAccessIterator2>
|
| 11264 |
pair<RandomAccessIterator2, RandomAccessIterator2>
|
| 11265 |
operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
|
| 11266 |
```
|
| 11267 |
|
| 11268 |
-
*
|
| 11269 |
-
|
| 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 |
|
|
@@ -11315,21 +11188,21 @@ boyer_moore_horspool_searcher(RandomAccessIterator1 pat_first,
|
|
| 11315 |
RandomAccessIterator1 pat_last,
|
| 11316 |
Hash hf = Hash(),
|
| 11317 |
BinaryPredicate pred = BinaryPredicate());
|
| 11318 |
```
|
| 11319 |
|
| 11320 |
-
*
|
| 11321 |
-
|
| 11322 |
-
requirements.
|
| 11323 |
|
| 11324 |
-
*
|
| 11325 |
-
`iterator_traits<RandomAccessIterator1>::value_type`
|
| 11326 |
-
`pred(A, B) == true`, then `hf(A) == hf(B)`
|
|
|
|
| 11327 |
|
| 11328 |
-
*Effects:*
|
| 11329 |
-
|
| 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
|
|
@@ -11340,12 +11213,12 @@ needed for internal data structures cannot be allocated.
|
|
| 11340 |
template<class RandomAccessIterator2>
|
| 11341 |
pair<RandomAccessIterator2, RandomAccessIterator2>
|
| 11342 |
operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
|
| 11343 |
```
|
| 11344 |
|
| 11345 |
-
*
|
| 11346 |
-
|
| 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 |
|
|
@@ -11363,18 +11236,18 @@ found.
|
|
| 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`
|
| 11369 |
-
|
| 11370 |
|
| 11371 |
Each specialization of `hash` is either enabled or disabled, as
|
| 11372 |
described below.
|
| 11373 |
|
| 11374 |
-
[*Note 1*: Enabled specializations meet the
|
| 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
|
|
@@ -11386,78 +11259,92 @@ 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
|
| 11392 |
|
| 11393 |
[*Note 2*: This means that the specialization of `hash` exists, but any
|
| 11394 |
-
attempts to use it as a
|
| 11395 |
|
| 11396 |
An enabled specialization `hash<Key>` will:
|
| 11397 |
|
| 11398 |
-
-
|
| 11399 |
-
|
| 11400 |
-
requirements (
|
| 11401 |
-
|
| 11402 |
-
- be swappable
|
| 11403 |
-
-
|
| 11404 |
-
|
| 11405 |
-
|
| 11406 |
-
-
|
| 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
|
| 11409 |
-
specialization that depends on at least one
|
| 11410 |
|
| 11411 |
## Metaprogramming and type traits <a id="meta">[[meta]]</a>
|
| 11412 |
|
| 11413 |
-
This subclause describes components used by C++programs, particularly
|
| 11414 |
-
templates, to support the widest possible range of types, optimise
|
| 11415 |
template code usage, detect type related user errors, and perform type
|
| 11416 |
inference and transformation at compile time. It includes type
|
| 11417 |
classification traits, type property inspection traits, and type
|
| 11418 |
transformations. The type classification traits describe a complete
|
| 11419 |
taxonomy of all possible C++ types, and state where in that taxonomy a
|
| 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 |
-
[[
|
| 11427 |
|
| 11428 |
### Requirements <a id="meta.rqmts">[[meta.rqmts]]</a>
|
| 11429 |
|
| 11430 |
-
A
|
| 11431 |
-
|
| 11432 |
-
|
| 11433 |
-
|
| 11434 |
unambiguously derived, directly or indirectly, from its *base
|
| 11435 |
characteristic*, which is a specialization of the template
|
| 11436 |
-
`integral_constant`
|
| 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 |
-
|
| 11441 |
|
| 11442 |
-
A
|
| 11443 |
-
|
| 11444 |
-
|
| 11445 |
-
|
| 11446 |
publicly and unambiguously derived, directly or indirectly, from its
|
| 11447 |
*base characteristic*, which is a specialization of the template
|
| 11448 |
-
`integral_constant`
|
| 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
|
| 11453 |
|
| 11454 |
-
A
|
| 11455 |
-
|
| 11456 |
-
|
| 11457 |
-
|
| 11458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11459 |
|
| 11460 |
### Header `<type_traits>` synopsis <a id="meta.type.synop">[[meta.type.synop]]</a>
|
| 11461 |
|
| 11462 |
``` cpp
|
| 11463 |
namespace std {
|
|
@@ -11498,19 +11385,20 @@ namespace std {
|
|
| 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;
|
| 11514 |
template<class T> struct is_default_constructible;
|
| 11515 |
template<class T> struct is_copy_constructible;
|
| 11516 |
template<class T> struct is_move_constructible;
|
|
@@ -11559,10 +11447,13 @@ namespace std {
|
|
| 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;
|
|
@@ -11627,227 +11518,269 @@ namespace std {
|
|
| 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
|
| 11633 |
-
|
| 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
|
| 11644 |
-
|
|
|
|
| 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;
|
| 11652 |
template<bool b, class T, class F>
|
| 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
|
| 11670 |
-
= is_void<T>::value;
|
| 11671 |
-
template
|
| 11672 |
-
= is_null_pointer<T>::value;
|
| 11673 |
-
template
|
| 11674 |
-
= is_integral<T>::value;
|
| 11675 |
-
template
|
| 11676 |
-
= is_floating_point<T>::value;
|
| 11677 |
-
template
|
| 11678 |
-
= is_array<T>::value;
|
| 11679 |
-
template
|
| 11680 |
-
= is_pointer<T>::value;
|
| 11681 |
-
template
|
| 11682 |
-
= is_lvalue_reference<T>::value;
|
| 11683 |
-
template
|
| 11684 |
-
= is_rvalue_reference<T>::value;
|
| 11685 |
-
template
|
| 11686 |
-
= is_member_object_pointer<T>::value;
|
| 11687 |
-
template
|
| 11688 |
-
= is_member_function_pointer<T>::value;
|
| 11689 |
-
template
|
| 11690 |
-
= is_enum<T>::value;
|
| 11691 |
-
template
|
| 11692 |
-
= is_union<T>::value;
|
| 11693 |
-
template
|
| 11694 |
-
= is_class<T>::value;
|
| 11695 |
-
template
|
| 11696 |
-
= is_function<T>::value;
|
| 11697 |
|
| 11698 |
// [meta.unary.comp], composite type categories
|
| 11699 |
-
template
|
| 11700 |
-
= is_reference<T>::value;
|
| 11701 |
-
template
|
| 11702 |
-
= is_arithmetic<T>::value;
|
| 11703 |
-
template
|
| 11704 |
-
= is_fundamental<T>::value;
|
| 11705 |
-
template
|
| 11706 |
-
= is_object<T>::value;
|
| 11707 |
-
template
|
| 11708 |
-
= is_scalar<T>::value;
|
| 11709 |
-
template
|
| 11710 |
-
= is_compound<T>::value;
|
| 11711 |
-
template
|
| 11712 |
-
= is_member_pointer<T>::value;
|
| 11713 |
|
| 11714 |
// [meta.unary.prop], type properties
|
| 11715 |
-
template
|
| 11716 |
-
= is_const<T>::value;
|
| 11717 |
-
template
|
| 11718 |
-
= is_volatile<T>::value;
|
| 11719 |
-
template
|
| 11720 |
-
= is_trivial<T>::value;
|
| 11721 |
-
template
|
| 11722 |
-
= is_trivially_copyable<T>::value;
|
| 11723 |
-
template
|
| 11724 |
-
= is_standard_layout<T>::value;
|
| 11725 |
-
template
|
| 11726 |
-
=
|
| 11727 |
-
template
|
| 11728 |
-
=
|
| 11729 |
-
template
|
| 11730 |
-
=
|
| 11731 |
-
template
|
| 11732 |
-
=
|
| 11733 |
-
template
|
| 11734 |
-
=
|
| 11735 |
-
template
|
| 11736 |
-
=
|
| 11737 |
-
template
|
| 11738 |
-
=
|
| 11739 |
-
template
|
| 11740 |
-
=
|
| 11741 |
-
template
|
| 11742 |
-
=
|
| 11743 |
-
template
|
| 11744 |
-
=
|
| 11745 |
-
template
|
| 11746 |
-
=
|
| 11747 |
-
template
|
| 11748 |
-
=
|
| 11749 |
-
template
|
| 11750 |
-
=
|
| 11751 |
-
template
|
| 11752 |
-
=
|
| 11753 |
-
template
|
| 11754 |
-
=
|
| 11755 |
-
template
|
| 11756 |
-
=
|
| 11757 |
-
template
|
| 11758 |
-
=
|
| 11759 |
-
template
|
| 11760 |
-
=
|
| 11761 |
-
template
|
|
|
|
|
|
|
|
|
|
| 11762 |
= is_trivially_constructible<T, Args...>::value;
|
| 11763 |
-
template
|
|
|
|
| 11764 |
= is_trivially_default_constructible<T>::value;
|
| 11765 |
-
template
|
|
|
|
| 11766 |
= is_trivially_copy_constructible<T>::value;
|
| 11767 |
-
template
|
|
|
|
| 11768 |
= is_trivially_move_constructible<T>::value;
|
| 11769 |
-
template
|
| 11770 |
-
= is_trivially_assignable<T, U>::value;
|
| 11771 |
-
template
|
|
|
|
| 11772 |
= is_trivially_copy_assignable<T>::value;
|
| 11773 |
-
template
|
|
|
|
| 11774 |
= is_trivially_move_assignable<T>::value;
|
| 11775 |
-
template
|
| 11776 |
-
= is_trivially_destructible<T>::value;
|
| 11777 |
-
template
|
|
|
|
| 11778 |
= is_nothrow_constructible<T, Args...>::value;
|
| 11779 |
-
template
|
|
|
|
| 11780 |
= is_nothrow_default_constructible<T>::value;
|
| 11781 |
-
template
|
|
|
|
| 11782 |
= is_nothrow_copy_constructible<T>::value;
|
| 11783 |
-
template
|
|
|
|
| 11784 |
= is_nothrow_move_constructible<T>::value;
|
| 11785 |
-
template
|
| 11786 |
-
= is_nothrow_assignable<T, U>::value;
|
| 11787 |
-
template
|
| 11788 |
-
= is_nothrow_copy_assignable<T>::value;
|
| 11789 |
-
template
|
| 11790 |
-
= is_nothrow_move_assignable<T>::value;
|
| 11791 |
-
template
|
| 11792 |
-
= is_nothrow_swappable_with<T, U>::value;
|
| 11793 |
-
template
|
| 11794 |
-
= is_nothrow_swappable<T>::value;
|
| 11795 |
-
template
|
| 11796 |
-
= is_nothrow_destructible<T>::value;
|
| 11797 |
-
template
|
| 11798 |
-
= has_virtual_destructor<T>::value;
|
| 11799 |
-
template
|
|
|
|
| 11800 |
= has_unique_object_representations<T>::value;
|
| 11801 |
|
| 11802 |
// [meta.unary.prop.query], type property queries
|
| 11803 |
-
template
|
| 11804 |
-
= alignment_of<T>::value;
|
| 11805 |
-
template
|
| 11806 |
-
= rank<T>::value;
|
| 11807 |
-
template
|
| 11808 |
-
= extent<T, I>::value;
|
| 11809 |
|
| 11810 |
// [meta.rel], type relations
|
| 11811 |
-
template
|
| 11812 |
-
= is_same<T, U>::value;
|
| 11813 |
-
template
|
| 11814 |
-
= is_base_of<Base, Derived>::value;
|
| 11815 |
-
template
|
| 11816 |
-
= is_convertible<From, To>::value;
|
| 11817 |
-
template
|
| 11818 |
-
=
|
| 11819 |
-
template
|
| 11820 |
-
=
|
| 11821 |
-
template
|
| 11822 |
-
|
| 11823 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11824 |
= is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;
|
| 11825 |
|
| 11826 |
// [meta.logical], logical operator traits
|
| 11827 |
-
template<class... B>
|
| 11828 |
-
|
| 11829 |
-
template<class B>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 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 |
```
|
|
@@ -11859,29 +11792,29 @@ as base classes to define the interface for various type traits.
|
|
| 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
|
| 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 |
-
|
| 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
|
| 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 |
|
|
@@ -11895,16 +11828,16 @@ 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
|
| 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
|
| 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*]
|
|
@@ -11985,19 +11918,18 @@ if:
|
|
| 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
|
| 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
|
| 11999 |
with a base characteristic of `integral_constant<size_t, Value>`.
|
| 12000 |
|
| 12001 |
[*Example 1*:
|
| 12002 |
|
| 12003 |
``` cpp
|
|
@@ -12028,21 +11960,21 @@ assert((extent_v<int[][4], 1>) == 4);
|
|
| 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
|
| 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
|
| 12044 |
corresponding definition notwithstanding the restrictions of
|
| 12045 |
[[declval]].
|
| 12046 |
|
| 12047 |
[*Example 1*:
|
| 12048 |
|
|
@@ -12073,17 +12005,17 @@ implicit conversions to the return type of the function:
|
|
| 12073 |
To test() {
|
| 12074 |
return declval<From>();
|
| 12075 |
}
|
| 12076 |
```
|
| 12077 |
|
| 12078 |
-
[*Note 2*: This requirement gives well
|
| 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
|
| 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
|
|
@@ -12093,22 +12025,22 @@ in the program being ill-formed. — *end note*]
|
|
| 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 |
-
|
| 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]]
|
| 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 |
|
|
@@ -12142,16 +12074,15 @@ assert((is_same_v<remove_all_extents_t<int[][3]>, int>));
|
|
| 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]]
|
| 12149 |
-
|
| 12150 |
-
|
| 12151 |
-
|
| 12152 |
-
passing. — *end note*]
|
| 12153 |
|
| 12154 |
[*Note 2*:
|
| 12155 |
|
| 12156 |
A typical implementation would define `aligned_storage` as:
|
| 12157 |
|
|
@@ -12164,16 +12095,51 @@ struct aligned_storage {
|
|
| 12164 |
};
|
| 12165 |
```
|
| 12166 |
|
| 12167 |
— *end note*]
|
| 12168 |
|
| 12169 |
-
|
| 12170 |
-
|
|
|
|
|
|
|
| 12171 |
|
| 12172 |
-
|
| 12173 |
-
|
| 12174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
@@ -12182,17 +12148,22 @@ follows:
|
|
| 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 |
-
-
|
|
|
|
|
|
|
| 12188 |
``` cpp
|
| 12189 |
decay_t<decltype(false ? declval<D1>() : declval<D2>())>
|
| 12190 |
```
|
| 12191 |
|
| 12192 |
-
|
| 12193 |
-
|
|
|
|
|
|
|
|
|
|
| 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
|
|
@@ -12216,11 +12187,59 @@ 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12222 |
|
| 12223 |
Given these definitions:
|
| 12224 |
|
| 12225 |
``` cpp
|
| 12226 |
using PF1 = bool (&)();
|
|
@@ -12260,29 +12279,29 @@ 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<
|
| 12266 |
-
type argument `
|
| 12267 |
-
instantiating `conjunction<
|
| 12268 |
-
instantiation of `
|
| 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 `
|
| 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<
|
| 12279 |
unambiguous base that is either
|
| 12280 |
|
| 12281 |
-
- the first type `
|
| 12282 |
-
`bool(
|
| 12283 |
-
- if there is no such `
|
| 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 |
|
|
@@ -12295,29 +12314,29 @@ 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<
|
| 12301 |
-
type argument `
|
| 12302 |
-
instantiating `disjunction<
|
| 12303 |
-
instantiation of `
|
| 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 `
|
| 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<
|
| 12314 |
unambiguous base that is either
|
| 12315 |
|
| 12316 |
-
- the first type `
|
| 12317 |
-
`bool(
|
| 12318 |
-
- if there is no such `
|
| 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 |
|
|
@@ -12328,26 +12347,106 @@ The member names of the base class, other than `disjunction` and
|
|
| 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
|
| 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 |
-
|
| 12341 |
-
`ratio` which exactly represents any finite rational number
|
| 12342 |
-
numerator and denominator representable by compile-time constants
|
| 12343 |
-
type `intmax_t`.
|
| 12344 |
|
| 12345 |
-
Throughout
|
| 12346 |
-
express type requirements. If a template parameter is named `R1`
|
| 12347 |
-
`R2`, and the template argument is not a specialization of the
|
| 12348 |
-
template, the program is ill-formed.
|
| 12349 |
|
| 12350 |
### Header `<ratio>` synopsis <a id="ratio.syn">[[ratio.syn]]</a>
|
| 12351 |
|
| 12352 |
``` cpp
|
| 12353 |
namespace std {
|
|
@@ -12407,12 +12506,11 @@ namespace std {
|
|
| 12407 |
|
| 12408 |
### Class template `ratio` <a id="ratio.ratio">[[ratio.ratio]]</a>
|
| 12409 |
|
| 12410 |
``` cpp
|
| 12411 |
namespace std {
|
| 12412 |
-
template
|
| 12413 |
-
class ratio {
|
| 12414 |
public:
|
| 12415 |
static constexpr intmax_t num;
|
| 12416 |
static constexpr intmax_t den;
|
| 12417 |
using type = ratio<num, den>;
|
| 12418 |
};
|
|
@@ -12423,12 +12521,12 @@ 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.
|
| 12429 |
-
|
| 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 |
|
|
@@ -12438,22 +12536,22 @@ values of `N` and `D`:
|
|
| 12438 |
### Arithmetic on `ratio`s <a id="ratio.arithmetic">[[ratio.arithmetic]]</a>
|
| 12439 |
|
| 12440 |
Each of the alias templates `ratio_add`, `ratio_subtract`,
|
| 12441 |
`ratio_multiply`, and `ratio_divide` denotes the result of an arithmetic
|
| 12442 |
computation on two `ratio`s `R1` and `R2`. With `X` and `Y` computed (in
|
| 12443 |
-
the absence of arithmetic overflow) as specified by
|
| 12444 |
-
[[
|
| 12445 |
-
|
| 12446 |
`ratio<X, Y>::den`.
|
| 12447 |
|
| 12448 |
If it is not possible to represent `U` or `V` with `intmax_t`, the
|
| 12449 |
program is ill-formed. Otherwise, an implementation should yield correct
|
| 12450 |
values of `U` and `V`. If it is not possible to represent `X` or `Y`
|
| 12451 |
with `intmax_t`, the program is ill-formed unless the implementation
|
| 12452 |
yields correct values of `U` and `V`.
|
| 12453 |
|
| 12454 |
-
**Table: Expressions used to perform ratio arithmetic** <a id="
|
| 12455 |
|
| 12456 |
| Type | Value of `X` | Value of `Y` |
|
| 12457 |
| ------------------------ | --------------------- | ------------------- |
|
| 12458 |
| `ratio_add<R1, R2>` | `R1::num * R2::den +` | `R1::den * R2::den` |
|
| 12459 |
| | `R2::num * R1::den` | |
|
|
@@ -12524,1280 +12622,20 @@ template <class R1, class R2>
|
|
| 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
|
| 12530 |
-
|
| 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>
|
| 12582 |
-
constexpr operator*(const Rep1& s, const duration<Rep2, Period>& d);
|
| 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);
|
| 12602 |
-
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12603 |
-
constexpr bool operator!=(const duration<Rep1, Period1>& lhs,
|
| 12604 |
-
const duration<Rep2, Period2>& rhs);
|
| 12605 |
-
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12606 |
-
constexpr bool operator< (const duration<Rep1, Period1>& lhs,
|
| 12607 |
-
const duration<Rep2, Period2>& rhs);
|
| 12608 |
-
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12609 |
-
constexpr bool operator<=(const duration<Rep1, Period1>& lhs,
|
| 12610 |
-
const duration<Rep2, Period2>& rhs);
|
| 12611 |
-
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12612 |
-
constexpr bool operator> (const duration<Rep1, Period1>& lhs,
|
| 12613 |
-
const duration<Rep2, Period2>& rhs);
|
| 12614 |
-
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 12615 |
-
constexpr bool operator>=(const duration<Rep1, Period1>& lhs,
|
| 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,
|
| 12660 |
-
const time_point<Clock, Duration2>& rhs);
|
| 12661 |
-
template <class Clock, class Duration1, class Duration2>
|
| 12662 |
-
constexpr bool operator< (const time_point<Clock, Duration1>& lhs,
|
| 12663 |
-
const time_point<Clock, Duration2>& rhs);
|
| 12664 |
-
template <class Clock, class Duration1, class Duration2>
|
| 12665 |
-
constexpr bool operator<=(const time_point<Clock, Duration1>& lhs,
|
| 12666 |
-
const time_point<Clock, Duration2>& rhs);
|
| 12667 |
-
template <class Clock, class Duration1, class Duration2>
|
| 12668 |
-
constexpr bool operator> (const time_point<Clock, Duration1>& lhs,
|
| 12669 |
-
const time_point<Clock, Duration2>& rhs);
|
| 12670 |
-
template <class Clock, class Duration1, class Duration2>
|
| 12671 |
-
constexpr bool operator>=(const time_point<Clock, Duration1>& lhs,
|
| 12672 |
-
const time_point<Clock, Duration2>& rhs);
|
| 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);
|
| 12706 |
-
constexpr chrono::duration<unspecified> operator""s(long double);
|
| 12707 |
-
constexpr chrono::milliseconds operator""ms(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
|
| 12725 |
-
function `now()` to get the current `time_point`. The origin of the
|
| 12726 |
-
clock’s `time_point` is referred to as the clock’s *epoch*. A clock
|
| 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.
|
| 12759 |
-
|
| 12760 |
-
### Time-related traits <a id="time.traits">[[time.traits]]</a>
|
| 12761 |
-
|
| 12762 |
-
#### `treat_as_floating_point` <a id="time.traits.is_fp">[[time.traits.is_fp]]</a>
|
| 12763 |
-
|
| 12764 |
-
``` cpp
|
| 12765 |
-
template <class Rep> struct treat_as_floating_point
|
| 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>
|
| 12787 |
-
struct duration_values {
|
| 12788 |
-
public:
|
| 12789 |
-
static constexpr Rep zero();
|
| 12790 |
-
static constexpr Rep min();
|
| 12791 |
-
static constexpr Rep max();
|
| 12792 |
-
};
|
| 12793 |
-
```
|
| 12794 |
-
|
| 12795 |
-
The `duration` template uses the `duration_values` trait to construct
|
| 12796 |
-
special values of the durations representation (`Rep`). This is done
|
| 12797 |
-
because the representation might be a class type with behavior which
|
| 12798 |
-
requires some other implementation to return these special values. In
|
| 12799 |
-
that case, the author of that class type should specialize
|
| 12800 |
-
`duration_values` to return the indicated values.
|
| 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
|
| 12863 |
-
`duration`s.
|
| 12864 |
-
|
| 12865 |
-
### Class template `duration` <a id="time.duration">[[time.duration]]</a>
|
| 12866 |
-
|
| 12867 |
-
A `duration` type measures time between two points in time
|
| 12868 |
-
(`time_point`s). A `duration` has a representation which holds a count
|
| 12869 |
-
of ticks and a tick period. The tick period is the amount of time which
|
| 12870 |
-
occurs from one tick to the next, in units of seconds. It is expressed
|
| 12871 |
-
as a rational constant using the template `ratio`.
|
| 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>
|
| 13001 |
-
|
| 13002 |
-
``` cpp
|
| 13003 |
-
constexpr rep count() const;
|
| 13004 |
-
```
|
| 13005 |
-
|
| 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 |
-
|
| 13100 |
-
``` cpp
|
| 13101 |
-
static constexpr duration zero();
|
| 13102 |
-
```
|
| 13103 |
-
|
| 13104 |
-
*Returns:* `duration(duration_values<rep>::zero())`.
|
| 13105 |
-
|
| 13106 |
-
``` cpp
|
| 13107 |
-
static constexpr duration min();
|
| 13108 |
-
```
|
| 13109 |
-
|
| 13110 |
-
*Returns:* `duration(duration_values<rep>::min())`.
|
| 13111 |
-
|
| 13112 |
-
``` cpp
|
| 13113 |
-
static constexpr duration max();
|
| 13114 |
-
```
|
| 13115 |
-
|
| 13116 |
-
*Returns:* `duration(duration_values<rep>::max())`.
|
| 13117 |
-
|
| 13118 |
-
#### `duration` non-member arithmetic <a id="time.duration.nonmember">[[time.duration.nonmember]]</a>
|
| 13119 |
-
|
| 13120 |
-
In the function descriptions that follow, `CD` represents the return
|
| 13121 |
-
type of the function. `CR(A, B)` represents `common_type_t<A, B>`.
|
| 13122 |
-
|
| 13123 |
-
``` cpp
|
| 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);
|
| 13154 |
-
```
|
| 13155 |
-
|
| 13156 |
-
*Remarks:* This operator shall not participate in overload resolution
|
| 13157 |
-
unless `Rep1` is implicitly convertible to `CR(Rep1, Rep2)`.
|
| 13158 |
-
|
| 13159 |
-
*Returns:* `d * s`.
|
| 13160 |
-
|
| 13161 |
-
``` cpp
|
| 13162 |
-
template <class Rep1, class Period, class Rep2>
|
| 13163 |
-
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 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);
|
| 13177 |
-
```
|
| 13178 |
-
|
| 13179 |
-
*Returns:* `CD(lhs).count() / CD(rhs).count()`.
|
| 13180 |
-
|
| 13181 |
-
``` cpp
|
| 13182 |
-
template <class Rep1, class Period, class Rep2>
|
| 13183 |
-
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 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>
|
| 13256 |
-
|
| 13257 |
-
``` cpp
|
| 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 |
-
```
|
| 13273 |
-
- otherwise, if `CF::num != 1` and `CF::den == 1`, returns
|
| 13274 |
-
``` cpp
|
| 13275 |
-
ToDuration(static_cast<typename ToDuration::rep>(
|
| 13276 |
-
static_cast<CR>(d.count()) * static_cast<CR>(CF::num)))
|
| 13277 |
-
```
|
| 13278 |
-
- otherwise, if `CF::num == 1` and `CF::den != 1`, returns
|
| 13279 |
-
``` cpp
|
| 13280 |
-
ToDuration(static_cast<typename ToDuration::rep>(
|
| 13281 |
-
static_cast<CR>(d.count()) / static_cast<CR>(CF::den)))
|
| 13282 |
-
```
|
| 13283 |
-
- otherwise, returns
|
| 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 |
-
|
| 13365 |
-
*Returns:* A `duration` literal representing `hours` hours.
|
| 13366 |
-
|
| 13367 |
-
``` cpp
|
| 13368 |
-
constexpr chrono::minutes operator""min(unsigned long long minutes);
|
| 13369 |
-
constexpr chrono::duration<unspecified, ratio<60, 1>> operator""min(long double minutes);
|
| 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 |
-
```
|
| 13389 |
-
|
| 13390 |
-
*Returns:* A `duration` literal representing `msec` milliseconds.
|
| 13391 |
-
|
| 13392 |
-
``` cpp
|
| 13393 |
-
constexpr chrono::microseconds operator""us(unsigned long long usec);
|
| 13394 |
-
constexpr chrono::duration<unspecified, micro> operator""us(long double usec);
|
| 13395 |
-
```
|
| 13396 |
-
|
| 13397 |
-
*Returns:* A `duration` literal representing `usec` microseconds.
|
| 13398 |
-
|
| 13399 |
-
``` cpp
|
| 13400 |
-
constexpr chrono::nanoseconds operator""ns(unsigned long long nsec);
|
| 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>
|
| 13457 |
-
|
| 13458 |
-
``` cpp
|
| 13459 |
-
constexpr time_point();
|
| 13460 |
-
```
|
| 13461 |
-
|
| 13462 |
-
*Effects:* Constructs an object of type `time_point`, initializing `d_`
|
| 13463 |
-
with `duration::zero()`. Such a `time_point` object represents the
|
| 13464 |
-
epoch.
|
| 13465 |
-
|
| 13466 |
-
``` cpp
|
| 13467 |
-
constexpr explicit time_point(const duration& d);
|
| 13468 |
-
```
|
| 13469 |
-
|
| 13470 |
-
*Effects:* Constructs an object of type `time_point`, initializing `d_`
|
| 13471 |
-
with `d`. Such a `time_point` object represents the epoch `+ d`.
|
| 13472 |
-
|
| 13473 |
-
``` cpp
|
| 13474 |
-
template <class Duration2>
|
| 13475 |
-
constexpr time_point(const time_point<clock, Duration2>& t);
|
| 13476 |
-
```
|
| 13477 |
-
|
| 13478 |
-
*Remarks:* This constructor shall not participate in overload resolution
|
| 13479 |
-
unless `Duration2` is implicitly convertible to `duration`.
|
| 13480 |
-
|
| 13481 |
-
*Effects:* Constructs an object of type `time_point`, initializing `d_`
|
| 13482 |
-
with `t.time_since_epoch()`.
|
| 13483 |
-
|
| 13484 |
-
#### `time_point` observer <a id="time.point.observer">[[time.point.observer]]</a>
|
| 13485 |
-
|
| 13486 |
-
``` cpp
|
| 13487 |
-
constexpr duration time_since_epoch() const;
|
| 13488 |
-
```
|
| 13489 |
-
|
| 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 |
-
|
| 13512 |
-
``` cpp
|
| 13513 |
-
static constexpr time_point min();
|
| 13514 |
-
```
|
| 13515 |
-
|
| 13516 |
-
*Returns:* `time_point(duration::min())`.
|
| 13517 |
-
|
| 13518 |
-
``` cpp
|
| 13519 |
-
static constexpr time_point max();
|
| 13520 |
-
```
|
| 13521 |
-
|
| 13522 |
-
*Returns:* `time_point(duration::max())`.
|
| 13523 |
-
|
| 13524 |
-
#### `time_point` non-member arithmetic <a id="time.point.nonmember">[[time.point.nonmember]]</a>
|
| 13525 |
-
|
| 13526 |
-
``` cpp
|
| 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);
|
| 13539 |
-
```
|
| 13540 |
-
|
| 13541 |
-
*Returns:* `rhs + lhs`.
|
| 13542 |
-
|
| 13543 |
-
``` cpp
|
| 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);
|
| 13556 |
-
```
|
| 13557 |
-
|
| 13558 |
-
*Returns:* `lhs.time_since_epoch() - rhs.time_since_epoch()`.
|
| 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>
|
| 13611 |
-
|
| 13612 |
-
``` cpp
|
| 13613 |
-
template <class ToDuration, class Clock, class Duration>
|
| 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]]).
|
| 13668 |
-
|
| 13669 |
-
#### Class `system_clock` <a id="time.clock.system">[[time.clock.system]]</a>
|
| 13670 |
-
|
| 13671 |
-
Objects of class `system_clock` represent wall clock time from the
|
| 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
|
| 13686 |
-
static time_t to_time_t (const time_point& t) noexcept;
|
| 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
|
| 13722 |
-
`time_point` never decrease as physical time advances and for which
|
| 13723 |
-
values of `time_point` advance at a steady rate relative to real time.
|
| 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 |
-
```
|
| 13738 |
-
|
| 13739 |
-
#### Class `high_resolution_clock` <a id="time.clock.hires">[[time.clock.hires]]</a>
|
| 13740 |
-
|
| 13741 |
-
Objects of class `high_resolution_clock` represent clocks with the
|
| 13742 |
-
shortest tick period. `high_resolution_clock` may be a synonym for
|
| 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 |
|
| 13798 |
``` cpp
|
|
|
|
|
|
|
| 13799 |
namespace std {
|
| 13800 |
class type_index;
|
| 13801 |
template<class T> struct hash;
|
| 13802 |
template<> struct hash<type_index>;
|
| 13803 |
}
|
|
@@ -13809,29 +12647,30 @@ namespace std {
|
|
| 13809 |
namespace std {
|
| 13810 |
class type_index {
|
| 13811 |
public:
|
| 13812 |
type_index(const type_info& rhs) noexcept;
|
| 13813 |
bool operator==(const type_index& rhs) const noexcept;
|
| 13814 |
-
bool operator!=(const type_index& rhs) const noexcept;
|
| 13815 |
bool operator< (const type_index& rhs) const noexcept;
|
| 13816 |
-
bool operator<= (const type_index& rhs) const noexcept;
|
| 13817 |
bool operator> (const type_index& rhs) const noexcept;
|
|
|
|
| 13818 |
bool operator>=(const type_index& rhs) const noexcept;
|
|
|
|
| 13819 |
size_t hash_code() const noexcept;
|
| 13820 |
const char* name() const noexcept;
|
|
|
|
| 13821 |
private:
|
| 13822 |
const type_info* target; // exposition only
|
| 13823 |
// Note that the use of a pointer here, rather than a reference,
|
| 13824 |
// means that the default copy/move constructor and assignment
|
| 13825 |
// operators will be provided and work as expected.
|
| 13826 |
};
|
| 13827 |
}
|
| 13828 |
```
|
| 13829 |
|
| 13830 |
The class `type_index` provides a simple wrapper for `type_info` which
|
| 13831 |
-
can be used as an index type in associative containers
|
| 13832 |
-
|
| 13833 |
|
| 13834 |
### `type_index` members <a id="type.index.members">[[type.index.members]]</a>
|
| 13835 |
|
| 13836 |
``` cpp
|
| 13837 |
type_index(const type_info& rhs) noexcept;
|
|
@@ -13844,40 +12683,46 @@ type_index(const type_info& rhs) noexcept;
|
|
| 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()`.
|
|
@@ -13899,14 +12744,14 @@ 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 |
-
|
| 13905 |
-
object of an execution policy type indicates the kinds of
|
| 13906 |
-
allowed in the execution of an algorithm and expresses the
|
| 13907 |
-
requirements on the element access functions.
|
| 13908 |
|
| 13909 |
[*Example 1*:
|
| 13910 |
|
| 13911 |
``` cpp
|
| 13912 |
using namespace std;
|
|
@@ -13949,14 +12794,18 @@ namespace std::execution {
|
|
| 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 |
|
|
@@ -13966,11 +12815,11 @@ template<class T> struct is_execution_policy { see below };
|
|
| 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>`
|
| 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
|
|
@@ -13989,11 +12838,11 @@ 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()`
|
| 13995 |
called.
|
| 13996 |
|
| 13997 |
### Parallel execution policy <a id="execpol.par">[[execpol.par]]</a>
|
| 13998 |
|
| 13999 |
``` cpp
|
|
@@ -14004,11 +12853,11 @@ 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()`
|
| 14010 |
called.
|
| 14011 |
|
| 14012 |
### Parallel and unsequenced execution policy <a id="execpol.parunseq">[[execpol.parunseq]]</a>
|
| 14013 |
|
| 14014 |
``` cpp
|
|
@@ -14021,46 +12870,1703 @@ 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.
|
| 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
|
|
@@ -14072,18 +14578,16 @@ type of execution policy.
|
|
| 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.
|
| 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
|
|
@@ -14095,92 +14599,136 @@ type of execution policy.
|
|
| 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.
|
| 14102 |
[comparisons.greater]: #comparisons.greater
|
| 14103 |
-
[comparisons.
|
| 14104 |
[comparisons.less]: #comparisons.less
|
| 14105 |
-
[comparisons.
|
| 14106 |
-
[comparisons.
|
| 14107 |
-
[
|
| 14108 |
-
[
|
| 14109 |
-
[conv.
|
| 14110 |
-
[conv.
|
| 14111 |
-
[
|
| 14112 |
-
[
|
| 14113 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 14134 |
[expr.eq]: expr.md#expr.eq
|
| 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.
|
| 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
|
| 14163 |
[func.wrap.func.cap]: #func.wrap.func.cap
|
| 14164 |
[func.wrap.func.con]: #func.wrap.func.con
|
| 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 |
-
[
|
| 14172 |
-
[
|
| 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
|
|
@@ -14204,12 +14752,14 @@ type of execution policy.
|
|
| 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,20 +14771,20 @@ type of execution policy.
|
|
| 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]:
|
| 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.
|
| 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
|
|
@@ -14255,14 +14805,17 @@ type of execution policy.
|
|
| 14255 |
[pair.piecewise]: #pair.piecewise
|
| 14256 |
[pairs]: #pairs
|
| 14257 |
[pairs.general]: #pairs.general
|
| 14258 |
[pairs.pair]: #pairs.pair
|
| 14259 |
[pairs.spec]: #pairs.spec
|
|
|
|
| 14260 |
[pointer.traits]: #pointer.traits
|
| 14261 |
[pointer.traits.functions]: #pointer.traits.functions
|
|
|
|
| 14262 |
[pointer.traits.types]: #pointer.traits.types
|
| 14263 |
[ptr.align]: #ptr.align
|
|
|
|
| 14264 |
[ratio]: #ratio
|
| 14265 |
[ratio.arithmetic]: #ratio.arithmetic
|
| 14266 |
[ratio.comparison]: #ratio.comparison
|
| 14267 |
[ratio.general]: #ratio.general
|
| 14268 |
[ratio.ratio]: #ratio.ratio
|
|
@@ -14272,69 +14825,26 @@ type of execution policy.
|
|
| 14272 |
[refwrap.access]: #refwrap.access
|
| 14273 |
[refwrap.assign]: #refwrap.assign
|
| 14274 |
[refwrap.const]: #refwrap.const
|
| 14275 |
[refwrap.helpers]: #refwrap.helpers
|
| 14276 |
[refwrap.invoke]: #refwrap.invoke
|
| 14277 |
-
[res.on.
|
|
|
|
| 14278 |
[scoped.adaptor.operators]: #scoped.adaptor.operators
|
| 14279 |
[smartptr]: #smartptr
|
| 14280 |
-
[special]:
|
| 14281 |
[specialized.addressof]: #specialized.addressof
|
| 14282 |
-
[specialized.algorithms]: #specialized.algorithms
|
| 14283 |
-
[specialized.destroy]: #specialized.destroy
|
| 14284 |
[stmt.dcl]: stmt.md#stmt.dcl
|
| 14285 |
-
[
|
| 14286 |
-
[support.
|
| 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
|
| 14319 |
-
[time.duration.nonmember]: #time.duration.nonmember
|
| 14320 |
-
[time.duration.observer]: #time.duration.observer
|
| 14321 |
-
[time.duration.special]: #time.duration.special
|
| 14322 |
-
[time.general]: #time.general
|
| 14323 |
-
[time.point]: #time.point
|
| 14324 |
-
[time.point.arithmetic]: #time.point.arithmetic
|
| 14325 |
-
[time.point.cast]: #time.point.cast
|
| 14326 |
-
[time.point.comparisons]: #time.point.comparisons
|
| 14327 |
-
[time.point.cons]: #time.point.cons
|
| 14328 |
-
[time.point.nonmember]: #time.point.nonmember
|
| 14329 |
-
[time.point.observer]: #time.point.observer
|
| 14330 |
-
[time.point.special]: #time.point.special
|
| 14331 |
-
[time.syn]: #time.syn
|
| 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
|
|
@@ -14350,21 +14860,17 @@ type of execution policy.
|
|
| 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
|
|
@@ -14376,18 +14882,16 @@ type of execution policy.
|
|
| 14376 |
[unique.ptr.single.observers]: #unique.ptr.single.observers
|
| 14377 |
[unique.ptr.special]: #unique.ptr.special
|
| 14378 |
[unord]: containers.md#unord
|
| 14379 |
[unord.hash]: #unord.hash
|
| 14380 |
[util.dynamic.safety]: #util.dynamic.safety
|
| 14381 |
-
[util.smartptr]: #util.smartptr
|
| 14382 |
[util.smartptr.enab]: #util.smartptr.enab
|
| 14383 |
[util.smartptr.getdeleter]: #util.smartptr.getdeleter
|
| 14384 |
[util.smartptr.hash]: #util.smartptr.hash
|
| 14385 |
[util.smartptr.ownerless]: #util.smartptr.ownerless
|
| 14386 |
[util.smartptr.shared]: #util.smartptr.shared
|
| 14387 |
[util.smartptr.shared.assign]: #util.smartptr.shared.assign
|
| 14388 |
-
[util.smartptr.shared.atomic]: #util.smartptr.shared.atomic
|
| 14389 |
[util.smartptr.shared.cast]: #util.smartptr.shared.cast
|
| 14390 |
[util.smartptr.shared.cmp]: #util.smartptr.shared.cmp
|
| 14391 |
[util.smartptr.shared.const]: #util.smartptr.shared.const
|
| 14392 |
[util.smartptr.shared.create]: #util.smartptr.shared.create
|
| 14393 |
[util.smartptr.shared.dest]: #util.smartptr.shared.dest
|
|
@@ -14403,17 +14907,17 @@ type of execution policy.
|
|
| 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.
|
| 14410 |
[utility.exchange]: #utility.exchange
|
| 14411 |
-
[utility.
|
| 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
|
|
@@ -14427,20 +14931,15 @@ type of execution policy.
|
|
| 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 |
|
| 14440 |
[^2]: Such a type is a function pointer or a class type which has a
|
| 14441 |
member `operator()` or a class type which has a conversion to a
|
| 14442 |
pointer to function.
|
| 14443 |
-
|
| 14444 |
-
[^3]: `strftime` supports the C conversion specifiers `C`, `D`, `e`,
|
| 14445 |
-
`F`, `g`, `G`, `h`, `r`, `R`, `t`, `T`, `u`, `V`, and `z`, and the
|
| 14446 |
-
modifiers `E` and `O`.
|
|
|
|
| 1 |
# General utilities library <a id="utilities">[[utilities]]</a>
|
| 2 |
|
| 3 |
## General <a id="utilities.general">[[utilities.general]]</a>
|
| 4 |
|
| 5 |
+
This Clause describes utilities that are generally useful in C++
|
| 6 |
+
programs; some of these utilities are used by other elements of the C++
|
| 7 |
+
standard library. These utilities are summarized in
|
| 8 |
+
[[utilities.summary]].
|
| 9 |
|
| 10 |
+
**Table: General utilities library summary** <a id="utilities.summary">[utilities.summary]</a>
|
| 11 |
|
| 12 |
| Subclause | | Header |
|
| 13 |
+
| --------------------- | -------------------------------- | ----------------------- |
|
| 14 |
| [[utility]] | Utility components | `<utility>` |
|
| 15 |
+
| [[intseq]] | Compile-time integer sequences | |
|
| 16 |
+
| [[pairs]] | Pairs | |
|
| 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 | `<cstdlib>`, `<memory>` |
|
|
|
|
| 23 |
| [[smartptr]] | Smart pointers | `<memory>` |
|
| 24 |
| [[mem.res]] | Memory resources | `<memory_resource>` |
|
| 25 |
| [[allocator.adaptor]] | Scoped allocators | `<scoped_allocator>` |
|
| 26 |
| [[function.objects]] | Function objects | `<functional>` |
|
| 27 |
| [[meta]] | Type traits | `<type_traits>` |
|
| 28 |
| [[ratio]] | Compile-time rational arithmetic | `<ratio>` |
|
|
|
|
|
|
|
| 29 |
| [[type.index]] | Type indexes | `<typeindex>` |
|
| 30 |
| [[execpol]] | Execution policies | `<execution>` |
|
| 31 |
+
| [[charconv]] | Primitive numeric conversions | `<charconv>` |
|
| 32 |
+
| [[format]] | Formatting | `<format>` |
|
| 33 |
|
| 34 |
|
| 35 |
## Utility components <a id="utility">[[utility]]</a>
|
| 36 |
|
|
|
|
|
|
|
|
|
|
| 37 |
### Header `<utility>` synopsis <a id="utility.syn">[[utility.syn]]</a>
|
| 38 |
|
| 39 |
+
The header `<utility>` contains some basic function and class templates
|
| 40 |
+
that are used throughout the rest of the library.
|
| 41 |
+
|
| 42 |
``` cpp
|
| 43 |
+
#include <compare> // see [compare.syn]
|
| 44 |
+
#include <initializer_list> // see [initializer.list.syn]
|
| 45 |
|
| 46 |
namespace std {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
// [utility.swap], swap
|
| 48 |
template<class T>
|
| 49 |
+
constexpr void swap(T& a, T& b) noexcept(see below);
|
| 50 |
template<class T, size_t N>
|
| 51 |
+
constexpr void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v<T>);
|
| 52 |
|
| 53 |
// [utility.exchange], exchange
|
| 54 |
template<class T, class U = T>
|
| 55 |
+
constexpr T exchange(T& obj, U&& new_val);
|
| 56 |
|
| 57 |
// [forward], forward/move
|
| 58 |
template<class T>
|
| 59 |
constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 60 |
template<class T>
|
|
|
|
| 64 |
template<class T>
|
| 65 |
constexpr conditional_t<
|
| 66 |
!is_nothrow_move_constructible_v<T> && is_copy_constructible_v<T>, const T&, T&&>
|
| 67 |
move_if_noexcept(T& x) noexcept;
|
| 68 |
|
| 69 |
+
// [utility.as.const], as_const
|
| 70 |
template<class T>
|
| 71 |
constexpr add_const_t<T>& as_const(T& t) noexcept;
|
| 72 |
template<class T>
|
| 73 |
void as_const(const T&&) = delete;
|
| 74 |
|
| 75 |
// [declval], declval
|
| 76 |
template<class T>
|
| 77 |
add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
| 78 |
+
|
| 79 |
+
// [utility.intcmp], integer comparison functions
|
| 80 |
+
template<class T, class U>
|
| 81 |
+
constexpr bool cmp_equal(T t, U u) noexcept;
|
| 82 |
+
template<class T, class U>
|
| 83 |
+
constexpr bool cmp_not_equal(T t, U u) noexcept;
|
| 84 |
+
|
| 85 |
+
template<class T, class U>
|
| 86 |
+
constexpr bool cmp_less(T t, U u) noexcept;
|
| 87 |
+
template<class T, class U>
|
| 88 |
+
constexpr bool cmp_greater(T t, U u) noexcept;
|
| 89 |
+
template<class T, class U>
|
| 90 |
+
constexpr bool cmp_less_equal(T t, U u) noexcept;
|
| 91 |
+
template<class T, class U>
|
| 92 |
+
constexpr bool cmp_greater_equal(T t, U u) noexcept;
|
| 93 |
+
|
| 94 |
+
template<class R, class T>
|
| 95 |
+
constexpr bool in_range(T t) noexcept;
|
| 96 |
+
|
| 97 |
+
// [intseq], compile-time integer sequences%
|
| 98 |
+
%
|
| 99 |
%
|
| 100 |
|
|
|
|
| 101 |
template<class T, T...>
|
| 102 |
struct integer_sequence;
|
| 103 |
template<size_t... I>
|
| 104 |
using index_sequence = integer_sequence<size_t, I...>;
|
| 105 |
|
|
|
|
| 117 |
|
| 118 |
// [pairs.spec], pair specialized algorithms
|
| 119 |
template<class T1, class T2>
|
| 120 |
constexpr bool operator==(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 121 |
template<class T1, class T2>
|
| 122 |
+
constexpr common_comparison_category_t<synth-three-way-result<T1>,
|
| 123 |
+
synth-three-way-result<T2>>
|
| 124 |
+
operator<=>(const pair<T1, T2>&, const pair<T1, T2>&);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
template<class T1, class T2>
|
| 127 |
+
constexpr void swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
|
| 128 |
|
| 129 |
template<class T1, class T2>
|
| 130 |
constexpr see below make_pair(T1&&, T2&&);
|
| 131 |
|
| 132 |
// [pair.astuple], tuple-like access to pair
|
| 133 |
+
template<class T> struct tuple_size;
|
| 134 |
+
template<size_t I, class T> struct tuple_element;
|
| 135 |
|
| 136 |
template<class T1, class T2> struct tuple_size<pair<T1, T2>>;
|
| 137 |
+
template<size_t I, class T1, class T2> struct tuple_element<I, pair<T1, T2>>;
|
|
|
|
| 138 |
|
| 139 |
template<size_t I, class T1, class T2>
|
| 140 |
constexpr tuple_element_t<I, pair<T1, T2>>& get(pair<T1, T2>&) noexcept;
|
| 141 |
template<size_t I, class T1, class T2>
|
| 142 |
constexpr tuple_element_t<I, pair<T1, T2>>&& get(pair<T1, T2>&&) noexcept;
|
|
|
|
| 164 |
// [pair.piecewise], pair piecewise construction
|
| 165 |
struct piecewise_construct_t {
|
| 166 |
explicit piecewise_construct_t() = default;
|
| 167 |
};
|
| 168 |
inline constexpr piecewise_construct_t piecewise_construct{};
|
| 169 |
+
template<class... Types> class tuple; // defined in <tuple>
|
| 170 |
+
|
| 171 |
+
// in-place construction%
|
| 172 |
+
%
|
| 173 |
+
%
|
| 174 |
+
%
|
| 175 |
+
%
|
| 176 |
+
%
|
| 177 |
|
|
|
|
| 178 |
struct in_place_t {
|
| 179 |
explicit in_place_t() = default;
|
| 180 |
};
|
| 181 |
inline constexpr in_place_t in_place{};
|
| 182 |
+
|
| 183 |
template<class T>
|
| 184 |
struct in_place_type_t {
|
| 185 |
explicit in_place_type_t() = default;
|
| 186 |
};
|
| 187 |
template<class T> inline constexpr in_place_type_t<T> in_place_type{};
|
| 188 |
+
|
| 189 |
template<size_t I>
|
| 190 |
struct in_place_index_t {
|
| 191 |
explicit in_place_index_t() = default;
|
| 192 |
};
|
| 193 |
template<size_t I> inline constexpr in_place_index_t<I> in_place_index{};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
}
|
| 195 |
```
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
### `swap` <a id="utility.swap">[[utility.swap]]</a>
|
| 198 |
|
| 199 |
``` cpp
|
| 200 |
template<class T>
|
| 201 |
+
constexpr void swap(T& a, T& b) noexcept(see below);
|
| 202 |
```
|
| 203 |
|
| 204 |
+
*Constraints:* `is_move_constructible_v<T>` is `true` and
|
| 205 |
+
`is_move_assignable_v<T>` is `true`.
|
|
|
|
|
|
|
| 206 |
|
| 207 |
+
*Preconditions:* Type `T` meets the *Cpp17MoveConstructible*
|
| 208 |
+
([[cpp17.moveconstructible]]) and *Cpp17MoveAssignable*
|
| 209 |
+
([[cpp17.moveassignable]]) requirements.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
*Effects:* Exchanges values stored in two locations.
|
| 212 |
|
| 213 |
+
*Remarks:* This function is a designated customization
|
| 214 |
+
point [[namespace.std]]. The expression inside `noexcept` is equivalent
|
| 215 |
+
to:
|
| 216 |
+
|
| 217 |
+
``` cpp
|
| 218 |
+
is_nothrow_move_constructible_v<T> && is_nothrow_move_assignable_v<T>
|
| 219 |
+
```
|
| 220 |
+
|
| 221 |
``` cpp
|
| 222 |
template<class T, size_t N>
|
| 223 |
+
constexpr void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v<T>);
|
| 224 |
```
|
| 225 |
|
| 226 |
+
*Constraints:* `is_swappable_v<T>` is `true`.
|
|
|
|
| 227 |
|
| 228 |
+
*Preconditions:* `a[i]` is swappable with [[swappable.requirements]]
|
| 229 |
`b[i]` for all `i` in the range \[`0`, `N`).
|
| 230 |
|
| 231 |
*Effects:* As if by `swap_ranges(a, a + N, b)`.
|
| 232 |
|
| 233 |
### `exchange` <a id="utility.exchange">[[utility.exchange]]</a>
|
| 234 |
|
| 235 |
``` cpp
|
| 236 |
+
template<class T, class U = T>
|
| 237 |
+
constexpr T exchange(T& obj, U&& new_val);
|
| 238 |
```
|
| 239 |
|
| 240 |
*Effects:* Equivalent to:
|
| 241 |
|
| 242 |
``` cpp
|
|
|
|
| 248 |
### Forward/move helpers <a id="forward">[[forward]]</a>
|
| 249 |
|
| 250 |
The library provides templated helper functions to simplify applying
|
| 251 |
move semantics to an lvalue and to simplify the implementation of
|
| 252 |
forwarding functions. All functions specified in this subclause are
|
| 253 |
+
signal-safe [[support.signal]].
|
| 254 |
|
| 255 |
``` cpp
|
| 256 |
template<class T> constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 257 |
template<class T> constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
|
| 258 |
```
|
| 259 |
|
| 260 |
+
*Mandates:* For the second overload, `is_lvalue_reference_v<T>` is
|
| 261 |
+
`false`.
|
| 262 |
+
|
| 263 |
*Returns:* `static_cast<T&&>(t)`.
|
| 264 |
|
|
|
|
|
|
|
|
|
|
| 265 |
[*Example 1*:
|
| 266 |
|
| 267 |
``` cpp
|
| 268 |
template<class T, class A1, class A2>
|
| 269 |
shared_ptr<T> factory(A1&& a1, A2&& a2) {
|
|
|
|
| 331 |
move_if_noexcept(T& x) noexcept;
|
| 332 |
```
|
| 333 |
|
| 334 |
*Returns:* `std::move(x)`.
|
| 335 |
|
| 336 |
+
### Function template `as_const` <a id="utility.as.const">[[utility.as.const]]</a>
|
| 337 |
|
| 338 |
``` cpp
|
| 339 |
template<class T> constexpr add_const_t<T>& as_const(T& t) noexcept;
|
| 340 |
```
|
| 341 |
|
| 342 |
*Returns:* `t`.
|
| 343 |
|
| 344 |
### Function template `declval` <a id="declval">[[declval]]</a>
|
| 345 |
|
| 346 |
The library provides the function template `declval` to simplify the
|
| 347 |
+
definition of expressions which occur as unevaluated operands
|
| 348 |
+
[[expr.prop]].
|
| 349 |
|
| 350 |
``` cpp
|
| 351 |
template<class T> add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
| 352 |
```
|
| 353 |
|
| 354 |
+
*Mandates:* This function is not odr-used [[basic.def.odr]].
|
|
|
|
| 355 |
|
| 356 |
*Remarks:* The template parameter `T` of `declval` may be an incomplete
|
| 357 |
type.
|
| 358 |
|
| 359 |
[*Example 1*:
|
|
|
|
| 362 |
template<class To, class From> decltype(static_cast<To>(declval<From>())) convert(From&&);
|
| 363 |
```
|
| 364 |
|
| 365 |
declares a function template `convert` which only participates in
|
| 366 |
overloading if the type `From` can be explicitly converted to type `To`.
|
| 367 |
+
For another example see class template `common_type`
|
| 368 |
+
[[meta.trans.other]].
|
| 369 |
|
| 370 |
— *end example*]
|
| 371 |
|
| 372 |
+
### Integer comparison functions <a id="utility.intcmp">[[utility.intcmp]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
``` cpp
|
| 375 |
+
template<class T, class U>
|
| 376 |
+
constexpr bool cmp_equal(T t, U u) noexcept;
|
| 377 |
```
|
| 378 |
|
| 379 |
+
*Mandates:* Both `T` and `U` are standard integer types or extended
|
| 380 |
+
integer types [[basic.fundamental]].
|
| 381 |
|
| 382 |
+
*Effects:* Equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
|
| 384 |
``` cpp
|
| 385 |
+
using UT = make_unsigned_t<T>;
|
| 386 |
+
using UU = make_unsigned_t<U>;
|
| 387 |
+
if constexpr (is_signed_v<T> == is_signed_v<U>)
|
| 388 |
+
return t == u;
|
| 389 |
+
else if constexpr (is_signed_v<T>)
|
| 390 |
+
return t < 0 ? false : UT(t) == u;
|
| 391 |
+
else
|
| 392 |
+
return u < 0 ? false : t == UU(u);
|
| 393 |
```
|
| 394 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
``` cpp
|
| 396 |
+
template<class T, class U>
|
| 397 |
+
constexpr bool cmp_not_equal(T t, U u) noexcept;
|
|
|
|
| 398 |
```
|
| 399 |
|
| 400 |
+
*Effects:* Equivalent to: `return !cmp_equal(t, u);`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
|
| 402 |
``` cpp
|
| 403 |
+
template<class T, class U>
|
| 404 |
+
constexpr bool cmp_less(T t, U u) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
```
|
| 406 |
|
| 407 |
+
*Mandates:* Both `T` and `U` are standard integer types or extended
|
| 408 |
+
integer types [[basic.fundamental]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
|
| 410 |
+
*Effects:* Equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
|
| 412 |
``` cpp
|
| 413 |
+
using UT = make_unsigned_t<T>;
|
| 414 |
+
using UU = make_unsigned_t<U>;
|
| 415 |
+
if constexpr (is_signed_v<T> == is_signed_v<U>)
|
| 416 |
+
return t < u;
|
| 417 |
+
else if constexpr (is_signed_v<T>)
|
| 418 |
+
return t < 0 ? true : UT(t) < u;
|
| 419 |
+
else
|
| 420 |
+
return u < 0 ? false : t < UU(u);
|
| 421 |
```
|
| 422 |
|
| 423 |
+
``` cpp
|
| 424 |
+
template<class T, class U>
|
| 425 |
+
constexpr bool cmp_greater(T t, U u) noexcept;
|
| 426 |
+
```
|
| 427 |
|
| 428 |
+
*Effects:* Equivalent to: `return cmp_less(u, t);`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
|
| 430 |
+
``` cpp
|
| 431 |
+
template<class T, class U>
|
| 432 |
+
constexpr bool cmp_less_equal(T t, U u) noexcept;
|
| 433 |
+
```
|
| 434 |
|
| 435 |
+
*Effects:* Equivalent to: `return !cmp_greater(t, u);`
|
|
|
|
|
|
|
| 436 |
|
| 437 |
``` cpp
|
| 438 |
+
template<class T, class U>
|
| 439 |
+
constexpr bool cmp_greater_equal(T t, U u) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
```
|
| 441 |
|
| 442 |
+
*Effects:* Equivalent to: `return !cmp_less(t, u);`
|
|
|
|
| 443 |
|
| 444 |
+
``` cpp
|
| 445 |
+
template<class R, class T>
|
| 446 |
+
constexpr bool in_range(T t) noexcept;
|
| 447 |
+
```
|
| 448 |
|
| 449 |
+
*Mandates:* Both `T` and `R` are standard integer types or extended
|
| 450 |
+
integer types [[basic.fundamental]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
|
| 452 |
+
*Effects:* Equivalent to:
|
|
|
|
| 453 |
|
| 454 |
+
``` cpp
|
| 455 |
+
return cmp_greater_equal(t, numeric_limits<R>::min()) &&
|
| 456 |
+
cmp_less_equal(t, numeric_limits<R>::max());
|
| 457 |
+
```
|
| 458 |
|
| 459 |
+
[*Note 1*: These function templates cannot be used to compare `byte`,
|
| 460 |
+
`char`, `char8_t`, `char16_t`, `char32_t`, `wchar_t`, and
|
| 461 |
+
`bool`. — *end note*]
|
| 462 |
|
| 463 |
## Compile-time integer sequences <a id="intseq">[[intseq]]</a>
|
| 464 |
|
| 465 |
### In general <a id="intseq.general">[[intseq.general]]</a>
|
| 466 |
|
| 467 |
The library provides a class template that can represent an integer
|
| 468 |
+
sequence. When used as an argument to a function template the template
|
| 469 |
+
parameter pack defining the sequence can be deduced and used in a pack
|
| 470 |
+
expansion.
|
| 471 |
|
| 472 |
[*Note 1*: The `index_sequence` alias template is provided for the
|
| 473 |
common case of an integer sequence of type `size_t`; see also
|
| 474 |
[[tuple.apply]]. — *end note*]
|
| 475 |
|
| 476 |
### Class template `integer_sequence` <a id="intseq.intseq">[[intseq.intseq]]</a>
|
| 477 |
|
| 478 |
``` cpp
|
| 479 |
namespace std {
|
| 480 |
+
template<class T, T... I> struct integer_sequence {
|
|
|
|
| 481 |
using value_type = T;
|
| 482 |
static constexpr size_t size() noexcept { return sizeof...(I); }
|
| 483 |
};
|
| 484 |
}
|
| 485 |
```
|
| 486 |
|
| 487 |
+
*Mandates:* `T` is an integer type.
|
| 488 |
|
| 489 |
### Alias template `make_integer_sequence` <a id="intseq.make">[[intseq.make]]</a>
|
| 490 |
|
| 491 |
``` cpp
|
| 492 |
template<class T, T N>
|
| 493 |
using make_integer_sequence = integer_sequence<T, see below>;
|
| 494 |
```
|
| 495 |
|
| 496 |
+
*Mandates:* `N` ≥ 0.
|
| 497 |
+
|
| 498 |
+
The alias template `make_integer_sequence` denotes a specialization of
|
| 499 |
+
`integer_sequence` with `N` non-type template arguments. The type
|
| 500 |
+
`make_integer_sequence<T, N>` is an alias for the type
|
| 501 |
`integer_sequence<T, 0, 1, ..., N-1>`.
|
| 502 |
|
| 503 |
+
[*Note 1*: `make_integer_sequence<int, 0>` is an alias for the type
|
| 504 |
+
`integer_sequence<int>`. — *end note*]
|
| 505 |
|
| 506 |
## Pairs <a id="pairs">[[pairs]]</a>
|
| 507 |
|
| 508 |
### In general <a id="pairs.general">[[pairs.general]]</a>
|
| 509 |
|
|
|
|
| 525 |
T1 first;
|
| 526 |
T2 second;
|
| 527 |
|
| 528 |
pair(const pair&) = default;
|
| 529 |
pair(pair&&) = default;
|
| 530 |
+
constexpr explicit(see below) pair();
|
| 531 |
+
constexpr explicit(see below) pair(const T1& x, const T2& y);
|
| 532 |
+
template<class U1, class U2>
|
| 533 |
+
constexpr explicit(see below) pair(U1&& x, U2&& y);
|
| 534 |
+
template<class U1, class U2>
|
| 535 |
+
constexpr explicit(see below) pair(const pair<U1, U2>& p);
|
| 536 |
+
template<class U1, class U2>
|
| 537 |
+
constexpr explicit(see below) pair(pair<U1, U2>&& p);
|
| 538 |
template<class... Args1, class... Args2>
|
| 539 |
+
constexpr pair(piecewise_construct_t,
|
| 540 |
+
tuple<Args1...> first_args, tuple<Args2...> second_args);
|
| 541 |
|
| 542 |
+
constexpr pair& operator=(const pair& p);
|
| 543 |
+
template<class U1, class U2>
|
| 544 |
+
constexpr pair& operator=(const pair<U1, U2>& p);
|
| 545 |
+
constexpr pair& operator=(pair&& p) noexcept(see below);
|
| 546 |
+
template<class U1, class U2>
|
| 547 |
+
constexpr pair& operator=(pair<U1, U2>&& p);
|
| 548 |
|
| 549 |
+
constexpr void swap(pair& p) noexcept(see below);
|
| 550 |
};
|
| 551 |
|
| 552 |
template<class T1, class T2>
|
| 553 |
pair(T1, T2) -> pair<T1, T2>;
|
| 554 |
}
|
| 555 |
```
|
| 556 |
|
| 557 |
+
Constructors and member functions of `pair` do not throw exceptions
|
| 558 |
unless one of the element-wise operations specified to be called for
|
| 559 |
that operation throws an exception.
|
| 560 |
|
| 561 |
+
The defaulted move and copy constructor, respectively, of `pair` is a
|
| 562 |
+
constexpr function if and only if all required element-wise
|
| 563 |
+
initializations for move and copy, respectively, would satisfy the
|
| 564 |
+
requirements for a constexpr function.
|
| 565 |
+
|
| 566 |
+
If
|
| 567 |
`(is_trivially_destructible_v<T1> && is_trivially_destructible_v<T2>)`
|
| 568 |
+
is `true`, then the destructor of `pair` is trivial.
|
| 569 |
+
|
| 570 |
+
`pair<T, U>` is a structural type [[temp.param]] if `T` and `U` are both
|
| 571 |
+
structural types. Two values `p1` and `p2` of type `pair<T, U>` are
|
| 572 |
+
template-argument-equivalent [[temp.type]] if and only if `p1.first` and
|
| 573 |
+
`p2.first` are template-argument-equivalent and `p1.second` and
|
| 574 |
+
`p2.second` are template-argument-equivalent.
|
| 575 |
|
| 576 |
``` cpp
|
| 577 |
+
constexpr explicit(see below) pair();
|
| 578 |
```
|
| 579 |
|
| 580 |
+
*Constraints:*
|
| 581 |
+
|
| 582 |
+
- `is_default_constructible_v<first_type>` is `true` and
|
| 583 |
+
- `is_default_constructible_v<second_type>` is `true`.
|
| 584 |
+
|
| 585 |
*Effects:* Value-initializes `first` and `second`.
|
| 586 |
|
| 587 |
+
*Remarks:* The expression inside `explicit` evaluates to `true` if and
|
| 588 |
+
only if either `first_type` or `second_type` is not implicitly
|
| 589 |
+
default-constructible.
|
| 590 |
|
| 591 |
+
[*Note 1*: This behavior can be implemented with a trait that checks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
whether a `const first_type&` or a `const second_type&` can be
|
| 593 |
initialized with `{}`. — *end note*]
|
| 594 |
|
| 595 |
``` cpp
|
| 596 |
+
constexpr explicit(see below) pair(const T1& x, const T2& y);
|
| 597 |
```
|
| 598 |
|
| 599 |
+
*Constraints:*
|
| 600 |
+
|
| 601 |
+
- `is_copy_constructible_v<first_type>` is `true` and
|
| 602 |
+
- `is_copy_constructible_v<second_type>` is `true`.
|
| 603 |
+
|
| 604 |
*Effects:* Initializes `first` with `x` and `second` with `y`.
|
| 605 |
|
| 606 |
+
*Remarks:* The expression inside `explicit` is equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
|
| 608 |
``` cpp
|
| 609 |
+
!is_convertible_v<const first_type&, first_type> ||
|
| 610 |
+
!is_convertible_v<const second_type&, second_type>
|
| 611 |
```
|
| 612 |
|
| 613 |
+
``` cpp
|
| 614 |
+
template<class U1, class U2> constexpr explicit(see below) pair(U1&& x, U2&& y);
|
| 615 |
+
```
|
| 616 |
+
|
| 617 |
+
*Constraints:*
|
| 618 |
+
|
| 619 |
+
- `is_constructible_v<first_type, U1>` is `true` and
|
| 620 |
+
- `is_constructible_v<second_type, U2>` is `true`.
|
| 621 |
+
|
| 622 |
*Effects:* Initializes `first` with `std::forward<U1>(x)` and `second`
|
| 623 |
with `std::forward<U2>(y)`.
|
| 624 |
|
| 625 |
+
*Remarks:* The expression inside `explicit` is equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 626 |
|
| 627 |
``` cpp
|
| 628 |
+
!is_convertible_v<U1, first_type> || !is_convertible_v<U2, second_type>
|
| 629 |
```
|
| 630 |
|
| 631 |
+
``` cpp
|
| 632 |
+
template<class U1, class U2> constexpr explicit(see below) pair(const pair<U1, U2>& p);
|
| 633 |
+
```
|
| 634 |
+
|
| 635 |
+
*Constraints:*
|
| 636 |
+
|
| 637 |
+
- `is_constructible_v<first_type, const U1&>` is `true` and
|
| 638 |
+
- `is_constructible_v<second_type, const U2&>` is `true`.
|
| 639 |
+
|
| 640 |
*Effects:* Initializes members from the corresponding members of the
|
| 641 |
argument.
|
| 642 |
|
| 643 |
+
*Remarks:* The expression inside explicit is equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 644 |
|
| 645 |
``` cpp
|
| 646 |
+
!is_convertible_v<const U1&, first_type> || !is_convertible_v<const U2&, second_type>
|
| 647 |
```
|
| 648 |
|
| 649 |
+
``` cpp
|
| 650 |
+
template<class U1, class U2> constexpr explicit(see below) pair(pair<U1, U2>&& p);
|
| 651 |
+
```
|
| 652 |
+
|
| 653 |
+
*Constraints:*
|
| 654 |
+
|
| 655 |
+
- `is_constructible_v<first_type, U1>` is `true` and
|
| 656 |
+
- `is_constructible_v<second_type, U2>` is `true`.
|
| 657 |
+
|
| 658 |
*Effects:* Initializes `first` with `std::forward<U1>(p.first)` and
|
| 659 |
`second` with `std::forward<U2>(p.second)`.
|
| 660 |
|
| 661 |
+
*Remarks:* The expression inside explicit is equivalent to:
|
| 662 |
+
|
| 663 |
+
``` cpp
|
| 664 |
+
!is_convertible_v<U1, first_type> || !is_convertible_v<U2, second_type>
|
| 665 |
+
```
|
| 666 |
|
| 667 |
``` cpp
|
| 668 |
template<class... Args1, class... Args2>
|
| 669 |
+
constexpr pair(piecewise_construct_t,
|
| 670 |
+
tuple<Args1...> first_args, tuple<Args2...> second_args);
|
| 671 |
```
|
| 672 |
|
| 673 |
+
*Mandates:*
|
| 674 |
+
|
| 675 |
+
- `is_constructible_v<first_type, Args1...>` is `true` and
|
| 676 |
+
- `is_constructible_v<second_type, Args2...>` is `true`.
|
| 677 |
|
| 678 |
*Effects:* Initializes `first` with arguments of types `Args1...`
|
| 679 |
obtained by forwarding the elements of `first_args` and initializes
|
| 680 |
`second` with arguments of types `Args2...` obtained by forwarding the
|
| 681 |
elements of `second_args`. (Here, forwarding an element `x` of type `U`
|
|
|
|
| 683 |
of construction, whereby constructor arguments for `first` and `second`
|
| 684 |
are each provided in a separate `tuple` object, is called *piecewise
|
| 685 |
construction*.
|
| 686 |
|
| 687 |
``` cpp
|
| 688 |
+
constexpr pair& operator=(const pair& p);
|
| 689 |
```
|
| 690 |
|
| 691 |
*Effects:* Assigns `p.first` to `first` and `p.second` to `second`.
|
| 692 |
|
| 693 |
+
*Remarks:* This operator is defined as deleted unless
|
| 694 |
`is_copy_assignable_v<first_type>` is `true` and
|
| 695 |
`is_copy_assignable_v<second_type>` is `true`.
|
| 696 |
|
| 697 |
*Returns:* `*this`.
|
| 698 |
|
| 699 |
``` cpp
|
| 700 |
+
template<class U1, class U2> constexpr pair& operator=(const pair<U1, U2>& p);
|
| 701 |
```
|
| 702 |
|
| 703 |
+
*Constraints:*
|
| 704 |
+
|
| 705 |
+
- `is_assignable_v<first_type&, const U1&>` is `true` and
|
| 706 |
+
- `is_assignable_v<second_type&, const U2&>` is `true`.
|
| 707 |
+
|
| 708 |
*Effects:* Assigns `p.first` to `first` and `p.second` to `second`.
|
| 709 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 710 |
*Returns:* `*this`.
|
| 711 |
|
| 712 |
``` cpp
|
| 713 |
+
constexpr pair& operator=(pair&& p) noexcept(see below);
|
| 714 |
```
|
| 715 |
|
| 716 |
+
*Constraints:*
|
| 717 |
+
|
| 718 |
+
- `is_move_assignable_v<first_type>` is `true` and
|
| 719 |
+
- `is_move_assignable_v<second_type>` is `true`.
|
| 720 |
+
|
| 721 |
*Effects:* Assigns to `first` with `std::forward<first_type>(p.first)`
|
| 722 |
and to `second` with
|
| 723 |
`std::forward<second_type>(p.second)`.
|
| 724 |
|
| 725 |
+
*Returns:* `*this`.
|
|
|
|
|
|
|
| 726 |
|
| 727 |
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 728 |
|
| 729 |
``` cpp
|
| 730 |
is_nothrow_move_assignable_v<T1> && is_nothrow_move_assignable_v<T2>
|
| 731 |
```
|
| 732 |
|
|
|
|
|
|
|
| 733 |
``` cpp
|
| 734 |
+
template<class U1, class U2> constexpr pair& operator=(pair<U1, U2>&& p);
|
| 735 |
```
|
| 736 |
|
| 737 |
+
*Constraints:*
|
| 738 |
+
|
| 739 |
+
- `is_assignable_v<first_type&, U1>` is `true` and
|
| 740 |
+
- `is_assignable_v<second_type&, U2>` is `true`.
|
| 741 |
+
|
| 742 |
+
*Effects:* Assigns to `first` with `std::forward<U1>(p.first)` and to
|
| 743 |
`second` with
|
| 744 |
+
`std::forward<U2>(p.second)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 745 |
|
| 746 |
*Returns:* `*this`.
|
| 747 |
|
| 748 |
``` cpp
|
| 749 |
+
constexpr void swap(pair& p) noexcept(see below);
|
| 750 |
```
|
| 751 |
|
| 752 |
+
*Preconditions:* `first` is swappable with [[swappable.requirements]]
|
| 753 |
+
`p.first` and `second` is swappable with `p.second`.
|
|
|
|
| 754 |
|
| 755 |
*Effects:* Swaps `first` with `p.first` and `second` with `p.second`.
|
| 756 |
|
| 757 |
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 758 |
|
|
|
|
| 769 |
|
| 770 |
*Returns:* `x.first == y.first && x.second == y.second`.
|
| 771 |
|
| 772 |
``` cpp
|
| 773 |
template<class T1, class T2>
|
| 774 |
+
constexpr common_comparison_category_t<synth-three-way-result<T1>,
|
| 775 |
+
synth-three-way-result<T2>>
|
| 776 |
+
operator<=>(const pair<T1, T2>& x, const pair<T1, T2>& y);
|
| 777 |
+
```
|
| 778 |
+
|
| 779 |
+
*Effects:* Equivalent to:
|
| 780 |
+
|
| 781 |
+
``` cpp
|
| 782 |
+
if (auto c = synth-three-way(x.first, y.first); c != 0) return c;
|
| 783 |
+
return synth-three-way(x.second, y.second);
|
| 784 |
+
```
|
| 785 |
+
|
| 786 |
+
``` cpp
|
| 787 |
+
template<class T1, class T2>
|
| 788 |
+
constexpr void swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
|
| 789 |
+
```
|
| 790 |
+
|
| 791 |
+
*Constraints:* `is_swappable_v<T1>` is `true` and `is_swappable_v<T2>`
|
| 792 |
+
is `true`.
|
| 793 |
+
|
| 794 |
+
*Effects:* Equivalent to `x.swap(y)`.
|
| 795 |
+
|
| 796 |
+
``` cpp
|
| 797 |
+
template<class T1, class T2>
|
| 798 |
+
constexpr pair<unwrap_ref_decay_t<T1>, unwrap_ref_decay_t<T2>> make_pair(T1&& x, T2&& y);
|
| 799 |
```
|
| 800 |
|
| 801 |
*Returns:*
|
|
|
|
| 802 |
|
| 803 |
``` cpp
|
| 804 |
+
pair<unwrap_ref_decay_t<T1>,
|
| 805 |
+
unwrap_ref_decay_t<T2>>(std::forward<T1>(x), std::forward<T2>(y))
|
| 806 |
```
|
| 807 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 808 |
[*Example 1*:
|
| 809 |
|
| 810 |
In place of:
|
| 811 |
|
| 812 |
``` cpp
|
|
|
|
| 827 |
template<class T1, class T2>
|
| 828 |
struct tuple_size<pair<T1, T2>> : integral_constant<size_t, 2> { };
|
| 829 |
```
|
| 830 |
|
| 831 |
``` cpp
|
| 832 |
+
template<size_t I, class T1, class T2>
|
| 833 |
+
struct tuple_element<I, pair<T1, T2>> {
|
| 834 |
+
using type = see below ;
|
| 835 |
+
};
|
| 836 |
```
|
| 837 |
|
| 838 |
+
*Mandates:* `I` < 2.
|
| 839 |
|
| 840 |
+
*Type:* The type `T1` if `I` is 0, otherwise the type `T2`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 841 |
|
| 842 |
``` cpp
|
| 843 |
template<size_t I, class T1, class T2>
|
| 844 |
constexpr tuple_element_t<I, pair<T1, T2>>& get(pair<T1, T2>& p) noexcept;
|
| 845 |
template<size_t I, class T1, class T2>
|
|
|
|
| 848 |
constexpr tuple_element_t<I, pair<T1, T2>>&& get(pair<T1, T2>&& p) noexcept;
|
| 849 |
template<size_t I, class T1, class T2>
|
| 850 |
constexpr const tuple_element_t<I, pair<T1, T2>>&& get(const pair<T1, T2>&& p) noexcept;
|
| 851 |
```
|
| 852 |
|
| 853 |
+
*Mandates:* `I` < 2.
|
| 854 |
+
|
| 855 |
+
*Returns:*
|
| 856 |
+
|
| 857 |
+
- If `I` is 0, returns a reference to `p.first`.
|
| 858 |
+
- If `I` is 1, returns a reference to `p.second`.
|
| 859 |
|
| 860 |
``` cpp
|
| 861 |
template<class T1, class T2>
|
| 862 |
constexpr T1& get(pair<T1, T2>& p) noexcept;
|
| 863 |
template<class T1, class T2>
|
|
|
|
| 866 |
constexpr T1&& get(pair<T1, T2>&& p) noexcept;
|
| 867 |
template<class T1, class T2>
|
| 868 |
constexpr const T1&& get(const pair<T1, T2>&& p) noexcept;
|
| 869 |
```
|
| 870 |
|
| 871 |
+
*Mandates:* `T1` and `T2` are distinct types.
|
|
|
|
| 872 |
|
| 873 |
*Returns:* A reference to `p.first`.
|
| 874 |
|
| 875 |
``` cpp
|
| 876 |
template<class T2, class T1>
|
|
|
|
| 881 |
constexpr T2&& get(pair<T1, T2>&& p) noexcept;
|
| 882 |
template<class T2, class T1>
|
| 883 |
constexpr const T2&& get(const pair<T1, T2>&& p) noexcept;
|
| 884 |
```
|
| 885 |
|
| 886 |
+
*Mandates:* `T1` and `T2` are distinct types.
|
|
|
|
| 887 |
|
| 888 |
*Returns:* A reference to `p.second`.
|
| 889 |
|
| 890 |
### Piecewise construction <a id="pair.piecewise">[[pair.piecewise]]</a>
|
| 891 |
|
|
|
|
| 894 |
explicit piecewise_construct_t() = default;
|
| 895 |
};
|
| 896 |
inline constexpr piecewise_construct_t piecewise_construct{};
|
| 897 |
```
|
| 898 |
|
| 899 |
+
The `struct` `piecewise_construct_t` is an empty class type used as a
|
| 900 |
+
unique type to disambiguate constructor and function overloading.
|
| 901 |
Specifically, `pair` has a constructor with `piecewise_construct_t` as
|
| 902 |
+
the first argument, immediately followed by two `tuple` [[tuple]]
|
| 903 |
arguments used for piecewise construction of the elements of the `pair`
|
| 904 |
object.
|
| 905 |
|
| 906 |
## Tuples <a id="tuple">[[tuple]]</a>
|
| 907 |
|
| 908 |
### In general <a id="tuple.general">[[tuple.general]]</a>
|
| 909 |
|
| 910 |
+
Subclause [[tuple]] describes the tuple library that provides a tuple
|
| 911 |
+
type as the class template `tuple` that can be instantiated with any
|
| 912 |
+
number of arguments. Each template argument specifies the type of an
|
| 913 |
+
element in the `tuple`. Consequently, tuples are heterogeneous,
|
| 914 |
+
fixed-size collections of values. An instantiation of `tuple` with two
|
| 915 |
+
arguments is similar to an instantiation of `pair` with the same two
|
| 916 |
+
arguments. See [[pairs]].
|
| 917 |
|
| 918 |
### Header `<tuple>` synopsis <a id="tuple.syn">[[tuple.syn]]</a>
|
| 919 |
|
| 920 |
``` cpp
|
| 921 |
+
#include <compare> // see [compare.syn]
|
| 922 |
+
|
| 923 |
namespace std {
|
| 924 |
// [tuple.tuple], class template tuple
|
| 925 |
template<class... Types>
|
| 926 |
class tuple;
|
| 927 |
|
| 928 |
// [tuple.creation], tuple creation functions
|
| 929 |
inline constexpr unspecified ignore;
|
| 930 |
|
| 931 |
template<class... TTypes>
|
| 932 |
+
constexpr tuple<unwrap_ref_decay_t<TTypes>...> make_tuple(TTypes&&...);
|
| 933 |
|
| 934 |
template<class... TTypes>
|
| 935 |
constexpr tuple<TTypes&&...> forward_as_tuple(TTypes&&...) noexcept;
|
| 936 |
|
| 937 |
template<class... TTypes>
|
|
|
|
| 946 |
|
| 947 |
template<class T, class Tuple>
|
| 948 |
constexpr T make_from_tuple(Tuple&& t);
|
| 949 |
|
| 950 |
// [tuple.helper], tuple helper classes
|
| 951 |
+
template<class T> struct tuple_size; // not defined
|
| 952 |
+
template<class T> struct tuple_size<const T>;
|
|
|
|
|
|
|
| 953 |
|
| 954 |
+
template<class... Types> struct tuple_size<tuple<Types...>>;
|
| 955 |
|
| 956 |
+
template<size_t I, class T> struct tuple_element; // not defined
|
| 957 |
+
template<size_t I, class T> struct tuple_element<I, const T>;
|
|
|
|
|
|
|
| 958 |
|
| 959 |
template<size_t I, class... Types>
|
| 960 |
+
struct tuple_element<I, tuple<Types...>>;
|
| 961 |
|
| 962 |
template<size_t I, class T>
|
| 963 |
using tuple_element_t = typename tuple_element<I, T>::type;
|
| 964 |
|
| 965 |
// [tuple.elem], element access
|
|
|
|
| 982 |
|
| 983 |
// [tuple.rel], relational operators
|
| 984 |
template<class... TTypes, class... UTypes>
|
| 985 |
constexpr bool operator==(const tuple<TTypes...>&, const tuple<UTypes...>&);
|
| 986 |
template<class... TTypes, class... UTypes>
|
| 987 |
+
constexpr common_comparison_category_t<synth-three-way-result<TTypes, UTypes>...>
|
| 988 |
+
operator<=>(const tuple<TTypes...>&, const tuple<UTypes...>&);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 989 |
|
| 990 |
// [tuple.traits], allocator-related traits
|
| 991 |
template<class... Types, class Alloc>
|
| 992 |
struct uses_allocator<tuple<Types...>, Alloc>;
|
| 993 |
|
| 994 |
// [tuple.special], specialized algorithms
|
| 995 |
template<class... Types>
|
| 996 |
+
constexpr void swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(see below);
|
| 997 |
|
| 998 |
// [tuple.helper], tuple helper classes
|
| 999 |
template<class T>
|
| 1000 |
inline constexpr size_t tuple_size_v = tuple_size<T>::value;
|
| 1001 |
}
|
|
|
|
| 1007 |
namespace std {
|
| 1008 |
template<class... Types>
|
| 1009 |
class tuple {
|
| 1010 |
public:
|
| 1011 |
// [tuple.cnstr], tuple construction
|
| 1012 |
+
constexpr explicit(see below) tuple();
|
| 1013 |
+
constexpr explicit(see below) tuple(const Types&...); // only if sizeof...(Types) >= 1
|
| 1014 |
template<class... UTypes>
|
| 1015 |
+
constexpr explicit(see below) tuple(UTypes&&...); // only if sizeof...(Types) >= 1
|
| 1016 |
|
| 1017 |
tuple(const tuple&) = default;
|
| 1018 |
tuple(tuple&&) = default;
|
| 1019 |
|
| 1020 |
template<class... UTypes>
|
| 1021 |
+
constexpr explicit(see below) tuple(const tuple<UTypes...>&);
|
| 1022 |
template<class... UTypes>
|
| 1023 |
+
constexpr explicit(see below) tuple(tuple<UTypes...>&&);
|
| 1024 |
|
| 1025 |
template<class U1, class U2>
|
| 1026 |
+
constexpr explicit(see below) tuple(const pair<U1, U2>&); // only if sizeof...(Types) == 2
|
| 1027 |
template<class U1, class U2>
|
| 1028 |
+
constexpr explicit(see below) tuple(pair<U1, U2>&&); // only if sizeof...(Types) == 2
|
| 1029 |
|
| 1030 |
// allocator-extended constructors
|
| 1031 |
template<class Alloc>
|
| 1032 |
+
constexpr explicit(see below)
|
| 1033 |
tuple(allocator_arg_t, const Alloc& a);
|
| 1034 |
template<class Alloc>
|
| 1035 |
+
constexpr explicit(see below)
|
| 1036 |
+
tuple(allocator_arg_t, const Alloc& a, const Types&...);
|
| 1037 |
template<class Alloc, class... UTypes>
|
| 1038 |
+
constexpr explicit(see below)
|
| 1039 |
+
tuple(allocator_arg_t, const Alloc& a, UTypes&&...);
|
| 1040 |
template<class Alloc>
|
| 1041 |
+
constexpr tuple(allocator_arg_t, const Alloc& a, const tuple&);
|
| 1042 |
template<class Alloc>
|
| 1043 |
+
constexpr tuple(allocator_arg_t, const Alloc& a, tuple&&);
|
| 1044 |
template<class Alloc, class... UTypes>
|
| 1045 |
+
constexpr explicit(see below)
|
| 1046 |
+
tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&);
|
| 1047 |
template<class Alloc, class... UTypes>
|
| 1048 |
+
constexpr explicit(see below)
|
| 1049 |
+
tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&);
|
| 1050 |
template<class Alloc, class U1, class U2>
|
| 1051 |
+
constexpr explicit(see below)
|
| 1052 |
+
tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
|
| 1053 |
template<class Alloc, class U1, class U2>
|
| 1054 |
+
constexpr explicit(see below)
|
| 1055 |
+
tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
|
| 1056 |
|
| 1057 |
// [tuple.assign], tuple assignment
|
| 1058 |
+
constexpr tuple& operator=(const tuple&);
|
| 1059 |
+
constexpr tuple& operator=(tuple&&) noexcept(see below);
|
| 1060 |
|
| 1061 |
template<class... UTypes>
|
| 1062 |
+
constexpr tuple& operator=(const tuple<UTypes...>&);
|
| 1063 |
template<class... UTypes>
|
| 1064 |
+
constexpr tuple& operator=(tuple<UTypes...>&&);
|
| 1065 |
|
| 1066 |
template<class U1, class U2>
|
| 1067 |
+
constexpr tuple& operator=(const pair<U1, U2>&); // only if sizeof...(Types) == 2
|
| 1068 |
template<class U1, class U2>
|
| 1069 |
+
constexpr tuple& operator=(pair<U1, U2>&&); // only if sizeof...(Types) == 2
|
| 1070 |
|
| 1071 |
// [tuple.swap], tuple swap
|
| 1072 |
+
constexpr void swap(tuple&) noexcept(see below);
|
| 1073 |
};
|
| 1074 |
|
| 1075 |
template<class... UTypes>
|
| 1076 |
tuple(UTypes...) -> tuple<UTypes...>;
|
| 1077 |
template<class T1, class T2>
|
|
|
|
| 1085 |
}
|
| 1086 |
```
|
| 1087 |
|
| 1088 |
#### Construction <a id="tuple.cnstr">[[tuple.cnstr]]</a>
|
| 1089 |
|
| 1090 |
+
In the descriptions that follow, let i be in the range \[`0`,
|
| 1091 |
+
`sizeof...(Types)`) in order, `Tᵢ` be the iᵗʰ type in `Types`, and `Uᵢ`
|
| 1092 |
+
be the iᵗʰ type in a template parameter pack named `UTypes`, where
|
| 1093 |
+
indexing is zero-based.
|
| 1094 |
+
|
| 1095 |
For each `tuple` constructor, an exception is thrown only if the
|
| 1096 |
construction of one of the types in `Types` throws an exception.
|
| 1097 |
|
| 1098 |
+
The defaulted move and copy constructor, respectively, of `tuple` is a
|
| 1099 |
+
constexpr function if and only if all required element-wise
|
| 1100 |
+
initializations for move and copy, respectively, would satisfy the
|
| 1101 |
requirements for a constexpr function. The defaulted move and copy
|
| 1102 |
+
constructor of `tuple<>` are constexpr functions.
|
| 1103 |
|
| 1104 |
+
If `is_trivially_destructible_v<Tᵢ>` is `true` for all `Tᵢ`, then the
|
| 1105 |
+
destructor of `tuple` is trivial.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1106 |
|
| 1107 |
``` cpp
|
| 1108 |
+
constexpr explicit(see below) tuple();
|
| 1109 |
```
|
| 1110 |
|
| 1111 |
+
*Constraints:* `is_default_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 1112 |
+
|
| 1113 |
*Effects:* Value-initializes each element.
|
| 1114 |
|
| 1115 |
+
*Remarks:* The expression inside `explicit` evaluates to `true` if and
|
| 1116 |
+
only if `Tᵢ` is not copy-list-initializable from an empty list for at
|
| 1117 |
+
least one i.
|
| 1118 |
|
| 1119 |
+
[*Note 1*: This behavior can be implemented with a trait that checks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1120 |
whether a `const ``Tᵢ``&` can be initialized with `{}`. — *end note*]
|
| 1121 |
|
| 1122 |
``` cpp
|
| 1123 |
+
constexpr explicit(see below) tuple(const Types&...);
|
| 1124 |
```
|
| 1125 |
|
| 1126 |
+
*Constraints:* `sizeof...(Types)` ≥ 1 and
|
| 1127 |
+
`is_copy_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 1128 |
+
|
| 1129 |
*Effects:* Initializes each element with the value of the corresponding
|
| 1130 |
parameter.
|
| 1131 |
|
| 1132 |
+
*Remarks:* The expression inside `explicit` is equivalent to:
|
|
|
|
|
|
|
|
|
|
| 1133 |
|
| 1134 |
``` cpp
|
| 1135 |
+
!conjunction_v<is_convertible<const Types&, Types>...>
|
| 1136 |
```
|
| 1137 |
|
| 1138 |
+
``` cpp
|
| 1139 |
+
template<class... UTypes> constexpr explicit(see below) tuple(UTypes&&... u);
|
| 1140 |
+
```
|
| 1141 |
+
|
| 1142 |
+
*Constraints:* `sizeof...(Types)` equals `sizeof...(UTypes)` and
|
| 1143 |
+
`sizeof...(Types)` ≥ 1 and `is_constructible_v<``Tᵢ``, ``Uᵢ``>` is
|
| 1144 |
+
`true` for all i.
|
| 1145 |
+
|
| 1146 |
*Effects:* Initializes the elements in the tuple with the corresponding
|
| 1147 |
value in `std::forward<UTypes>(u)`.
|
| 1148 |
|
| 1149 |
+
*Remarks:* The expression inside `explicit` is equivalent to:
|
| 1150 |
+
|
| 1151 |
+
``` cpp
|
| 1152 |
+
!conjunction_v<is_convertible<UTypes, Types>...>
|
| 1153 |
+
```
|
| 1154 |
|
| 1155 |
``` cpp
|
| 1156 |
tuple(const tuple& u) = default;
|
| 1157 |
```
|
| 1158 |
|
| 1159 |
+
*Mandates:* `is_copy_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 1160 |
|
| 1161 |
*Effects:* Initializes each element of `*this` with the corresponding
|
| 1162 |
element of `u`.
|
| 1163 |
|
| 1164 |
``` cpp
|
| 1165 |
tuple(tuple&& u) = default;
|
| 1166 |
```
|
| 1167 |
|
| 1168 |
+
*Constraints:* `is_move_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 1169 |
|
| 1170 |
*Effects:* For all i, initializes the iᵗʰ element of `*this` with
|
| 1171 |
`std::forward<``Tᵢ``>(get<`i`>(u))`.
|
| 1172 |
|
| 1173 |
``` cpp
|
| 1174 |
+
template<class... UTypes> constexpr explicit(see below) tuple(const tuple<UTypes...>& u);
|
| 1175 |
```
|
| 1176 |
|
| 1177 |
+
*Constraints:*
|
|
|
|
| 1178 |
|
| 1179 |
+
- `sizeof...(Types)` equals `sizeof...(UTypes)` and
|
|
|
|
|
|
|
|
|
|
| 1180 |
- `is_constructible_v<``Tᵢ``, const ``Uᵢ``&>` is `true` for all i, and
|
| 1181 |
+
- either `sizeof...(Types)` is not 1, or (when `Types...` expands to `T`
|
| 1182 |
+
and `UTypes...` expands to `U`)
|
| 1183 |
+
`is_convertible_v<const tuple<U>&, T>`,
|
| 1184 |
+
`is_constructible_v<T, const tuple<U>&>`, and `is_same_v<T, U>` are
|
| 1185 |
+
all `false`.
|
| 1186 |
|
| 1187 |
+
*Effects:* Initializes each element of `*this` with the corresponding
|
| 1188 |
+
element of `u`.
|
| 1189 |
+
|
| 1190 |
+
*Remarks:* The expression inside `explicit` is equivalent to:
|
| 1191 |
+
|
| 1192 |
+
``` cpp
|
| 1193 |
+
!conjunction_v<is_convertible<const UTypes&, Types>...>
|
| 1194 |
+
```
|
| 1195 |
|
| 1196 |
``` cpp
|
| 1197 |
+
template<class... UTypes> constexpr explicit(see below) tuple(tuple<UTypes...>&& u);
|
| 1198 |
```
|
| 1199 |
|
| 1200 |
+
*Constraints:*
|
| 1201 |
+
|
| 1202 |
+
- `sizeof...(Types)` equals `sizeof...(UTypes)`, and
|
| 1203 |
+
- `is_constructible_v<``Tᵢ``, ``Uᵢ``>` is `true` for all i, and
|
| 1204 |
+
- either `sizeof...(Types)` is not 1, or (when `Types...` expands to `T`
|
| 1205 |
+
and `UTypes...` expands to `U`) `is_convertible_v<tuple<U>, T>`,
|
| 1206 |
+
`is_constructible_v<T, tuple<U>>`, and `is_same_v<T, U>` are all
|
| 1207 |
+
`false`.
|
| 1208 |
+
|
| 1209 |
*Effects:* For all i, initializes the iᵗʰ element of `*this` with
|
| 1210 |
`std::forward<``Uᵢ``>(get<`i`>(u))`.
|
| 1211 |
|
| 1212 |
+
*Remarks:* The expression inside `explicit` is equivalent to:
|
|
|
|
| 1213 |
|
| 1214 |
+
``` cpp
|
| 1215 |
+
!conjunction_v<is_convertible<UTypes, Types>...>
|
| 1216 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1217 |
|
| 1218 |
``` cpp
|
| 1219 |
+
template<class U1, class U2> constexpr explicit(see below) tuple(const pair<U1, U2>& u);
|
| 1220 |
```
|
| 1221 |
|
| 1222 |
+
*Constraints:*
|
| 1223 |
+
|
| 1224 |
+
- `sizeof...(Types)` is 2,
|
| 1225 |
+
- `is_constructible_v<``T₀``, const U1&>` is `true`, and
|
| 1226 |
+
- `is_constructible_v<``T₁``, const U2&>` is `true`.
|
| 1227 |
+
|
| 1228 |
*Effects:* Initializes the first element with `u.first` and the second
|
| 1229 |
element with `u.second`.
|
| 1230 |
|
| 1231 |
+
The expression inside `explicit` is equivalent to:
|
|
|
|
|
|
|
| 1232 |
|
| 1233 |
+
``` cpp
|
| 1234 |
+
!is_convertible_v<const U1&, $T_0$> || !is_convertible_v<const U2&, $T_1$>
|
| 1235 |
+
```
|
| 1236 |
|
| 1237 |
``` cpp
|
| 1238 |
+
template<class U1, class U2> constexpr explicit(see below) tuple(pair<U1, U2>&& u);
|
| 1239 |
```
|
| 1240 |
|
| 1241 |
+
*Constraints:*
|
| 1242 |
+
|
| 1243 |
+
- `sizeof...(Types)` is 2,
|
| 1244 |
+
- `is_constructible_v<``T₀``, U1>` is `true`, and
|
| 1245 |
+
- `is_constructible_v<``T₁``, U2>` is `true`.
|
| 1246 |
+
|
| 1247 |
*Effects:* Initializes the first element with
|
| 1248 |
`std::forward<U1>(u.first)` and the second element with
|
| 1249 |
`std::forward<U2>(u.second)`.
|
| 1250 |
|
| 1251 |
+
The expression inside `explicit` is equivalent to:
|
|
|
|
|
|
|
| 1252 |
|
| 1253 |
+
``` cpp
|
| 1254 |
+
!is_convertible_v<U1, $T_0$> || !is_convertible_v<U2, $T_1$>
|
| 1255 |
+
```
|
| 1256 |
|
| 1257 |
``` cpp
|
| 1258 |
template<class Alloc>
|
| 1259 |
+
constexpr explicit(see below)
|
| 1260 |
tuple(allocator_arg_t, const Alloc& a);
|
| 1261 |
template<class Alloc>
|
| 1262 |
+
constexpr explicit(see below)
|
| 1263 |
+
tuple(allocator_arg_t, const Alloc& a, const Types&...);
|
| 1264 |
template<class Alloc, class... UTypes>
|
| 1265 |
+
constexpr explicit(see below)
|
| 1266 |
+
tuple(allocator_arg_t, const Alloc& a, UTypes&&...);
|
| 1267 |
template<class Alloc>
|
| 1268 |
+
constexpr tuple(allocator_arg_t, const Alloc& a, const tuple&);
|
| 1269 |
template<class Alloc>
|
| 1270 |
+
constexpr tuple(allocator_arg_t, const Alloc& a, tuple&&);
|
| 1271 |
template<class Alloc, class... UTypes>
|
| 1272 |
+
constexpr explicit(see below)
|
| 1273 |
+
tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&);
|
| 1274 |
template<class Alloc, class... UTypes>
|
| 1275 |
+
constexpr explicit(see below)
|
| 1276 |
+
tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&);
|
| 1277 |
template<class Alloc, class U1, class U2>
|
| 1278 |
+
constexpr explicit(see below)
|
| 1279 |
+
tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
|
| 1280 |
template<class Alloc, class U1, class U2>
|
| 1281 |
+
constexpr explicit(see below)
|
| 1282 |
+
tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
|
| 1283 |
```
|
| 1284 |
|
| 1285 |
+
*Preconditions:* `Alloc` meets the *Cpp17Allocator* requirements
|
| 1286 |
+
([[cpp17.allocator]]).
|
| 1287 |
|
| 1288 |
*Effects:* Equivalent to the preceding constructors except that each
|
| 1289 |
element is constructed with uses-allocator
|
| 1290 |
+
construction [[allocator.uses.construction]].
|
| 1291 |
|
| 1292 |
#### Assignment <a id="tuple.assign">[[tuple.assign]]</a>
|
| 1293 |
|
| 1294 |
For each `tuple` assignment operator, an exception is thrown only if the
|
| 1295 |
assignment of one of the types in `Types` throws an exception. In the
|
|
|
|
| 1297 |
`sizeof...(Types)`) in order, `Tᵢ` be the iᵗʰ type in `Types`, and `Uᵢ`
|
| 1298 |
be the iᵗʰ type in a template parameter pack named `UTypes`, where
|
| 1299 |
indexing is zero-based.
|
| 1300 |
|
| 1301 |
``` cpp
|
| 1302 |
+
constexpr tuple& operator=(const tuple& u);
|
| 1303 |
```
|
| 1304 |
|
| 1305 |
*Effects:* Assigns each element of `u` to the corresponding element of
|
| 1306 |
`*this`.
|
| 1307 |
|
| 1308 |
+
*Remarks:* This operator is defined as deleted unless
|
| 1309 |
`is_copy_assignable_v<``Tᵢ``>` is `true` for all i.
|
| 1310 |
|
| 1311 |
*Returns:* `*this`.
|
| 1312 |
|
| 1313 |
``` cpp
|
| 1314 |
+
constexpr tuple& operator=(tuple&& u) noexcept(see below);
|
| 1315 |
```
|
| 1316 |
|
| 1317 |
+
*Constraints:* `is_move_assignable_v<``Tᵢ``>` is `true` for all i.
|
| 1318 |
+
|
| 1319 |
*Effects:* For all i, assigns `std::forward<``Tᵢ``>(get<`i`>(u))` to
|
| 1320 |
`get<`i`>(*this)`.
|
| 1321 |
|
|
|
|
|
|
|
|
|
|
| 1322 |
*Remarks:* The expression inside `noexcept` is equivalent to the logical
|
| 1323 |
<span class="smallcaps">and</span> of the following expressions:
|
| 1324 |
|
| 1325 |
``` cpp
|
| 1326 |
is_nothrow_move_assignable_v<Tᵢ>
|
|
|
|
| 1329 |
where Tᵢ is the iᵗʰ type in `Types`.
|
| 1330 |
|
| 1331 |
*Returns:* `*this`.
|
| 1332 |
|
| 1333 |
``` cpp
|
| 1334 |
+
template<class... UTypes> constexpr tuple& operator=(const tuple<UTypes...>& u);
|
| 1335 |
```
|
| 1336 |
|
| 1337 |
+
*Constraints:*
|
| 1338 |
+
|
| 1339 |
+
- `sizeof...(Types)` equals `sizeof...(UTypes)` and
|
| 1340 |
+
- `is_assignable_v<``Tᵢ``&, const ``Uᵢ``&>` is `true` for all i.
|
| 1341 |
+
|
| 1342 |
*Effects:* Assigns each element of `u` to the corresponding element of
|
| 1343 |
`*this`.
|
| 1344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1345 |
*Returns:* `*this`.
|
| 1346 |
|
| 1347 |
``` cpp
|
| 1348 |
+
template<class... UTypes> constexpr tuple& operator=(tuple<UTypes...>&& u);
|
| 1349 |
```
|
| 1350 |
|
| 1351 |
+
*Constraints:*
|
| 1352 |
+
|
| 1353 |
+
- `sizeof...(Types)` equals `sizeof...(UTypes)` and
|
| 1354 |
+
- `is_assignable_v<``Tᵢ``&, ``Uᵢ``>` is `true` for all i.
|
| 1355 |
+
|
| 1356 |
*Effects:* For all i, assigns `std::forward<``Uᵢ``>(get<`i`>(u))` to
|
| 1357 |
`get<`i`>(*this)`.
|
| 1358 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1359 |
*Returns:* `*this`.
|
| 1360 |
|
| 1361 |
``` cpp
|
| 1362 |
+
template<class U1, class U2> constexpr tuple& operator=(const pair<U1, U2>& u);
|
| 1363 |
```
|
| 1364 |
|
| 1365 |
+
*Constraints:*
|
| 1366 |
+
|
| 1367 |
+
- `sizeof...(Types)` is 2 and
|
| 1368 |
+
- `is_assignable_v<``T₀``&, const U1&>` is `true`, and
|
| 1369 |
+
- `is_assignable_v<``T₁``&, const U2&>` is `true`.
|
| 1370 |
+
|
| 1371 |
*Effects:* Assigns `u.first` to the first element of `*this` and
|
| 1372 |
`u.second` to the second element of `*this`.
|
| 1373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1374 |
*Returns:* `*this`.
|
| 1375 |
|
| 1376 |
``` cpp
|
| 1377 |
+
template<class U1, class U2> constexpr tuple& operator=(pair<U1, U2>&& u);
|
| 1378 |
```
|
| 1379 |
|
| 1380 |
+
*Constraints:*
|
| 1381 |
+
|
| 1382 |
+
- `sizeof...(Types)` is 2 and
|
| 1383 |
+
- `is_assignable_v<``T₀``&, U1>` is `true`, and
|
| 1384 |
+
- `is_assignable_v<``T₁``&, U2>` is `true`.
|
| 1385 |
+
|
| 1386 |
*Effects:* Assigns `std::forward<U1>(u.first)` to the first element of
|
| 1387 |
`*this` and
|
| 1388 |
`std::forward<U2>(u.second)` to the second element of `*this`.
|
| 1389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1390 |
*Returns:* `*this`.
|
| 1391 |
|
| 1392 |
#### `swap` <a id="tuple.swap">[[tuple.swap]]</a>
|
| 1393 |
|
| 1394 |
``` cpp
|
| 1395 |
+
constexpr void swap(tuple& rhs) noexcept(see below);
|
| 1396 |
```
|
| 1397 |
|
| 1398 |
+
*Preconditions:* Each element in `*this` is swappable
|
| 1399 |
+
with [[swappable.requirements]] the corresponding element in `rhs`.
|
| 1400 |
|
| 1401 |
*Effects:* Calls `swap` for each element in `*this` and its
|
| 1402 |
corresponding element in `rhs`.
|
| 1403 |
|
| 1404 |
*Remarks:* The expression inside `noexcept` is equivalent to the logical
|
|
|
|
| 1411 |
where Tᵢ is the iᵗʰ type in `Types`.
|
| 1412 |
|
| 1413 |
*Throws:* Nothing unless one of the element-wise `swap` calls throws an
|
| 1414 |
exception.
|
| 1415 |
|
| 1416 |
+
### Tuple creation functions <a id="tuple.creation">[[tuple.creation]]</a>
|
| 1417 |
|
| 1418 |
+
In the function descriptions that follow, the members of a template
|
| 1419 |
+
parameter pack `XTypes` are denoted by `X`ᵢ for i in \[`0`,
|
| 1420 |
`sizeof...(`*X*`Types)`) in order, where indexing is zero-based.
|
| 1421 |
|
| 1422 |
``` cpp
|
| 1423 |
template<class... TTypes>
|
| 1424 |
+
constexpr tuple<unwrap_ref_decay_t<TTypes>...> make_tuple(TTypes&&... t);
|
| 1425 |
```
|
| 1426 |
|
| 1427 |
+
*Returns:*
|
| 1428 |
+
`tuple<unwrap_ref_decay_t<TTypes>...>(std::forward<TTypes>(t)...)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1429 |
|
| 1430 |
[*Example 1*:
|
| 1431 |
|
| 1432 |
``` cpp
|
| 1433 |
int i; float j;
|
|
|
|
| 1443 |
constexpr tuple<TTypes&&...> forward_as_tuple(TTypes&&... t) noexcept;
|
| 1444 |
```
|
| 1445 |
|
| 1446 |
*Effects:* Constructs a tuple of references to the arguments in `t`
|
| 1447 |
suitable for forwarding as arguments to a function. Because the result
|
| 1448 |
+
may contain references to temporary objects, a program shall ensure that
|
| 1449 |
+
the return value of this function does not outlive any of its arguments
|
| 1450 |
+
(e.g., the program should typically not store the result in a named
|
| 1451 |
+
variable).
|
| 1452 |
|
| 1453 |
*Returns:* `tuple<TTypes&&...>(std::forward<TTypes>(t)...)`.
|
| 1454 |
|
| 1455 |
``` cpp
|
| 1456 |
template<class... TTypes>
|
|
|
|
| 1481 |
|
| 1482 |
In the following paragraphs, let `Tᵢ` be the iᵗʰ type in `Tuples`, `Uᵢ`
|
| 1483 |
be `remove_reference_t<T`ᵢ`>`, and `tpᵢ` be the iᵗʰ parameter in the
|
| 1484 |
function parameter pack `tpls`, where all indexing is zero-based.
|
| 1485 |
|
| 1486 |
+
*Preconditions:* For all i, `Uᵢ` is the type cvᵢ `tuple<``Argsᵢ``...>`,
|
| 1487 |
where cvᵢ is the (possibly empty) iᵗʰ *cv-qualifier-seq* and `Argsᵢ` is
|
| 1488 |
+
the template parameter pack representing the element types in `Uᵢ`. Let
|
| 1489 |
+
`A_ik` be the kᵗʰ type in `Argsᵢ`. For all `A_ik` the following
|
| 1490 |
+
requirements are met:
|
| 1491 |
|
| 1492 |
- If `Tᵢ` is deduced as an lvalue reference type, then
|
| 1493 |
`is_constructible_v<``A_ik``, `cvᵢ `A_ik``&> == true`, otherwise
|
| 1494 |
- `is_constructible_v<``A_ik``, `cvᵢ `A_ik``&&> == true`.
|
| 1495 |
|
| 1496 |
+
*Remarks:* The types in `CTypes` are equal to the ordered sequence of
|
| 1497 |
+
the extended types `Args₀``..., ``Args₁``..., `…`, ``Args_n-1``...`,
|
| 1498 |
where n is equal to `sizeof...(Tuples)`. Let `eᵢ``...` be the iᵗʰ
|
| 1499 |
ordered sequence of tuple elements of the resulting `tuple` object
|
| 1500 |
corresponding to the type sequence `Argsᵢ`.
|
| 1501 |
|
| 1502 |
*Returns:* A `tuple` object constructed by initializing the kᵢᵗʰ type
|
|
|
|
| 1507 |
```
|
| 1508 |
|
| 1509 |
for each valid kᵢ and each group `eᵢ` in order.
|
| 1510 |
|
| 1511 |
[*Note 1*: An implementation may support additional types in the
|
| 1512 |
+
template parameter pack `Tuples` that support the `tuple`-like protocol,
|
| 1513 |
+
such as `pair` and `array`. — *end note*]
|
| 1514 |
|
| 1515 |
+
### Calling a function with a `tuple` of arguments <a id="tuple.apply">[[tuple.apply]]</a>
|
| 1516 |
|
| 1517 |
``` cpp
|
| 1518 |
template<class F, class Tuple>
|
| 1519 |
constexpr decltype(auto) apply(F&& f, Tuple&& t);
|
| 1520 |
```
|
| 1521 |
|
| 1522 |
*Effects:* Given the exposition-only function:
|
| 1523 |
|
| 1524 |
``` cpp
|
| 1525 |
template<class F, class Tuple, size_t... I>
|
| 1526 |
+
constexpr decltype(auto) apply-impl(F&& f, Tuple&& t, index_sequence<I...>) {
|
| 1527 |
+
// exposition only
|
| 1528 |
+
return INVOKE(std::forward<F>(f), std::get<I>(std::forward<Tuple>(t))...); // see [func.require]
|
| 1529 |
}
|
| 1530 |
```
|
| 1531 |
|
| 1532 |
Equivalent to:
|
| 1533 |
|
| 1534 |
``` cpp
|
| 1535 |
+
return apply-impl(std::forward<F>(f), std::forward<Tuple>(t),
|
| 1536 |
+
make_index_sequence<tuple_size_v<remove_reference_t<Tuple>>>{});
|
| 1537 |
```
|
| 1538 |
|
| 1539 |
``` cpp
|
| 1540 |
template<class T, class Tuple>
|
| 1541 |
constexpr T make_from_tuple(Tuple&& t);
|
|
|
|
| 1543 |
|
| 1544 |
*Effects:* Given the exposition-only function:
|
| 1545 |
|
| 1546 |
``` cpp
|
| 1547 |
template<class T, class Tuple, size_t... I>
|
| 1548 |
+
constexpr T make-from-tuple-impl(Tuple&& t, index_sequence<I...>) { // exposition only
|
| 1549 |
return T(get<I>(std::forward<Tuple>(t))...);
|
| 1550 |
}
|
| 1551 |
```
|
| 1552 |
|
| 1553 |
Equivalent to:
|
| 1554 |
|
| 1555 |
``` cpp
|
| 1556 |
+
return make-from-tuple-impl<T>(
|
| 1557 |
+
forward<Tuple>(t),
|
| 1558 |
+
make_index_sequence<tuple_size_v<remove_reference_t<Tuple>>>{});
|
| 1559 |
```
|
| 1560 |
|
| 1561 |
[*Note 1*: The type of `T` must be supplied as an explicit template
|
| 1562 |
parameter, as it cannot be deduced from the argument
|
| 1563 |
list. — *end note*]
|
| 1564 |
|
| 1565 |
+
### Tuple helper classes <a id="tuple.helper">[[tuple.helper]]</a>
|
| 1566 |
|
| 1567 |
``` cpp
|
| 1568 |
template<class T> struct tuple_size;
|
| 1569 |
```
|
| 1570 |
|
| 1571 |
+
All specializations of `tuple_size` meet the *Cpp17UnaryTypeTrait*
|
| 1572 |
+
requirements [[meta.rqmts]] with a base characteristic of
|
| 1573 |
+
`integral_constant<size_t, N>` for some `N`.
|
| 1574 |
|
| 1575 |
``` cpp
|
| 1576 |
template<class... Types>
|
| 1577 |
+
struct tuple_size<tuple<Types...>> : public integral_constant<size_t, sizeof...(Types)> { };
|
| 1578 |
```
|
| 1579 |
|
| 1580 |
``` cpp
|
| 1581 |
template<size_t I, class... Types>
|
| 1582 |
+
struct tuple_element<I, tuple<Types...>> {
|
|
|
|
| 1583 |
using type = TI;
|
| 1584 |
};
|
| 1585 |
```
|
| 1586 |
|
| 1587 |
+
*Mandates:* `I` < `sizeof...(Types)`.
|
|
|
|
| 1588 |
|
| 1589 |
+
*Type:* `TI` is the type of the `I`ᵗʰ element of `Types`, where indexing
|
| 1590 |
is zero-based.
|
| 1591 |
|
| 1592 |
``` cpp
|
| 1593 |
+
template<class T> struct tuple_size<const T>;
|
|
|
|
|
|
|
| 1594 |
```
|
| 1595 |
|
| 1596 |
+
Let `TS` denote `tuple_size<T>` of the cv-unqualified type `T`. If the
|
| 1597 |
+
expression `TS::value` is well-formed when treated as an unevaluated
|
| 1598 |
+
operand, then each specialization of the template meets the
|
| 1599 |
+
*Cpp17UnaryTypeTrait* requirements [[meta.rqmts]] with a base
|
| 1600 |
characteristic of
|
| 1601 |
|
| 1602 |
``` cpp
|
| 1603 |
integral_constant<size_t, TS::value>
|
| 1604 |
```
|
| 1605 |
|
| 1606 |
+
Otherwise, it has no member `value`.
|
| 1607 |
|
| 1608 |
+
Access checking is performed as if in a context unrelated to `TS` and
|
| 1609 |
`T`. Only the validity of the immediate context of the expression is
|
| 1610 |
considered.
|
| 1611 |
|
| 1612 |
[*Note 1*: The compilation of the expression can result in side effects
|
| 1613 |
such as the instantiation of class template specializations and function
|
| 1614 |
template specializations, the generation of implicitly-defined
|
| 1615 |
functions, and so on. Such side effects are not in the “immediate
|
| 1616 |
context” and can result in the program being ill-formed. — *end note*]
|
| 1617 |
|
| 1618 |
In addition to being available via inclusion of the `<tuple>` header,
|
| 1619 |
+
the template is available when any of the headers `<array>`, `<ranges>`,
|
| 1620 |
or `<utility>` are included.
|
| 1621 |
|
| 1622 |
``` cpp
|
| 1623 |
+
template<size_t I, class T> struct tuple_element<I, const T>;
|
|
|
|
|
|
|
| 1624 |
```
|
| 1625 |
|
| 1626 |
+
Let `TE` denote `tuple_element_t<I, T>` of the cv-unqualified type `T`.
|
| 1627 |
+
Then each specialization of the template meets the
|
| 1628 |
+
*Cpp17TransformationTrait* requirements [[meta.rqmts]] with a member
|
| 1629 |
+
typedef `type` that names the type `add_const_t<TE>`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1630 |
|
| 1631 |
In addition to being available via inclusion of the `<tuple>` header,
|
| 1632 |
+
the template is available when any of the headers `<array>`, `<ranges>`,
|
| 1633 |
or `<utility>` are included.
|
| 1634 |
|
| 1635 |
+
### Element access <a id="tuple.elem">[[tuple.elem]]</a>
|
| 1636 |
|
| 1637 |
``` cpp
|
| 1638 |
template<size_t I, class... Types>
|
| 1639 |
constexpr tuple_element_t<I, tuple<Types...>>&
|
| 1640 |
get(tuple<Types...>& t) noexcept;
|
|
|
|
| 1646 |
get(const tuple<Types...>& t) noexcept; // Note B
|
| 1647 |
template<size_t I, class... Types>
|
| 1648 |
constexpr const tuple_element_t<I, tuple<Types...>>&& get(const tuple<Types...>&& t) noexcept;
|
| 1649 |
```
|
| 1650 |
|
| 1651 |
+
*Mandates:* `I` < `sizeof...(Types)`.
|
|
|
|
| 1652 |
|
| 1653 |
+
*Returns:* A reference to the `I`ᵗʰ element of `t`, where indexing is
|
| 1654 |
zero-based.
|
| 1655 |
|
| 1656 |
+
[*Note 1*: \[Note A\]If a type `T` in `Types` is some reference type
|
| 1657 |
+
`X&`, the return type is `X&`, not `X&&`. However, if the element type
|
| 1658 |
+
is a non-reference type `T`, the return type is `T&&`. — *end note*]
|
| 1659 |
|
| 1660 |
+
[*Note 2*: \[Note B\]Constness is shallow. If a type `T` in `Types` is
|
| 1661 |
+
some reference type `X&`, the return type is `X&`, not `const X&`.
|
| 1662 |
+
However, if the element type is a non-reference type `T`, the return
|
| 1663 |
+
type is `const T&`. This is consistent with how constness is defined to
|
| 1664 |
+
work for member variables of reference type. — *end note*]
|
| 1665 |
|
| 1666 |
``` cpp
|
| 1667 |
template<class T, class... Types>
|
| 1668 |
constexpr T& get(tuple<Types...>& t) noexcept;
|
| 1669 |
template<class T, class... Types>
|
|
|
|
| 1672 |
constexpr const T& get(const tuple<Types...>& t) noexcept;
|
| 1673 |
template<class T, class... Types>
|
| 1674 |
constexpr const T&& get(const tuple<Types...>&& t) noexcept;
|
| 1675 |
```
|
| 1676 |
|
| 1677 |
+
*Mandates:* The type `T` occurs exactly once in `Types`.
|
|
|
|
| 1678 |
|
| 1679 |
*Returns:* A reference to the element of `t` corresponding to the type
|
| 1680 |
+
`T` in `Types`.
|
| 1681 |
|
| 1682 |
[*Example 1*:
|
| 1683 |
|
| 1684 |
``` cpp
|
| 1685 |
const tuple<int, const int, double, double> t(1, 2, 3.4, 5.6);
|
| 1686 |
+
const int& i1 = get<int>(t); // OK, i1 has value 1
|
| 1687 |
+
const int& i2 = get<const int>(t); // OK, i2 has value 2
|
| 1688 |
+
const double& d = get<double>(t); // error: type double is not unique within t
|
| 1689 |
```
|
| 1690 |
|
| 1691 |
— *end example*]
|
| 1692 |
|
| 1693 |
[*Note 1*: The reason `get` is a non-member function is that if this
|
| 1694 |
functionality had been provided as a member function, code where the
|
| 1695 |
type depended on a template parameter would have required using the
|
| 1696 |
`template` keyword. — *end note*]
|
| 1697 |
|
| 1698 |
+
### Relational operators <a id="tuple.rel">[[tuple.rel]]</a>
|
| 1699 |
|
| 1700 |
``` cpp
|
| 1701 |
template<class... TTypes, class... UTypes>
|
| 1702 |
constexpr bool operator==(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
|
| 1703 |
```
|
| 1704 |
|
| 1705 |
+
*Mandates:* For all `i`, where 0 ≤ `i` < `sizeof...(TTypes)`,
|
| 1706 |
`get<i>(t) == get<i>(u)` is a valid expression returning a type that is
|
| 1707 |
+
convertible to `bool`. `sizeof...(TTypes)` equals `sizeof...(UTypes)`.
|
| 1708 |
|
| 1709 |
*Returns:* `true` if `get<i>(t) == get<i>(u)` for all `i`, otherwise
|
| 1710 |
`false`. For any two zero-length tuples `e` and `f`, `e == f` returns
|
| 1711 |
`true`.
|
| 1712 |
|
|
|
|
| 1714 |
zeroth index upwards. No comparisons or element accesses are performed
|
| 1715 |
after the first equality comparison that evaluates to `false`.
|
| 1716 |
|
| 1717 |
``` cpp
|
| 1718 |
template<class... TTypes, class... UTypes>
|
| 1719 |
+
constexpr common_comparison_category_t<synth-three-way-result<TTypes, UTypes>...>
|
| 1720 |
+
operator<=>(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
|
| 1721 |
```
|
| 1722 |
|
| 1723 |
+
*Effects:* Performs a lexicographical comparison between `t` and `u`.
|
| 1724 |
+
For any two zero-length tuples `t` and `u`, `t <=> u` returns
|
| 1725 |
+
`strong_ordering::equal`. Otherwise, equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1726 |
|
| 1727 |
``` cpp
|
| 1728 |
+
if (auto c = synth-three-way(get<0>(t), get<0>(u)); c != 0) return c;
|
| 1729 |
+
return $t_tail$ <=> $u_tail$;
|
| 1730 |
```
|
| 1731 |
|
| 1732 |
+
where `r_tail` for some tuple `r` is a tuple containing all but the
|
| 1733 |
+
first element of `r`.
|
| 1734 |
|
| 1735 |
+
[*Note 1*: The above definition does not require `tₜₐᵢₗ` (or `uₜₐᵢₗ`)
|
| 1736 |
+
to be constructed. It may not even be possible, as `t` and `u` are not
|
| 1737 |
+
required to be copy constructible. Also, all comparison functions are
|
| 1738 |
+
short circuited; they do not perform element accesses beyond what is
|
| 1739 |
+
required to determine the result of the comparison. — *end note*]
|
|
|
|
| 1740 |
|
| 1741 |
+
### Tuple traits <a id="tuple.traits">[[tuple.traits]]</a>
|
| 1742 |
|
| 1743 |
``` cpp
|
| 1744 |
template<class... Types, class Alloc>
|
| 1745 |
struct uses_allocator<tuple<Types...>, Alloc> : true_type { };
|
| 1746 |
```
|
| 1747 |
|
| 1748 |
+
*Preconditions:* `Alloc` meets the *Cpp17Allocator* requirements
|
| 1749 |
+
([[cpp17.allocator]]).
|
| 1750 |
|
| 1751 |
[*Note 1*: Specialization of this trait informs other library
|
| 1752 |
components that `tuple` can be constructed with an allocator, even
|
| 1753 |
though it does not have a nested `allocator_type`. — *end note*]
|
| 1754 |
|
| 1755 |
+
### Tuple specialized algorithms <a id="tuple.special">[[tuple.special]]</a>
|
| 1756 |
|
| 1757 |
``` cpp
|
| 1758 |
template<class... Types>
|
| 1759 |
+
constexpr void swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(see below);
|
| 1760 |
```
|
| 1761 |
|
| 1762 |
+
*Constraints:* `is_swappable_v<T>` is `true` for every type `T` in
|
| 1763 |
+
`Types`.
|
| 1764 |
+
|
| 1765 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 1766 |
|
| 1767 |
``` cpp
|
| 1768 |
noexcept(x.swap(y))
|
| 1769 |
```
|
| 1770 |
|
|
|
|
| 1772 |
|
| 1773 |
## Optional objects <a id="optional">[[optional]]</a>
|
| 1774 |
|
| 1775 |
### In general <a id="optional.general">[[optional.general]]</a>
|
| 1776 |
|
| 1777 |
+
Subclause [[optional]] describes class template `optional` that
|
| 1778 |
+
represents optional objects. An *optional object* is an object that
|
| 1779 |
+
contains the storage for another object and manages the lifetime of this
|
| 1780 |
+
contained object, if any. The contained object may be initialized after
|
| 1781 |
+
the optional object has been initialized, and may be destroyed before
|
| 1782 |
+
the optional object has been destroyed. The initialization state of the
|
| 1783 |
contained object is tracked by the optional object.
|
| 1784 |
|
| 1785 |
### Header `<optional>` synopsis <a id="optional.syn">[[optional.syn]]</a>
|
| 1786 |
|
| 1787 |
``` cpp
|
| 1788 |
+
#include <compare> // see [compare.syn]
|
| 1789 |
+
|
| 1790 |
namespace std {
|
| 1791 |
// [optional.optional], class template optional
|
| 1792 |
template<class T>
|
| 1793 |
class optional;
|
| 1794 |
|
|
|
|
| 1810 |
constexpr bool operator>(const optional<T>&, const optional<U>&);
|
| 1811 |
template<class T, class U>
|
| 1812 |
constexpr bool operator<=(const optional<T>&, const optional<U>&);
|
| 1813 |
template<class T, class U>
|
| 1814 |
constexpr bool operator>=(const optional<T>&, const optional<U>&);
|
| 1815 |
+
template<class T, three_way_comparable_with<T> U>
|
| 1816 |
+
constexpr compare_three_way_result_t<T,U>
|
| 1817 |
+
operator<=>(const optional<T>&, const optional<U>&);
|
| 1818 |
|
| 1819 |
// [optional.nullops], comparison with nullopt
|
| 1820 |
template<class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
|
| 1821 |
+
template<class T>
|
| 1822 |
+
constexpr strong_ordering operator<=>(const optional<T>&, nullopt_t) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1823 |
|
| 1824 |
+
// [optional.comp.with.t], comparison with T
|
| 1825 |
template<class T, class U> constexpr bool operator==(const optional<T>&, const U&);
|
| 1826 |
+
template<class T, class U> constexpr bool operator==(const T&, const optional<U>&);
|
| 1827 |
template<class T, class U> constexpr bool operator!=(const optional<T>&, const U&);
|
| 1828 |
+
template<class T, class U> constexpr bool operator!=(const T&, const optional<U>&);
|
| 1829 |
template<class T, class U> constexpr bool operator<(const optional<T>&, const U&);
|
| 1830 |
+
template<class T, class U> constexpr bool operator<(const T&, const optional<U>&);
|
|
|
|
|
|
|
| 1831 |
template<class T, class U> constexpr bool operator>(const optional<T>&, const U&);
|
| 1832 |
+
template<class T, class U> constexpr bool operator>(const T&, const optional<U>&);
|
| 1833 |
+
template<class T, class U> constexpr bool operator<=(const optional<T>&, const U&);
|
| 1834 |
+
template<class T, class U> constexpr bool operator<=(const T&, const optional<U>&);
|
| 1835 |
template<class T, class U> constexpr bool operator>=(const optional<T>&, const U&);
|
| 1836 |
+
template<class T, class U> constexpr bool operator>=(const T&, const optional<U>&);
|
| 1837 |
+
template<class T, three_way_comparable_with<T> U>
|
| 1838 |
+
constexpr compare_three_way_result_t<T,U>
|
| 1839 |
+
operator<=>(const optional<T>&, const U&);
|
| 1840 |
|
| 1841 |
// [optional.specalg], specialized algorithms
|
| 1842 |
template<class T>
|
| 1843 |
void swap(optional<T>&, optional<T>&) noexcept(see below);
|
| 1844 |
|
|
|
|
| 1853 |
template<class T> struct hash;
|
| 1854 |
template<class T> struct hash<optional<T>>;
|
| 1855 |
}
|
| 1856 |
```
|
| 1857 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1858 |
### Class template `optional` <a id="optional.optional">[[optional.optional]]</a>
|
| 1859 |
|
| 1860 |
``` cpp
|
| 1861 |
+
namespace std {
|
| 1862 |
template<class T>
|
| 1863 |
class optional {
|
| 1864 |
public:
|
| 1865 |
using value_type = T;
|
| 1866 |
|
|
|
|
| 1872 |
template<class... Args>
|
| 1873 |
constexpr explicit optional(in_place_t, Args&&...);
|
| 1874 |
template<class U, class... Args>
|
| 1875 |
constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
|
| 1876 |
template<class U = T>
|
| 1877 |
+
constexpr explicit(see below) optional(U&&);
|
| 1878 |
template<class U>
|
| 1879 |
+
explicit(see below) optional(const optional<U>&);
|
| 1880 |
template<class U>
|
| 1881 |
+
explicit(see below) optional(optional<U>&&);
|
| 1882 |
|
| 1883 |
// [optional.dtor], destructor
|
| 1884 |
~optional();
|
| 1885 |
|
| 1886 |
// [optional.assign], assignment
|
| 1887 |
optional& operator=(nullopt_t) noexcept;
|
| 1888 |
+
constexpr optional& operator=(const optional&);
|
| 1889 |
+
constexpr optional& operator=(optional&&) noexcept(see below);
|
| 1890 |
template<class U = T> optional& operator=(U&&);
|
| 1891 |
template<class U> optional& operator=(const optional<U>&);
|
| 1892 |
template<class U> optional& operator=(optional<U>&&);
|
| 1893 |
template<class... Args> T& emplace(Args&&...);
|
| 1894 |
template<class U, class... Args> T& emplace(initializer_list<U>, Args&&...);
|
|
|
|
| 1917 |
|
| 1918 |
private:
|
| 1919 |
T *val; // exposition only
|
| 1920 |
};
|
| 1921 |
|
| 1922 |
+
template<class T>
|
| 1923 |
+
optional(T) -> optional<T>;
|
| 1924 |
+
}
|
| 1925 |
```
|
| 1926 |
|
| 1927 |
Any instance of `optional<T>` at any given time either contains a value
|
| 1928 |
or does not contain a value. When an instance of `optional<T>` *contains
|
| 1929 |
a value*, it means that an object of type `T`, referred to as the
|
|
|
|
| 1937 |
returns `false`.
|
| 1938 |
|
| 1939 |
Member `val` is provided for exposition only. When an `optional<T>`
|
| 1940 |
object contains a value, `val` points to the contained value.
|
| 1941 |
|
| 1942 |
+
`T` shall be a type other than cv `in_place_t` or cv `nullopt_t` that
|
| 1943 |
+
meets the *Cpp17Destructible* requirements ([[cpp17.destructible]]).
|
| 1944 |
|
| 1945 |
#### Constructors <a id="optional.ctor">[[optional.ctor]]</a>
|
| 1946 |
|
| 1947 |
``` cpp
|
| 1948 |
constexpr optional() noexcept;
|
| 1949 |
constexpr optional(nullopt_t) noexcept;
|
| 1950 |
```
|
| 1951 |
|
| 1952 |
+
*Ensures:* `*this` does not contain a value.
|
| 1953 |
|
| 1954 |
*Remarks:* No contained value is initialized. For every object type `T`
|
| 1955 |
+
these constructors are constexpr constructors [[dcl.constexpr]].
|
| 1956 |
|
| 1957 |
``` cpp
|
| 1958 |
constexpr optional(const optional& rhs);
|
| 1959 |
```
|
| 1960 |
|
| 1961 |
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 1962 |
if direct-non-list-initializing an object of type `T` with the
|
| 1963 |
expression `*rhs`.
|
| 1964 |
|
| 1965 |
+
*Ensures:* `bool(rhs) == bool(*this)`.
|
| 1966 |
|
| 1967 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 1968 |
|
| 1969 |
+
*Remarks:* This constructor is defined as deleted unless
|
| 1970 |
`is_copy_constructible_v<T>` is `true`. If
|
| 1971 |
+
`is_trivially_copy_constructible_v<T>` is `true`, this constructor is
|
| 1972 |
+
trivial.
|
| 1973 |
|
| 1974 |
``` cpp
|
| 1975 |
constexpr optional(optional&& rhs) noexcept(see below);
|
| 1976 |
```
|
| 1977 |
|
| 1978 |
+
*Constraints:* `is_move_constructible_v<T>` is `true`.
|
| 1979 |
+
|
| 1980 |
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 1981 |
if direct-non-list-initializing an object of type `T` with the
|
| 1982 |
expression `std::move(*rhs)`. `bool(rhs)` is unchanged.
|
| 1983 |
|
| 1984 |
+
*Ensures:* `bool(rhs) == bool(*this)`.
|
| 1985 |
|
| 1986 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 1987 |
|
| 1988 |
*Remarks:* The expression inside `noexcept` is equivalent to
|
| 1989 |
+
`is_nothrow_move_constructible_v<T>`. If
|
| 1990 |
+
`is_trivially_move_constructible_v<T>` is `true`, this constructor is
|
| 1991 |
+
trivial.
|
|
|
|
| 1992 |
|
| 1993 |
``` cpp
|
| 1994 |
template<class... Args> constexpr explicit optional(in_place_t, Args&&... args);
|
| 1995 |
```
|
| 1996 |
|
| 1997 |
+
*Constraints:* `is_constructible_v<T, Args...>` is `true`.
|
| 1998 |
+
|
| 1999 |
*Effects:* Initializes the contained value as if
|
| 2000 |
direct-non-list-initializing an object of type `T` with the arguments
|
| 2001 |
`std::forward<Args>(args)...`.
|
| 2002 |
|
| 2003 |
+
*Ensures:* `*this` contains a value.
|
| 2004 |
|
| 2005 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2006 |
|
| 2007 |
*Remarks:* If `T`’s constructor selected for the initialization is a
|
| 2008 |
+
constexpr constructor, this constructor is a constexpr constructor.
|
|
|
|
|
|
|
| 2009 |
|
| 2010 |
``` cpp
|
| 2011 |
template<class U, class... Args>
|
| 2012 |
constexpr explicit optional(in_place_t, initializer_list<U> il, Args&&... args);
|
| 2013 |
```
|
| 2014 |
|
| 2015 |
+
*Constraints:* `is_constructible_v<T, initializer_list<U>&, Args...>` is
|
| 2016 |
+
`true`.
|
| 2017 |
+
|
| 2018 |
*Effects:* Initializes the contained value as if
|
| 2019 |
direct-non-list-initializing an object of type `T` with the arguments
|
| 2020 |
`il, std::forward<Args>(args)...`.
|
| 2021 |
|
| 2022 |
+
*Ensures:* `*this` contains a value.
|
| 2023 |
|
| 2024 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2025 |
|
| 2026 |
+
*Remarks:* If `T`’s constructor selected for the initialization is a
|
| 2027 |
+
constexpr constructor, this constructor is a constexpr constructor.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2028 |
|
| 2029 |
``` cpp
|
| 2030 |
+
template<class U = T> constexpr explicit(see below) optional(U&& v);
|
| 2031 |
```
|
| 2032 |
|
| 2033 |
+
*Constraints:* `is_constructible_v<T, U>` is `true`,
|
| 2034 |
+
`is_same_v<remove_cvref_t<U>, in_place_t>` is `false`, and
|
| 2035 |
+
`is_same_v<remove_cvref_t<U>, optional>` is `false`.
|
| 2036 |
+
|
| 2037 |
*Effects:* Initializes the contained value as if
|
| 2038 |
direct-non-list-initializing an object of type `T` with the expression
|
| 2039 |
`std::forward<U>(v)`.
|
| 2040 |
|
| 2041 |
+
*Ensures:* `*this` contains a value.
|
| 2042 |
|
| 2043 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2044 |
|
| 2045 |
*Remarks:* If `T`’s selected constructor is a constexpr constructor,
|
| 2046 |
+
this constructor is a constexpr constructor. The expression inside
|
| 2047 |
+
`explicit` is equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2048 |
|
| 2049 |
``` cpp
|
| 2050 |
+
!is_convertible_v<U, T>
|
| 2051 |
```
|
| 2052 |
|
| 2053 |
+
``` cpp
|
| 2054 |
+
template<class U> explicit(see below) optional(const optional<U>& rhs);
|
| 2055 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2056 |
|
| 2057 |
+
*Constraints:*
|
|
|
|
| 2058 |
|
| 2059 |
- `is_constructible_v<T, const U&>` is `true`,
|
| 2060 |
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 2061 |
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 2062 |
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
|
|
|
| 2064 |
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 2065 |
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 2066 |
- `is_convertible_v<const optional<U>&, T>` is `false`, and
|
| 2067 |
- `is_convertible_v<const optional<U>&&, T>` is `false`.
|
| 2068 |
|
| 2069 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 2070 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 2071 |
+
expression `*rhs`.
|
| 2072 |
+
|
| 2073 |
+
*Ensures:* `bool(rhs)` == `bool(*this)`.
|
| 2074 |
+
|
| 2075 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2076 |
+
|
| 2077 |
+
*Remarks:* The expression inside `explicit` is equivalent to:
|
| 2078 |
+
|
| 2079 |
+
``` cpp
|
| 2080 |
+
!is_convertible_v<const U&, T>
|
| 2081 |
+
```
|
| 2082 |
|
| 2083 |
``` cpp
|
| 2084 |
+
template<class U> explicit(see below) optional(optional<U>&& rhs);
|
| 2085 |
```
|
| 2086 |
|
| 2087 |
+
*Constraints:*
|
| 2088 |
+
|
| 2089 |
+
- `is_constructible_v<T, U>` is true,
|
| 2090 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 2091 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 2092 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 2093 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 2094 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 2095 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 2096 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`, and
|
| 2097 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`.
|
| 2098 |
+
|
| 2099 |
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 2100 |
if direct-non-list-initializing an object of type `T` with the
|
| 2101 |
expression `std::move(*rhs)`. `bool(rhs)` is unchanged.
|
| 2102 |
|
| 2103 |
+
*Ensures:* `bool(rhs)` == `bool(*this)`.
|
| 2104 |
|
| 2105 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2106 |
|
| 2107 |
+
*Remarks:* The expression inside `explicit` is equivalent to:
|
|
|
|
| 2108 |
|
| 2109 |
+
``` cpp
|
| 2110 |
+
!is_convertible_v<U, T>
|
| 2111 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2112 |
|
| 2113 |
#### Destructor <a id="optional.dtor">[[optional.dtor]]</a>
|
| 2114 |
|
| 2115 |
``` cpp
|
| 2116 |
~optional();
|
|
|
|
| 2121 |
|
| 2122 |
``` cpp
|
| 2123 |
val->T::~T()
|
| 2124 |
```
|
| 2125 |
|
| 2126 |
+
*Remarks:* If `is_trivially_destructible_v<T>` is `true`, then this
|
| 2127 |
+
destructor is trivial.
|
| 2128 |
|
| 2129 |
#### Assignment <a id="optional.assign">[[optional.assign]]</a>
|
| 2130 |
|
| 2131 |
``` cpp
|
| 2132 |
optional<T>& operator=(nullopt_t) noexcept;
|
| 2133 |
```
|
| 2134 |
|
| 2135 |
*Effects:* If `*this` contains a value, calls `val->T::T̃()` to destroy
|
| 2136 |
the contained value; otherwise no effect.
|
| 2137 |
|
| 2138 |
+
*Ensures:* `*this` does not contain a value.
|
| 2139 |
|
| 2140 |
+
*Returns:* `*this`.
|
| 2141 |
|
| 2142 |
``` cpp
|
| 2143 |
+
constexpr optional<T>& operator=(const optional& rhs);
|
| 2144 |
```
|
| 2145 |
|
| 2146 |
+
*Effects:* See [[optional.assign.copy]].
|
| 2147 |
|
| 2148 |
+
**Table: `optional::operator=(const optional&)` effects** <a id="optional.assign.copy">[optional.assign.copy]</a>
|
| 2149 |
|
| 2150 |
| | `*this` contains a value | `*this` does not contain a value |
|
| 2151 |
| ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
|
| 2152 |
| `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` |
|
| 2153 |
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 2154 |
|
| 2155 |
|
| 2156 |
+
*Ensures:* `bool(rhs) == bool(*this)`.
|
| 2157 |
|
| 2158 |
+
*Returns:* `*this`.
|
| 2159 |
|
| 2160 |
*Remarks:* If any exception is thrown, the result of the expression
|
| 2161 |
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 2162 |
call to `T`’s copy constructor, no effect. If an exception is thrown
|
| 2163 |
during the call to `T`’s copy assignment, the state of its contained
|
| 2164 |
value is as defined by the exception safety guarantee of `T`’s copy
|
| 2165 |
+
assignment. This operator is defined as deleted unless
|
| 2166 |
`is_copy_constructible_v<T>` is `true` and `is_copy_assignable_v<T>` is
|
| 2167 |
+
`true`. If `is_trivially_copy_constructible_v<T> &&`
|
| 2168 |
+
`is_trivially_copy_assignable_v<T> &&` `is_trivially_destructible_v<T>`
|
| 2169 |
+
is `true`, this assignment operator is trivial.
|
| 2170 |
|
| 2171 |
``` cpp
|
| 2172 |
+
constexpr optional& operator=(optional&& rhs) noexcept(see below);
|
| 2173 |
```
|
| 2174 |
|
| 2175 |
+
*Constraints:* `is_move_constructible_v<T>` is `true` and
|
| 2176 |
+
`is_move_assignable_v<T>` is `true`.
|
| 2177 |
|
| 2178 |
+
*Effects:* See [[optional.assign.move]]. The result of the expression
|
| 2179 |
+
`bool(rhs)` remains unchanged.
|
| 2180 |
+
|
| 2181 |
+
**Table: `optional::operator=(optional&&)` effects** <a id="optional.assign.move">[optional.assign.move]</a>
|
| 2182 |
|
| 2183 |
| | `*this` contains a value | `*this` does not contain a value |
|
| 2184 |
| ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 2185 |
| `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)` |
|
| 2186 |
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 2187 |
|
| 2188 |
|
| 2189 |
+
*Ensures:* `bool(rhs) == bool(*this)`.
|
| 2190 |
+
|
| 2191 |
*Returns:* `*this`.
|
| 2192 |
|
|
|
|
|
|
|
| 2193 |
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 2194 |
|
| 2195 |
``` cpp
|
| 2196 |
is_nothrow_move_assignable_v<T> && is_nothrow_move_constructible_v<T>
|
| 2197 |
```
|
|
|
|
| 2200 |
remains unchanged. If an exception is thrown during the call to `T`’s
|
| 2201 |
move constructor, the state of `*rhs.val` is determined by the exception
|
| 2202 |
safety guarantee of `T`’s move constructor. If an exception is thrown
|
| 2203 |
during the call to `T`’s move assignment, the state of `*val` and
|
| 2204 |
`*rhs.val` is determined by the exception safety guarantee of `T`’s move
|
| 2205 |
+
assignment. If `is_trivially_move_constructible_v<T> &&`
|
| 2206 |
+
`is_trivially_move_assignable_v<T> &&` `is_trivially_destructible_v<T>`
|
| 2207 |
+
is `true`, this assignment operator is trivial.
|
| 2208 |
|
| 2209 |
``` cpp
|
| 2210 |
template<class U = T> optional<T>& operator=(U&& v);
|
| 2211 |
```
|
| 2212 |
|
| 2213 |
+
*Constraints:* `is_same_v<remove_cvref_t<U>, optional>` is `false`,
|
| 2214 |
+
`conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>>` is `false`,
|
| 2215 |
+
`is_constructible_v<T, U>` is `true`, and `is_assignable_v<T&, U>` is
|
| 2216 |
+
`true`.
|
| 2217 |
+
|
| 2218 |
*Effects:* If `*this` contains a value, assigns `std::forward<U>(v)` to
|
| 2219 |
the contained value; otherwise initializes the contained value as if
|
| 2220 |
direct-non-list-initializing object of type `T` with
|
| 2221 |
`std::forward<U>(v)`.
|
| 2222 |
|
| 2223 |
+
*Ensures:* `*this` contains a value.
|
| 2224 |
|
| 2225 |
+
*Returns:* `*this`.
|
| 2226 |
|
| 2227 |
*Remarks:* If any exception is thrown, the result of the expression
|
| 2228 |
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 2229 |
call to `T`’s constructor, the state of `v` is determined by the
|
| 2230 |
exception safety guarantee of `T`’s constructor. If an exception is
|
| 2231 |
thrown during the call to `T`’s assignment, the state of `*val` and `v`
|
| 2232 |
is determined by the exception safety guarantee of `T`’s assignment.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2233 |
|
| 2234 |
``` cpp
|
| 2235 |
template<class U> optional<T>& operator=(const optional<U>& rhs);
|
| 2236 |
```
|
| 2237 |
|
| 2238 |
+
*Constraints:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2239 |
|
| 2240 |
- `is_constructible_v<T, const U&>` is `true`,
|
| 2241 |
- `is_assignable_v<T&, const U&>` is `true`,
|
| 2242 |
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 2243 |
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
|
|
|
| 2250 |
- `is_assignable_v<T&, optional<U>&>` is `false`,
|
| 2251 |
- `is_assignable_v<T&, optional<U>&&>` is `false`,
|
| 2252 |
- `is_assignable_v<T&, const optional<U>&>` is `false`, and
|
| 2253 |
- `is_assignable_v<T&, const optional<U>&&>` is `false`.
|
| 2254 |
|
| 2255 |
+
*Effects:* See [[optional.assign.copy.templ]].
|
| 2256 |
+
|
| 2257 |
+
**Table: `optional::operator=(const optional<U>&)` effects** <a id="optional.assign.copy.templ">[optional.assign.copy.templ]</a>
|
| 2258 |
+
|
| 2259 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 2260 |
+
| ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
|
| 2261 |
+
| `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` |
|
| 2262 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 2263 |
+
|
| 2264 |
+
|
| 2265 |
+
*Ensures:* `bool(rhs) == bool(*this)`.
|
| 2266 |
+
|
| 2267 |
+
*Returns:* `*this`.
|
| 2268 |
+
|
| 2269 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 2270 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 2271 |
+
call to `T`’s constructor, the state of `*rhs.val` is determined by the
|
| 2272 |
+
exception safety guarantee of `T`’s constructor. If an exception is
|
| 2273 |
+
thrown during the call to `T`’s assignment, the state of `*val` and
|
| 2274 |
+
`*rhs.val` is determined by the exception safety guarantee of `T`’s
|
| 2275 |
+
assignment.
|
| 2276 |
+
|
| 2277 |
``` cpp
|
| 2278 |
template<class U> optional<T>& operator=(optional<U>&& rhs);
|
| 2279 |
```
|
| 2280 |
|
| 2281 |
+
*Constraints:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2282 |
|
| 2283 |
- `is_constructible_v<T, U>` is `true`,
|
| 2284 |
- `is_assignable_v<T&, U>` is `true`,
|
| 2285 |
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 2286 |
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
|
|
|
| 2293 |
- `is_assignable_v<T&, optional<U>&>` is `false`,
|
| 2294 |
- `is_assignable_v<T&, optional<U>&&>` is `false`,
|
| 2295 |
- `is_assignable_v<T&, const optional<U>&>` is `false`, and
|
| 2296 |
- `is_assignable_v<T&, const optional<U>&&>` is `false`.
|
| 2297 |
|
| 2298 |
+
*Effects:* See [[optional.assign.move.templ]]. The result of the
|
| 2299 |
+
expression `bool(rhs)` remains unchanged.
|
| 2300 |
+
|
| 2301 |
+
**Table: `optional::operator=(optional<U>&&)` effects** <a id="optional.assign.move.templ">[optional.assign.move.templ]</a>
|
| 2302 |
+
|
| 2303 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 2304 |
+
| ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 2305 |
+
| `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)` |
|
| 2306 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 2307 |
+
|
| 2308 |
+
|
| 2309 |
+
*Ensures:* `bool(rhs) == bool(*this)`.
|
| 2310 |
+
|
| 2311 |
+
*Returns:* `*this`.
|
| 2312 |
+
|
| 2313 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 2314 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 2315 |
+
call to `T`’s constructor, the state of `*rhs.val` is determined by the
|
| 2316 |
+
exception safety guarantee of `T`’s constructor. If an exception is
|
| 2317 |
+
thrown during the call to `T`’s assignment, the state of `*val` and
|
| 2318 |
+
`*rhs.val` is determined by the exception safety guarantee of `T`’s
|
| 2319 |
+
assignment.
|
| 2320 |
+
|
| 2321 |
``` cpp
|
| 2322 |
template<class... Args> T& emplace(Args&&... args);
|
| 2323 |
```
|
| 2324 |
|
| 2325 |
+
*Mandates:* `is_constructible_v<T, Args...>` is `true`.
|
| 2326 |
|
| 2327 |
*Effects:* Calls `*this = nullopt`. Then initializes the contained value
|
| 2328 |
as if direct-non-list-initializing an object of type `T` with the
|
| 2329 |
arguments `std::forward<Args>(args)...`.
|
| 2330 |
|
| 2331 |
+
*Ensures:* `*this` contains a value.
|
| 2332 |
|
| 2333 |
*Returns:* A reference to the new contained value.
|
| 2334 |
|
| 2335 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2336 |
|
|
|
|
| 2340 |
|
| 2341 |
``` cpp
|
| 2342 |
template<class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
|
| 2343 |
```
|
| 2344 |
|
| 2345 |
+
*Constraints:* `is_constructible_v<T, initializer_list<U>&, Args...>` is
|
| 2346 |
+
`true`.
|
| 2347 |
+
|
| 2348 |
*Effects:* Calls `*this = nullopt`. Then initializes the contained value
|
| 2349 |
as if direct-non-list-initializing an object of type `T` with the
|
| 2350 |
arguments `il, std::forward<Args>(args)...`.
|
| 2351 |
|
| 2352 |
+
*Ensures:* `*this` contains a value.
|
| 2353 |
|
| 2354 |
*Returns:* A reference to the new contained value.
|
| 2355 |
|
| 2356 |
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 2357 |
|
| 2358 |
*Remarks:* If an exception is thrown during the call to `T`’s
|
| 2359 |
constructor, `*this` does not contain a value, and the previous `*val`
|
| 2360 |
+
(if any) has been destroyed.
|
|
|
|
|
|
|
| 2361 |
|
| 2362 |
#### Swap <a id="optional.swap">[[optional.swap]]</a>
|
| 2363 |
|
| 2364 |
``` cpp
|
| 2365 |
void swap(optional& rhs) noexcept(see below);
|
| 2366 |
```
|
| 2367 |
|
| 2368 |
+
*Mandates:* `is_move_constructible_v<T>` is `true`.
|
|
|
|
| 2369 |
|
| 2370 |
+
*Preconditions:* Lvalues of type `T` are swappable.
|
| 2371 |
|
| 2372 |
+
*Effects:* See [[optional.swap]].
|
| 2373 |
+
|
| 2374 |
+
**Table: `optional::swap(optional&)` effects** <a id="optional.swap">[optional.swap]</a>
|
| 2375 |
|
| 2376 |
| | `*this` contains a value | `*this` does not contain a value |
|
| 2377 |
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
| 2378 |
| `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 |
|
| 2379 |
| `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 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
*Throws:* Any exceptions thrown by the operations in the relevant part
|
| 2383 |
+
of [[optional.swap]].
|
| 2384 |
|
| 2385 |
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 2386 |
|
| 2387 |
``` cpp
|
| 2388 |
is_nothrow_move_constructible_v<T> && is_nothrow_swappable_v<T>
|
|
|
|
| 2401 |
``` cpp
|
| 2402 |
constexpr const T* operator->() const;
|
| 2403 |
constexpr T* operator->();
|
| 2404 |
```
|
| 2405 |
|
| 2406 |
+
*Preconditions:* `*this` contains a value.
|
| 2407 |
|
| 2408 |
*Returns:* `val`.
|
| 2409 |
|
| 2410 |
*Throws:* Nothing.
|
| 2411 |
|
| 2412 |
+
*Remarks:* These functions are constexpr functions.
|
| 2413 |
|
| 2414 |
``` cpp
|
| 2415 |
constexpr const T& operator*() const&;
|
| 2416 |
constexpr T& operator*() &;
|
| 2417 |
```
|
| 2418 |
|
| 2419 |
+
*Preconditions:* `*this` contains a value.
|
| 2420 |
|
| 2421 |
*Returns:* `*val`.
|
| 2422 |
|
| 2423 |
*Throws:* Nothing.
|
| 2424 |
|
| 2425 |
+
*Remarks:* These functions are constexpr functions.
|
| 2426 |
|
| 2427 |
``` cpp
|
| 2428 |
constexpr T&& operator*() &&;
|
| 2429 |
constexpr const T&& operator*() const&&;
|
| 2430 |
```
|
| 2431 |
|
| 2432 |
+
*Preconditions:* `*this` contains a value.
|
| 2433 |
|
| 2434 |
*Effects:* Equivalent to: `return std::move(*val);`
|
| 2435 |
|
| 2436 |
``` cpp
|
| 2437 |
constexpr explicit operator bool() const noexcept;
|
| 2438 |
```
|
| 2439 |
|
| 2440 |
*Returns:* `true` if and only if `*this` contains a value.
|
| 2441 |
|
| 2442 |
+
*Remarks:* This function is a constexpr function.
|
| 2443 |
|
| 2444 |
``` cpp
|
| 2445 |
constexpr bool has_value() const noexcept;
|
| 2446 |
```
|
| 2447 |
|
| 2448 |
*Returns:* `true` if and only if `*this` contains a value.
|
| 2449 |
|
| 2450 |
+
*Remarks:* This function is a constexpr function.
|
| 2451 |
|
| 2452 |
``` cpp
|
| 2453 |
constexpr const T& value() const&;
|
| 2454 |
constexpr T& value() &;
|
| 2455 |
```
|
|
|
|
| 2473 |
|
| 2474 |
``` cpp
|
| 2475 |
template<class U> constexpr T value_or(U&& v) const&;
|
| 2476 |
```
|
| 2477 |
|
| 2478 |
+
*Mandates:* `is_copy_constructible_v<T> && is_convertible_v<U&&, T>` is
|
| 2479 |
+
`true`.
|
| 2480 |
+
|
| 2481 |
*Effects:* Equivalent to:
|
| 2482 |
|
| 2483 |
``` cpp
|
| 2484 |
return bool(*this) ? **this : static_cast<T>(std::forward<U>(v));
|
| 2485 |
```
|
| 2486 |
|
|
|
|
|
|
|
|
|
|
| 2487 |
``` cpp
|
| 2488 |
template<class U> constexpr T value_or(U&& v) &&;
|
| 2489 |
```
|
| 2490 |
|
| 2491 |
+
*Mandates:* `is_move_constructible_v<T> && is_convertible_v<U&&, T>` is
|
| 2492 |
+
`true`.
|
| 2493 |
+
|
| 2494 |
*Effects:* Equivalent to:
|
| 2495 |
|
| 2496 |
``` cpp
|
| 2497 |
return bool(*this) ? std::move(**this) : static_cast<T>(std::forward<U>(v));
|
| 2498 |
```
|
| 2499 |
|
|
|
|
|
|
|
|
|
|
| 2500 |
#### Modifiers <a id="optional.mod">[[optional.mod]]</a>
|
| 2501 |
|
| 2502 |
``` cpp
|
| 2503 |
void reset() noexcept;
|
| 2504 |
```
|
| 2505 |
|
| 2506 |
*Effects:* If `*this` contains a value, calls `val->T::T̃()` to destroy
|
| 2507 |
the contained value; otherwise no effect.
|
| 2508 |
|
| 2509 |
+
*Ensures:* `*this` does not contain a value.
|
| 2510 |
|
| 2511 |
### No-value state indicator <a id="optional.nullopt">[[optional.nullopt]]</a>
|
| 2512 |
|
| 2513 |
``` cpp
|
| 2514 |
struct nullopt_t{see below};
|
| 2515 |
inline constexpr nullopt_t nullopt(unspecified);
|
| 2516 |
```
|
| 2517 |
|
| 2518 |
+
The struct `nullopt_t` is an empty class type used as a unique type to
|
| 2519 |
+
indicate the state of not containing a value for `optional` objects. In
|
| 2520 |
+
particular, `optional<T>` has a constructor with `nullopt_t` as a single
|
| 2521 |
+
argument; this indicates that an optional object not containing a value
|
| 2522 |
+
shall be constructed.
|
| 2523 |
|
| 2524 |
Type `nullopt_t` shall not have a default constructor or an
|
| 2525 |
initializer-list constructor, and shall not be an aggregate.
|
| 2526 |
|
| 2527 |
### Class `bad_optional_access` <a id="optional.bad.access">[[optional.bad.access]]</a>
|
| 2528 |
|
| 2529 |
``` cpp
|
| 2530 |
class bad_optional_access : public exception {
|
| 2531 |
public:
|
| 2532 |
+
// see [exception] for the specification of the special member functions
|
| 2533 |
+
const char* what() const noexcept override;
|
| 2534 |
};
|
| 2535 |
```
|
| 2536 |
|
| 2537 |
The class `bad_optional_access` defines the type of objects thrown as
|
| 2538 |
exceptions to report the situation where an attempt is made to access
|
| 2539 |
the value of an optional object that does not contain a value.
|
| 2540 |
|
| 2541 |
``` cpp
|
| 2542 |
+
const char* what() const noexcept override;
|
| 2543 |
```
|
| 2544 |
|
| 2545 |
+
*Returns:* An *implementation-defined* NTBS.
|
|
|
|
|
|
|
| 2546 |
|
| 2547 |
### Relational operators <a id="optional.relops">[[optional.relops]]</a>
|
| 2548 |
|
| 2549 |
``` cpp
|
| 2550 |
template<class T, class U> constexpr bool operator==(const optional<T>& x, const optional<U>& y);
|
| 2551 |
```
|
| 2552 |
|
| 2553 |
+
*Mandates:* The expression `*x == *y` is well-formed and its result is
|
| 2554 |
+
convertible to `bool`.
|
| 2555 |
|
| 2556 |
+
[*Note 1*: `T` need not be *Cpp17EqualityComparable*. — *end note*]
|
| 2557 |
|
| 2558 |
*Returns:* If `bool(x) != bool(y)`, `false`; otherwise if
|
| 2559 |
`bool(x) == false`, `true`; otherwise `*x == *y`.
|
| 2560 |
|
| 2561 |
*Remarks:* Specializations of this function template for which
|
| 2562 |
+
`*x == *y` is a core constant expression are constexpr functions.
|
| 2563 |
|
| 2564 |
``` cpp
|
| 2565 |
template<class T, class U> constexpr bool operator!=(const optional<T>& x, const optional<U>& y);
|
| 2566 |
```
|
| 2567 |
|
| 2568 |
+
*Mandates:* The expression `*x != *y` is well-formed and its result is
|
| 2569 |
+
convertible to `bool`.
|
| 2570 |
|
| 2571 |
*Returns:* If `bool(x) != bool(y)`, `true`; otherwise, if
|
| 2572 |
`bool(x) == false`, `false`; otherwise `*x != *y`.
|
| 2573 |
|
| 2574 |
*Remarks:* Specializations of this function template for which
|
| 2575 |
+
`*x != *y` is a core constant expression are constexpr functions.
|
| 2576 |
|
| 2577 |
``` cpp
|
| 2578 |
template<class T, class U> constexpr bool operator<(const optional<T>& x, const optional<U>& y);
|
| 2579 |
```
|
| 2580 |
|
| 2581 |
+
*Mandates:* `*x < *y` is well-formed and its result is convertible to
|
| 2582 |
+
`bool`.
|
| 2583 |
|
| 2584 |
*Returns:* If `!y`, `false`; otherwise, if `!x`, `true`; otherwise
|
| 2585 |
`*x < *y`.
|
| 2586 |
|
| 2587 |
*Remarks:* Specializations of this function template for which `*x < *y`
|
| 2588 |
+
is a core constant expression are constexpr functions.
|
| 2589 |
|
| 2590 |
``` cpp
|
| 2591 |
template<class T, class U> constexpr bool operator>(const optional<T>& x, const optional<U>& y);
|
| 2592 |
```
|
| 2593 |
|
| 2594 |
+
*Mandates:* The expression `*x > *y` is well-formed and its result is
|
| 2595 |
+
convertible to `bool`.
|
| 2596 |
|
| 2597 |
*Returns:* If `!x`, `false`; otherwise, if `!y`, `true`; otherwise
|
| 2598 |
`*x > *y`.
|
| 2599 |
|
| 2600 |
*Remarks:* Specializations of this function template for which `*x > *y`
|
| 2601 |
+
is a core constant expression are constexpr functions.
|
| 2602 |
|
| 2603 |
``` cpp
|
| 2604 |
template<class T, class U> constexpr bool operator<=(const optional<T>& x, const optional<U>& y);
|
| 2605 |
```
|
| 2606 |
|
| 2607 |
+
*Mandates:* The expression `*x <= *y` is well-formed and its result is
|
| 2608 |
+
convertible to `bool`.
|
| 2609 |
|
| 2610 |
*Returns:* If `!x`, `true`; otherwise, if `!y`, `false`; otherwise
|
| 2611 |
`*x <= *y`.
|
| 2612 |
|
| 2613 |
*Remarks:* Specializations of this function template for which
|
| 2614 |
+
`*x <= *y` is a core constant expression are constexpr functions.
|
| 2615 |
|
| 2616 |
``` cpp
|
| 2617 |
template<class T, class U> constexpr bool operator>=(const optional<T>& x, const optional<U>& y);
|
| 2618 |
```
|
| 2619 |
|
| 2620 |
+
*Mandates:* The expression `*x >= *y` is well-formed and its result is
|
| 2621 |
+
convertible to `bool`.
|
| 2622 |
|
| 2623 |
*Returns:* If `!y`, `true`; otherwise, if `!x`, `false`; otherwise
|
| 2624 |
`*x >= *y`.
|
| 2625 |
|
| 2626 |
*Remarks:* Specializations of this function template for which
|
| 2627 |
+
`*x >= *y` is a core constant expression are constexpr functions.
|
| 2628 |
+
|
| 2629 |
+
``` cpp
|
| 2630 |
+
template<class T, three_way_comparable_with<T> U>
|
| 2631 |
+
constexpr compare_three_way_result_t<T,U>
|
| 2632 |
+
operator<=>(const optional<T>& x, const optional<U>& y);
|
| 2633 |
+
```
|
| 2634 |
+
|
| 2635 |
+
*Returns:* If `x && y`, `*x <=> *y`; otherwise `bool(x) <=> bool(y)`.
|
| 2636 |
+
|
| 2637 |
+
*Remarks:* Specializations of this function template for which
|
| 2638 |
+
`*x <=> *y` is a core constant expression are constexpr functions.
|
| 2639 |
|
| 2640 |
### Comparison with `nullopt` <a id="optional.nullops">[[optional.nullops]]</a>
|
| 2641 |
|
| 2642 |
``` cpp
|
| 2643 |
template<class T> constexpr bool operator==(const optional<T>& x, nullopt_t) noexcept;
|
|
|
|
| 2644 |
```
|
| 2645 |
|
| 2646 |
*Returns:* `!x`.
|
| 2647 |
|
| 2648 |
``` cpp
|
| 2649 |
+
template<class T> constexpr strong_ordering operator<=>(const optional<T>& x, nullopt_t) noexcept;
|
|
|
|
| 2650 |
```
|
| 2651 |
|
| 2652 |
+
*Returns:* `bool(x) <=> false`.
|
| 2653 |
|
| 2654 |
+
### Comparison with `T` <a id="optional.comp.with.t">[[optional.comp.with.t]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2655 |
|
| 2656 |
``` cpp
|
| 2657 |
template<class T, class U> constexpr bool operator==(const optional<T>& x, const U& v);
|
| 2658 |
```
|
| 2659 |
|
| 2660 |
+
*Mandates:* The expression `*x == v` is well-formed and its result is
|
| 2661 |
+
convertible to `bool`.
|
| 2662 |
|
| 2663 |
+
[*Note 1*: `T` need not be *Cpp17EqualityComparable*. — *end note*]
|
| 2664 |
|
| 2665 |
*Effects:* Equivalent to: `return bool(x) ? *x == v : false;`
|
| 2666 |
|
| 2667 |
``` cpp
|
| 2668 |
+
template<class T, class U> constexpr bool operator==(const T& v, const optional<U>& x);
|
| 2669 |
```
|
| 2670 |
|
| 2671 |
+
*Mandates:* The expression `v == *x` is well-formed and its result is
|
| 2672 |
+
convertible to `bool`.
|
| 2673 |
|
| 2674 |
*Effects:* Equivalent to: `return bool(x) ? v == *x : false;`
|
| 2675 |
|
| 2676 |
``` cpp
|
| 2677 |
template<class T, class U> constexpr bool operator!=(const optional<T>& x, const U& v);
|
| 2678 |
```
|
| 2679 |
|
| 2680 |
+
*Mandates:* The expression `*x != v` is well-formed and its result is
|
| 2681 |
+
convertible to `bool`.
|
| 2682 |
|
| 2683 |
*Effects:* Equivalent to: `return bool(x) ? *x != v : true;`
|
| 2684 |
|
| 2685 |
``` cpp
|
| 2686 |
+
template<class T, class U> constexpr bool operator!=(const T& v, const optional<U>& x);
|
| 2687 |
```
|
| 2688 |
|
| 2689 |
+
*Mandates:* The expression `v != *x` is well-formed and its result is
|
| 2690 |
+
convertible to `bool`.
|
| 2691 |
|
| 2692 |
*Effects:* Equivalent to: `return bool(x) ? v != *x : true;`
|
| 2693 |
|
| 2694 |
``` cpp
|
| 2695 |
template<class T, class U> constexpr bool operator<(const optional<T>& x, const U& v);
|
| 2696 |
```
|
| 2697 |
|
| 2698 |
+
*Mandates:* The expression `*x < v` is well-formed and its result is
|
| 2699 |
+
convertible to `bool`.
|
| 2700 |
|
| 2701 |
*Effects:* Equivalent to: `return bool(x) ? *x < v : true;`
|
| 2702 |
|
| 2703 |
``` cpp
|
| 2704 |
+
template<class T, class U> constexpr bool operator<(const T& v, const optional<U>& x);
|
| 2705 |
```
|
| 2706 |
|
| 2707 |
+
*Mandates:* The expression `v < *x` is well-formed and its result is
|
| 2708 |
+
convertible to `bool`.
|
| 2709 |
|
| 2710 |
*Effects:* Equivalent to: `return bool(x) ? v < *x : false;`
|
| 2711 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2712 |
``` cpp
|
| 2713 |
template<class T, class U> constexpr bool operator>(const optional<T>& x, const U& v);
|
| 2714 |
```
|
| 2715 |
|
| 2716 |
+
*Mandates:* The expression `*x > v` is well-formed and its result is
|
| 2717 |
+
convertible to `bool`.
|
| 2718 |
|
| 2719 |
*Effects:* Equivalent to: `return bool(x) ? *x > v : false;`
|
| 2720 |
|
| 2721 |
``` cpp
|
| 2722 |
+
template<class T, class U> constexpr bool operator>(const T& v, const optional<U>& x);
|
| 2723 |
```
|
| 2724 |
|
| 2725 |
+
*Mandates:* The expression `v > *x` is well-formed and its result is
|
| 2726 |
+
convertible to `bool`.
|
| 2727 |
|
| 2728 |
*Effects:* Equivalent to: `return bool(x) ? v > *x : true;`
|
| 2729 |
|
| 2730 |
+
``` cpp
|
| 2731 |
+
template<class T, class U> constexpr bool operator<=(const optional<T>& x, const U& v);
|
| 2732 |
+
```
|
| 2733 |
+
|
| 2734 |
+
*Mandates:* The expression `*x <= v` is well-formed and its result is
|
| 2735 |
+
convertible to `bool`.
|
| 2736 |
+
|
| 2737 |
+
*Effects:* Equivalent to: `return bool(x) ? *x <= v : true;`
|
| 2738 |
+
|
| 2739 |
+
``` cpp
|
| 2740 |
+
template<class T, class U> constexpr bool operator<=(const T& v, const optional<U>& x);
|
| 2741 |
+
```
|
| 2742 |
+
|
| 2743 |
+
*Mandates:* The expression `v <= *x` is well-formed and its result is
|
| 2744 |
+
convertible to `bool`.
|
| 2745 |
+
|
| 2746 |
+
*Effects:* Equivalent to: `return bool(x) ? v <= *x : false;`
|
| 2747 |
+
|
| 2748 |
``` cpp
|
| 2749 |
template<class T, class U> constexpr bool operator>=(const optional<T>& x, const U& v);
|
| 2750 |
```
|
| 2751 |
|
| 2752 |
+
*Mandates:* The expression `*x >= v` is well-formed and its result is
|
| 2753 |
+
convertible to `bool`.
|
| 2754 |
|
| 2755 |
*Effects:* Equivalent to: `return bool(x) ? *x >= v : false;`
|
| 2756 |
|
| 2757 |
``` cpp
|
| 2758 |
+
template<class T, class U> constexpr bool operator>=(const T& v, const optional<U>& x);
|
| 2759 |
```
|
| 2760 |
|
| 2761 |
+
*Mandates:* The expression `v >= *x` is well-formed and its result is
|
| 2762 |
+
convertible to `bool`.
|
| 2763 |
|
| 2764 |
*Effects:* Equivalent to: `return bool(x) ? v >= *x : true;`
|
| 2765 |
|
| 2766 |
+
``` cpp
|
| 2767 |
+
template<class T, three_way_comparable_with<T> U>
|
| 2768 |
+
constexpr compare_three_way_result_t<T,U>
|
| 2769 |
+
operator<=>(const optional<T>& x, const U& v);
|
| 2770 |
+
```
|
| 2771 |
+
|
| 2772 |
+
*Effects:* Equivalent to:
|
| 2773 |
+
`return bool(x) ? *x <=> v : strong_ordering::less;`
|
| 2774 |
+
|
| 2775 |
### Specialized algorithms <a id="optional.specalg">[[optional.specalg]]</a>
|
| 2776 |
|
| 2777 |
``` cpp
|
| 2778 |
template<class T> void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y)));
|
| 2779 |
```
|
| 2780 |
|
| 2781 |
+
*Constraints:* `is_move_constructible_v<T>` is `true` and
|
| 2782 |
+
`is_swappable_v<T>` is `true`.
|
| 2783 |
|
| 2784 |
+
*Effects:* Calls `x.swap(y)`.
|
|
|
|
|
|
|
| 2785 |
|
| 2786 |
``` cpp
|
| 2787 |
template<class T> constexpr optional<decay_t<T>> make_optional(T&& v);
|
| 2788 |
```
|
| 2789 |
|
|
|
|
| 2809 |
|
| 2810 |
``` cpp
|
| 2811 |
template<class T> struct hash<optional<T>>;
|
| 2812 |
```
|
| 2813 |
|
| 2814 |
+
The specialization `hash<optional<T>>` is enabled [[unord.hash]] if and
|
| 2815 |
+
only if `hash<remove_const_t<T>>` is enabled. When enabled, for an
|
| 2816 |
object `o` of type `optional<T>`, if `bool(o) == true`, then
|
| 2817 |
+
`hash<optional<T>>()(o)` evaluates to the same value as
|
| 2818 |
`hash<remove_const_t<T>>()(*o)`; otherwise it evaluates to an
|
| 2819 |
unspecified value. The member functions are not guaranteed to be
|
| 2820 |
`noexcept`.
|
| 2821 |
|
| 2822 |
## Variants <a id="variant">[[variant]]</a>
|
| 2823 |
|
| 2824 |
### In general <a id="variant.general">[[variant.general]]</a>
|
| 2825 |
|
| 2826 |
A variant object holds and manages the lifetime of a value. If the
|
| 2827 |
`variant` holds a value, that value’s type has to be one of the template
|
| 2828 |
+
argument types given to `variant`. These template arguments are called
|
| 2829 |
alternatives.
|
| 2830 |
|
| 2831 |
### Header `<variant>` synopsis <a id="variant.syn">[[variant.syn]]</a>
|
| 2832 |
|
| 2833 |
``` cpp
|
| 2834 |
+
#include <compare> // see [compare.syn]
|
| 2835 |
+
|
| 2836 |
namespace std {
|
| 2837 |
// [variant.variant], class template variant
|
| 2838 |
template<class... Types>
|
| 2839 |
class variant;
|
| 2840 |
|
| 2841 |
// [variant.helper], variant helper classes
|
| 2842 |
template<class T> struct variant_size; // not defined
|
| 2843 |
template<class T> struct variant_size<const T>;
|
|
|
|
|
|
|
| 2844 |
template<class T>
|
| 2845 |
inline constexpr size_t variant_size_v = variant_size<T>::value;
|
| 2846 |
|
| 2847 |
template<class... Types>
|
| 2848 |
struct variant_size<variant<Types...>>;
|
| 2849 |
|
| 2850 |
template<size_t I, class T> struct variant_alternative; // not defined
|
| 2851 |
template<size_t I, class T> struct variant_alternative<I, const T>;
|
|
|
|
|
|
|
| 2852 |
template<size_t I, class T>
|
| 2853 |
using variant_alternative_t = typename variant_alternative<I, T>::type;
|
| 2854 |
|
| 2855 |
template<size_t I, class... Types>
|
| 2856 |
struct variant_alternative<I, variant<Types...>>;
|
|
|
|
| 2904 |
constexpr bool operator>(const variant<Types...>&, const variant<Types...>&);
|
| 2905 |
template<class... Types>
|
| 2906 |
constexpr bool operator<=(const variant<Types...>&, const variant<Types...>&);
|
| 2907 |
template<class... Types>
|
| 2908 |
constexpr bool operator>=(const variant<Types...>&, const variant<Types...>&);
|
| 2909 |
+
template<class... Types> requires (three_way_comparable<Types> && ...)
|
| 2910 |
+
constexpr common_comparison_category_t<compare_three_way_result_t<Types>...>
|
| 2911 |
+
operator<=>(const variant<Types...>&, const variant<Types...>&);
|
| 2912 |
|
| 2913 |
// [variant.visit], visitation
|
| 2914 |
template<class Visitor, class... Variants>
|
| 2915 |
constexpr see below visit(Visitor&&, Variants&&...);
|
| 2916 |
+
template<class R, class Visitor, class... Variants>
|
| 2917 |
+
constexpr R visit(Visitor&&, Variants&&...);
|
| 2918 |
|
| 2919 |
// [variant.monostate], class monostate
|
| 2920 |
struct monostate;
|
| 2921 |
|
| 2922 |
// [variant.monostate.relops], monostate relational operators
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2923 |
constexpr bool operator==(monostate, monostate) noexcept;
|
| 2924 |
+
constexpr strong_ordering operator<=>(monostate, monostate) noexcept;
|
| 2925 |
|
| 2926 |
// [variant.specalg], specialized algorithms
|
| 2927 |
template<class... Types>
|
| 2928 |
void swap(variant<Types...>&, variant<Types...>&) noexcept(see below);
|
| 2929 |
|
|
|
|
| 2932 |
|
| 2933 |
// [variant.hash], hash support
|
| 2934 |
template<class T> struct hash;
|
| 2935 |
template<class... Types> struct hash<variant<Types...>>;
|
| 2936 |
template<> struct hash<monostate>;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2937 |
}
|
| 2938 |
```
|
| 2939 |
|
| 2940 |
### Class template `variant` <a id="variant.variant">[[variant.variant]]</a>
|
| 2941 |
|
|
|
|
| 2944 |
template<class... Types>
|
| 2945 |
class variant {
|
| 2946 |
public:
|
| 2947 |
// [variant.ctor], constructors
|
| 2948 |
constexpr variant() noexcept(see below);
|
| 2949 |
+
constexpr variant(const variant&);
|
| 2950 |
+
constexpr variant(variant&&) noexcept(see below);
|
| 2951 |
|
| 2952 |
template<class T>
|
| 2953 |
constexpr variant(T&&) noexcept(see below);
|
| 2954 |
|
| 2955 |
template<class T, class... Args>
|
|
|
|
| 2960 |
template<size_t I, class... Args>
|
| 2961 |
constexpr explicit variant(in_place_index_t<I>, Args&&...);
|
| 2962 |
template<size_t I, class U, class... Args>
|
| 2963 |
constexpr explicit variant(in_place_index_t<I>, initializer_list<U>, Args&&...);
|
| 2964 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2965 |
// [variant.dtor], destructor
|
| 2966 |
~variant();
|
| 2967 |
|
| 2968 |
// [variant.assign], assignment
|
| 2969 |
+
constexpr variant& operator=(const variant&);
|
| 2970 |
+
constexpr variant& operator=(variant&&) noexcept(see below);
|
| 2971 |
|
| 2972 |
template<class T> variant& operator=(T&&) noexcept(see below);
|
| 2973 |
|
| 2974 |
// [variant.mod], modifiers
|
| 2975 |
template<class T, class... Args>
|
|
|
|
| 2990 |
};
|
| 2991 |
}
|
| 2992 |
```
|
| 2993 |
|
| 2994 |
Any instance of `variant` at any given time either holds a value of one
|
| 2995 |
+
of its alternative types or holds no value. When an instance of
|
| 2996 |
`variant` holds a value of alternative type `T`, it means that a value
|
| 2997 |
of type `T`, referred to as the `variant` object’s *contained value*, is
|
| 2998 |
allocated within the storage of the `variant` object. Implementations
|
| 2999 |
are not permitted to use additional storage, such as dynamic memory, to
|
| 3000 |
allocate the contained value. The contained value shall be allocated in
|
| 3001 |
a region of the `variant` storage suitably aligned for all types in
|
| 3002 |
+
`Types`.
|
|
|
|
| 3003 |
|
| 3004 |
+
All types in `Types` shall meet the *Cpp17Destructible* requirements (
|
| 3005 |
+
[[cpp17.destructible]]).
|
| 3006 |
|
| 3007 |
A program that instantiates the definition of `variant` with no template
|
| 3008 |
arguments is ill-formed.
|
| 3009 |
|
| 3010 |
#### Constructors <a id="variant.ctor">[[variant.ctor]]</a>
|
| 3011 |
|
| 3012 |
In the descriptions that follow, let i be in the range \[`0`,
|
| 3013 |
+
`sizeof...(Types)`), and `Tᵢ` be the iᵗʰ type in `Types`.
|
| 3014 |
|
| 3015 |
``` cpp
|
| 3016 |
constexpr variant() noexcept(see below);
|
| 3017 |
```
|
| 3018 |
|
| 3019 |
+
*Constraints:* `is_default_constructible_v<``T₀``>` is `true`.
|
| 3020 |
+
|
| 3021 |
*Effects:* Constructs a `variant` holding a value-initialized value of
|
| 3022 |
type `T₀`.
|
| 3023 |
|
| 3024 |
+
*Ensures:* `valueless_by_exception()` is `false` and `index()` is `0`.
|
|
|
|
| 3025 |
|
| 3026 |
*Throws:* Any exception thrown by the value-initialization of `T₀`.
|
| 3027 |
|
| 3028 |
+
*Remarks:* This function is `constexpr` if and only if the
|
| 3029 |
value-initialization of the alternative type `T₀` would satisfy the
|
| 3030 |
requirements for a constexpr function. The expression inside `noexcept`
|
| 3031 |
+
is equivalent to `is_nothrow_default_constructible_v<``T₀``>`.
|
|
|
|
|
|
|
| 3032 |
|
| 3033 |
[*Note 1*: See also class `monostate`. — *end note*]
|
| 3034 |
|
| 3035 |
``` cpp
|
| 3036 |
+
constexpr variant(const variant& w);
|
| 3037 |
```
|
| 3038 |
|
| 3039 |
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 3040 |
same alternative as `w` and direct-initializes the contained value with
|
| 3041 |
`get<j>(w)`, where `j` is `w.index()`. Otherwise, initializes the
|
| 3042 |
`variant` to not hold a value.
|
| 3043 |
|
| 3044 |
*Throws:* Any exception thrown by direct-initializing any `Tᵢ` for all
|
| 3045 |
i.
|
| 3046 |
|
| 3047 |
+
*Remarks:* This constructor is defined as deleted unless
|
| 3048 |
+
`is_copy_constructible_v<``Tᵢ``>` is `true` for all i. If
|
| 3049 |
+
`is_trivially_copy_constructible_v<``Tᵢ``>` is `true` for all i, this
|
| 3050 |
+
constructor is trivial.
|
| 3051 |
|
| 3052 |
``` cpp
|
| 3053 |
+
constexpr variant(variant&& w) noexcept(see below);
|
| 3054 |
```
|
| 3055 |
|
| 3056 |
+
*Constraints:* `is_move_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 3057 |
+
|
| 3058 |
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 3059 |
same alternative as `w` and direct-initializes the contained value with
|
| 3060 |
`get<j>(std::move(w))`, where `j` is `w.index()`. Otherwise, initializes
|
| 3061 |
the `variant` to not hold a value.
|
| 3062 |
|
| 3063 |
*Throws:* Any exception thrown by move-constructing any `Tᵢ` for all i.
|
| 3064 |
|
| 3065 |
*Remarks:* The expression inside `noexcept` is equivalent to the logical
|
| 3066 |
+
of `is_nothrow_move_constructible_v<``Tᵢ``>` for all i. If
|
| 3067 |
+
`is_trivially_move_constructible_v<``Tᵢ``>` is `true` for all i, this
|
| 3068 |
+
constructor is trivial.
|
| 3069 |
|
| 3070 |
``` cpp
|
| 3071 |
template<class T> constexpr variant(T&& t) noexcept(see below);
|
| 3072 |
```
|
| 3073 |
|
| 3074 |
Let `Tⱼ` be a type that is determined as follows: build an imaginary
|
| 3075 |
+
function *FUN*(Tᵢ) for each alternative type `Tᵢ` for which `Tᵢ`` x[] =`
|
| 3076 |
+
`{std::forward<T>(t)};` is well-formed for some invented variable `x`.
|
| 3077 |
+
The overload *FUN*(Tⱼ) selected by overload resolution for the
|
| 3078 |
+
expression *FUN*(std::forward\<T\>(t)) defines the alternative `Tⱼ`
|
| 3079 |
+
which is the type of the contained value after construction.
|
| 3080 |
+
|
| 3081 |
+
*Constraints:*
|
| 3082 |
+
|
| 3083 |
+
- `sizeof...(Types)` is nonzero,
|
| 3084 |
+
- `is_same_v<remove_cvref_t<T>, variant>` is `false`,
|
| 3085 |
+
- `remove_cvref_t<T>` is neither a specialization of `in_place_type_t`
|
| 3086 |
+
nor a specialization of `in_place_index_t`,
|
| 3087 |
+
- `is_constructible_v<``Tⱼ``, T>` is `true`, and
|
| 3088 |
+
- the expression *FUN*(`std::forward<T>(t))` (with *FUN* being the
|
| 3089 |
+
above-mentioned set of imaginary functions) is well-formed.
|
| 3090 |
+
\[*Note 1*:
|
| 3091 |
+
variant<string, string> v("abc");
|
| 3092 |
+
|
| 3093 |
+
is ill-formed, as both alternative types have an equally viable
|
| 3094 |
+
constructor for the argument.
|
| 3095 |
+
— *end note*]
|
| 3096 |
|
| 3097 |
*Effects:* Initializes `*this` to hold the alternative type `Tⱼ` and
|
| 3098 |
direct-initializes the contained value as if
|
| 3099 |
direct-non-list-initializing it with `std::forward<T>(t)`.
|
| 3100 |
|
| 3101 |
+
*Ensures:* `holds_alternative<``Tⱼ``>(*this)` is `true`.
|
| 3102 |
|
| 3103 |
*Throws:* Any exception thrown by the initialization of the selected
|
| 3104 |
alternative `Tⱼ`.
|
| 3105 |
|
| 3106 |
+
*Remarks:* The expression inside `noexcept` is equivalent to
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3107 |
`is_nothrow_constructible_v<``Tⱼ``, T>`. If `Tⱼ`’s selected constructor
|
| 3108 |
+
is a constexpr constructor, this constructor is a constexpr constructor.
|
|
|
|
| 3109 |
|
| 3110 |
``` cpp
|
| 3111 |
template<class T, class... Args> constexpr explicit variant(in_place_type_t<T>, Args&&... args);
|
| 3112 |
```
|
| 3113 |
|
| 3114 |
+
*Constraints:*
|
| 3115 |
+
|
| 3116 |
+
- There is exactly one occurrence of `T` in `Types...` and
|
| 3117 |
+
- `is_constructible_v<T, Args...>` is `true`.
|
| 3118 |
+
|
| 3119 |
*Effects:* Initializes the contained value as if
|
| 3120 |
direct-non-list-initializing an object of type `T` with the arguments
|
| 3121 |
`std::forward<Args>(args)...`.
|
| 3122 |
|
| 3123 |
+
*Ensures:* `holds_alternative<T>(*this)` is `true`.
|
| 3124 |
|
| 3125 |
*Throws:* Any exception thrown by calling the selected constructor of
|
| 3126 |
`T`.
|
| 3127 |
|
| 3128 |
+
*Remarks:* If `T`’s selected constructor is a constexpr constructor,
|
| 3129 |
+
this constructor is a constexpr constructor.
|
|
|
|
|
|
|
|
|
|
| 3130 |
|
| 3131 |
``` cpp
|
| 3132 |
template<class T, class U, class... Args>
|
| 3133 |
constexpr explicit variant(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
|
| 3134 |
```
|
| 3135 |
|
| 3136 |
+
*Constraints:*
|
| 3137 |
+
|
| 3138 |
+
- There is exactly one occurrence of `T` in `Types...` and
|
| 3139 |
+
- `is_constructible_v<T, initializer_list<U>&, Args...>` is `true`.
|
| 3140 |
+
|
| 3141 |
*Effects:* Initializes the contained value as if
|
| 3142 |
direct-non-list-initializing an object of type `T` with the arguments
|
| 3143 |
`il, std::forward<Args>(args)...`.
|
| 3144 |
|
| 3145 |
+
*Ensures:* `holds_alternative<T>(*this)` is `true`.
|
| 3146 |
|
| 3147 |
*Throws:* Any exception thrown by calling the selected constructor of
|
| 3148 |
`T`.
|
| 3149 |
|
| 3150 |
+
*Remarks:* If `T`’s selected constructor is a constexpr constructor,
|
| 3151 |
+
this constructor is a constexpr constructor.
|
|
|
|
|
|
|
|
|
|
| 3152 |
|
| 3153 |
``` cpp
|
| 3154 |
template<size_t I, class... Args> constexpr explicit variant(in_place_index_t<I>, Args&&... args);
|
| 3155 |
```
|
| 3156 |
|
| 3157 |
+
*Constraints:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3158 |
|
| 3159 |
- `I` is less than `sizeof...(Types)` and
|
| 3160 |
- `is_constructible_v<``T_I``, Args...>` is `true`.
|
| 3161 |
|
| 3162 |
+
*Effects:* Initializes the contained value as if
|
| 3163 |
+
direct-non-list-initializing an object of type `T_I` with the arguments
|
| 3164 |
+
`std::forward<Args>(args)...`.
|
| 3165 |
+
|
| 3166 |
+
*Ensures:* `index()` is `I`.
|
| 3167 |
+
|
| 3168 |
+
*Throws:* Any exception thrown by calling the selected constructor of
|
| 3169 |
+
`T_I`.
|
| 3170 |
+
|
| 3171 |
+
*Remarks:* If `T_I`’s selected constructor is a constexpr constructor,
|
| 3172 |
+
this constructor is a constexpr constructor.
|
| 3173 |
|
| 3174 |
``` cpp
|
| 3175 |
template<size_t I, class U, class... Args>
|
| 3176 |
constexpr explicit variant(in_place_index_t<I>, initializer_list<U> il, Args&&... args);
|
| 3177 |
```
|
| 3178 |
|
| 3179 |
+
*Constraints:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3180 |
|
| 3181 |
- `I` is less than `sizeof...(Types)` and
|
| 3182 |
- `is_constructible_v<``T_I``, initializer_list<U>&, Args...>` is
|
| 3183 |
`true`.
|
| 3184 |
|
| 3185 |
+
*Effects:* Initializes the contained value as if
|
| 3186 |
+
direct-non-list-initializing an object of type `T_I` with the arguments
|
| 3187 |
+
`il, std::forward<Args>(args)...`.
|
| 3188 |
|
| 3189 |
+
*Ensures:* `index()` is `I`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3190 |
|
| 3191 |
+
*Remarks:* If `T_I`’s selected constructor is a constexpr constructor,
|
| 3192 |
+
this constructor is a constexpr constructor.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3193 |
|
| 3194 |
#### Destructor <a id="variant.dtor">[[variant.dtor]]</a>
|
| 3195 |
|
| 3196 |
``` cpp
|
| 3197 |
~variant();
|
| 3198 |
```
|
| 3199 |
|
| 3200 |
*Effects:* If `valueless_by_exception()` is `false`, destroys the
|
| 3201 |
currently contained value.
|
| 3202 |
|
| 3203 |
+
*Remarks:* If `is_trivially_destructible_v<``Tᵢ``>` is `true` for all
|
| 3204 |
+
`Tᵢ`, then this destructor is trivial.
|
| 3205 |
|
| 3206 |
#### Assignment <a id="variant.assign">[[variant.assign]]</a>
|
| 3207 |
|
| 3208 |
``` cpp
|
| 3209 |
+
constexpr variant& operator=(const variant& rhs);
|
| 3210 |
```
|
| 3211 |
|
| 3212 |
Let j be `rhs.index()`.
|
| 3213 |
|
| 3214 |
*Effects:*
|
| 3215 |
|
| 3216 |
- If neither `*this` nor `rhs` holds a value, there is no effect.
|
| 3217 |
+
- Otherwise, if `*this` holds a value but `rhs` does not, destroys the
|
| 3218 |
+
value contained in `*this` and sets `*this` to not hold a value.
|
| 3219 |
+
- Otherwise, if `index() == `j, assigns the value contained in `rhs` to
|
| 3220 |
+
the value contained in `*this`.
|
| 3221 |
+
- Otherwise, if either `is_nothrow_copy_constructible_v<``Tⱼ``>` is
|
| 3222 |
+
`true` or `is_nothrow_move_constructible_v<``Tⱼ``>` is `false`,
|
| 3223 |
+
equivalent to `emplace<`j`>(get<`j`>(rhs))`.
|
| 3224 |
+
- Otherwise, equivalent to `operator=(variant(rhs))`.
|
|
|
|
| 3225 |
|
| 3226 |
*Returns:* `*this`.
|
| 3227 |
|
| 3228 |
+
*Ensures:* `index() == rhs.index()`.
|
| 3229 |
|
| 3230 |
+
*Remarks:* This operator is defined as deleted unless
|
| 3231 |
+
`is_copy_constructible_v<``Tᵢ``> &&` `is_copy_assignable_v<``Tᵢ``>` is
|
| 3232 |
+
`true` for all i. If `is_trivially_copy_constructible_v<``Tᵢ``> &&`
|
| 3233 |
+
`is_trivially_copy_assignable_v<``Tᵢ``> &&`
|
| 3234 |
+
`is_trivially_destructible_v<``Tᵢ``>` is `true` for all i, this
|
| 3235 |
+
assignment operator is trivial.
|
| 3236 |
|
| 3237 |
``` cpp
|
| 3238 |
+
constexpr variant& operator=(variant&& rhs) noexcept(see below);
|
| 3239 |
```
|
| 3240 |
|
| 3241 |
Let j be `rhs.index()`.
|
| 3242 |
|
| 3243 |
+
*Constraints:* `is_move_constructible_v<``Tᵢ``> &&`
|
| 3244 |
+
`is_move_assignable_v<``Tᵢ``>` is `true` for all i.
|
| 3245 |
+
|
| 3246 |
*Effects:*
|
| 3247 |
|
| 3248 |
- If neither `*this` nor `rhs` holds a value, there is no effect.
|
| 3249 |
+
- Otherwise, if `*this` holds a value but `rhs` does not, destroys the
|
| 3250 |
+
value contained in `*this` and sets `*this` to not hold a value.
|
| 3251 |
+
- Otherwise, if `index() == `j, assigns `get<`j`>(std::move(rhs))` to
|
| 3252 |
+
the value contained in `*this`.
|
| 3253 |
+
- Otherwise, equivalent to `emplace<`j`>(get<`j`>(std::move(rhs)))`.
|
|
|
|
| 3254 |
|
| 3255 |
*Returns:* `*this`.
|
| 3256 |
|
| 3257 |
+
*Remarks:* If `is_trivially_move_constructible_v<``Tᵢ``> &&`
|
| 3258 |
+
`is_trivially_move_assignable_v<``Tᵢ``> &&`
|
| 3259 |
+
`is_trivially_destructible_v<``Tᵢ``>` is `true` for all i, this
|
| 3260 |
+
assignment operator is trivial. The expression inside `noexcept` is
|
| 3261 |
+
equivalent to:
|
| 3262 |
`is_nothrow_move_constructible_v<``Tᵢ``> && is_nothrow_move_assignable_v<``Tᵢ``>`
|
| 3263 |
for all i.
|
| 3264 |
|
| 3265 |
- If an exception is thrown during the call to `Tⱼ`’s move construction
|
| 3266 |
+
(with j being `rhs.index()`), the `variant` will hold no value.
|
| 3267 |
- If an exception is thrown during the call to `Tⱼ`’s move assignment,
|
| 3268 |
the state of the contained value is as defined by the exception safety
|
| 3269 |
guarantee of `Tⱼ`’s move assignment; `index()` will be j.
|
| 3270 |
|
| 3271 |
``` cpp
|
| 3272 |
template<class T> variant& operator=(T&& t) noexcept(see below);
|
| 3273 |
```
|
| 3274 |
|
| 3275 |
Let `Tⱼ` be a type that is determined as follows: build an imaginary
|
| 3276 |
+
function *FUN*(Tᵢ) for each alternative type `Tᵢ` for which `Tᵢ`` x[] =`
|
| 3277 |
+
`{std::forward<T>(t)};` is well-formed for some invented variable `x`.
|
| 3278 |
+
The overload *FUN*(Tⱼ) selected by overload resolution for the
|
| 3279 |
+
expression *FUN*(std::forward\<T\>(t)) defines the alternative `Tⱼ`
|
| 3280 |
+
which is the type of the contained value after assignment.
|
| 3281 |
+
|
| 3282 |
+
*Constraints:*
|
| 3283 |
+
|
| 3284 |
+
- `is_same_v<remove_cvref_t<T>, variant>` is `false`,
|
| 3285 |
+
- `is_assignable_v<``Tⱼ``&, T> && is_constructible_v<``Tⱼ``, T>` is
|
| 3286 |
+
`true`, and
|
| 3287 |
+
- the expression *FUN*(std::forward\<T\>(t)) (with *FUN* being the
|
| 3288 |
+
above-mentioned set of imaginary functions) is well-formed.
|
| 3289 |
+
\[*Note 1*:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3290 |
variant<string, string> v;
|
| 3291 |
v = "abc";
|
|
|
|
| 3292 |
|
| 3293 |
is ill-formed, as both alternative types have an equally viable
|
| 3294 |
constructor for the argument.
|
|
|
|
| 3295 |
— *end note*]
|
| 3296 |
|
| 3297 |
+
*Effects:*
|
| 3298 |
+
|
| 3299 |
+
- If `*this` holds a `Tⱼ`, assigns `std::forward<T>(t)` to the value
|
| 3300 |
+
contained in `*this`.
|
| 3301 |
+
- Otherwise, if `is_nothrow_constructible_v<``Tⱼ``, T> ||`
|
| 3302 |
+
`!is_nothrow_move_constructible_v<``Tⱼ``>` is `true`, equivalent to
|
| 3303 |
+
`emplace<`j`>(std::forward<T>(t))`.
|
| 3304 |
+
- Otherwise, equivalent to `operator=(variant(std::forward<T>(t)))`.
|
| 3305 |
+
|
| 3306 |
+
*Ensures:* `holds_alternative<``Tⱼ``>(*this)` is `true`, with `Tⱼ`
|
| 3307 |
+
selected by the imaginary function overload resolution described above.
|
| 3308 |
+
|
| 3309 |
+
*Returns:* `*this`.
|
| 3310 |
+
|
| 3311 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 3312 |
|
| 3313 |
``` cpp
|
| 3314 |
is_nothrow_assignable_v<Tⱼ&, T> && is_nothrow_constructible_v<Tⱼ, T>
|
| 3315 |
```
|
| 3316 |
|
|
|
|
| 3326 |
|
| 3327 |
``` cpp
|
| 3328 |
template<class T, class... Args> T& emplace(Args&&... args);
|
| 3329 |
```
|
| 3330 |
|
| 3331 |
+
*Constraints:* `is_constructible_v<T, Args...>` is `true`, and `T`
|
| 3332 |
+
occurs exactly once in `Types`.
|
| 3333 |
|
| 3334 |
*Effects:* Equivalent to:
|
|
|
|
| 3335 |
|
| 3336 |
+
``` cpp
|
| 3337 |
+
return emplace<I>(std::forward<Args>(args)...);
|
| 3338 |
+
```
|
| 3339 |
+
|
| 3340 |
+
where I is the zero-based index of `T` in `Types`.
|
| 3341 |
|
| 3342 |
``` cpp
|
| 3343 |
template<class T, class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
|
| 3344 |
```
|
| 3345 |
|
| 3346 |
+
*Constraints:* `is_constructible_v<T, initializer_list<U>&, Args...>` is
|
| 3347 |
+
`true`, and `T` occurs exactly once in `Types`.
|
| 3348 |
|
| 3349 |
*Effects:* Equivalent to:
|
|
|
|
| 3350 |
|
| 3351 |
+
``` cpp
|
| 3352 |
+
return emplace<I>(il, std::forward<Args>(args)...);
|
| 3353 |
+
```
|
| 3354 |
+
|
| 3355 |
+
where I is the zero-based index of `T` in `Types`.
|
| 3356 |
|
| 3357 |
``` cpp
|
| 3358 |
template<size_t I, class... Args>
|
| 3359 |
variant_alternative_t<I, variant<Types...>>& emplace(Args&&... args);
|
| 3360 |
```
|
| 3361 |
|
| 3362 |
+
*Mandates:* `I` < `sizeof...(Types)`.
|
| 3363 |
+
|
| 3364 |
+
*Constraints:* `is_constructible_v<``T_I``, Args...>` is `true`.
|
| 3365 |
|
| 3366 |
*Effects:* Destroys the currently contained value if
|
| 3367 |
`valueless_by_exception()` is `false`. Then initializes the contained
|
| 3368 |
value as if direct-non-list-initializing a value of type `T_I` with the
|
| 3369 |
arguments `std::forward<Args>(args)...`.
|
| 3370 |
|
| 3371 |
+
*Ensures:* `index()` is `I`.
|
| 3372 |
|
| 3373 |
*Returns:* A reference to the new contained value.
|
| 3374 |
|
| 3375 |
*Throws:* Any exception thrown during the initialization of the
|
| 3376 |
contained value.
|
| 3377 |
|
| 3378 |
+
*Remarks:* If an exception is thrown during the initialization of the
|
| 3379 |
+
contained value, the `variant` might not hold a value.
|
|
|
|
|
|
|
| 3380 |
|
| 3381 |
``` cpp
|
| 3382 |
template<size_t I, class U, class... Args>
|
| 3383 |
variant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U> il, Args&&... args);
|
| 3384 |
```
|
| 3385 |
|
| 3386 |
+
*Mandates:* `I` < `sizeof...(Types)`.
|
| 3387 |
+
|
| 3388 |
+
*Constraints:*
|
| 3389 |
+
`is_constructible_v<``T_I``, initializer_list<U>&, Args...>` is `true`.
|
| 3390 |
|
| 3391 |
*Effects:* Destroys the currently contained value if
|
| 3392 |
`valueless_by_exception()` is `false`. Then initializes the contained
|
| 3393 |
value as if direct-non-list-initializing a value of type `T_I` with the
|
| 3394 |
arguments `il, std::forward<Args>(args)...`.
|
| 3395 |
|
| 3396 |
+
*Ensures:* `index()` is `I`.
|
| 3397 |
|
| 3398 |
*Returns:* A reference to the new contained value.
|
| 3399 |
|
| 3400 |
*Throws:* Any exception thrown during the initialization of the
|
| 3401 |
contained value.
|
| 3402 |
|
| 3403 |
+
*Remarks:* If an exception is thrown during the initialization of the
|
|
|
|
|
|
|
| 3404 |
contained value, the `variant` might not hold a value.
|
| 3405 |
|
| 3406 |
#### Value status <a id="variant.status">[[variant.status]]</a>
|
| 3407 |
|
| 3408 |
``` cpp
|
|
|
|
| 3438 |
|
| 3439 |
``` cpp
|
| 3440 |
void swap(variant& rhs) noexcept(see below);
|
| 3441 |
```
|
| 3442 |
|
| 3443 |
+
*Mandates:* `is_move_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 3444 |
+
|
| 3445 |
+
*Preconditions:* Lvalues of type `Tᵢ` are
|
| 3446 |
+
swappable [[swappable.requirements]].
|
| 3447 |
|
| 3448 |
*Effects:*
|
| 3449 |
|
| 3450 |
+
- If `valueless_by_exception() && rhs.valueless_by_exception()` no
|
| 3451 |
+
effect.
|
| 3452 |
+
- Otherwise, if `index() == rhs.index()`, calls
|
| 3453 |
`swap(get<`i`>(*this), get<`i`>(rhs))` where i is `index()`.
|
| 3454 |
+
- Otherwise, exchanges values of `rhs` and `*this`.
|
|
|
|
| 3455 |
|
| 3456 |
*Throws:* If `index() == rhs.index()`, any exception thrown by
|
| 3457 |
`swap(get<`i`>(*this), get<`i`>(rhs))` with i being `index()`.
|
| 3458 |
Otherwise, any exception thrown by the move constructor of `Tᵢ` or `Tⱼ`
|
| 3459 |
with i being `index()` and j being `rhs.index()`.
|
|
|
|
| 3463 |
values of `*this` and of `rhs` are determined by the exception safety
|
| 3464 |
guarantee of `swap` for lvalues of `Tᵢ` with i being `index()`. If an
|
| 3465 |
exception is thrown during the exchange of the values of `*this` and
|
| 3466 |
`rhs`, the states of the values of `*this` and of `rhs` are determined
|
| 3467 |
by the exception safety guarantee of `variant`’s move constructor. The
|
| 3468 |
+
expression inside `noexcept` is equivalent to the logical of
|
| 3469 |
`is_nothrow_move_constructible_v<``Tᵢ``> && is_nothrow_swappable_v<``Tᵢ``>`
|
| 3470 |
for all i.
|
| 3471 |
|
| 3472 |
### `variant` helper classes <a id="variant.helper">[[variant.helper]]</a>
|
| 3473 |
|
| 3474 |
``` cpp
|
| 3475 |
template<class T> struct variant_size;
|
| 3476 |
```
|
| 3477 |
|
| 3478 |
+
All specializations of `variant_size` meet the *Cpp17UnaryTypeTrait*
|
| 3479 |
+
requirements [[meta.rqmts]] with a base characteristic of
|
| 3480 |
+
`integral_constant<size_t, N>` for some `N`.
|
| 3481 |
|
| 3482 |
``` cpp
|
| 3483 |
template<class T> class variant_size<const T>;
|
|
|
|
|
|
|
| 3484 |
```
|
| 3485 |
|
| 3486 |
Let `VS` denote `variant_size<T>` of the cv-unqualified type `T`. Then
|
| 3487 |
+
each specialization of the template meets the *Cpp17UnaryTypeTrait*
|
| 3488 |
+
requirements [[meta.rqmts]] with a base characteristic of
|
| 3489 |
`integral_constant<size_t, VS::value>`.
|
| 3490 |
|
| 3491 |
``` cpp
|
| 3492 |
template<class... Types>
|
| 3493 |
struct variant_size<variant<Types...>> : integral_constant<size_t, sizeof...(Types)> { };
|
| 3494 |
```
|
| 3495 |
|
| 3496 |
``` cpp
|
| 3497 |
template<size_t I, class T> class variant_alternative<I, const T>;
|
|
|
|
|
|
|
| 3498 |
```
|
| 3499 |
|
| 3500 |
Let `VA` denote `variant_alternative<I, T>` of the cv-unqualified type
|
| 3501 |
+
`T`. Then each specialization of the template meets the
|
| 3502 |
+
*Cpp17TransformationTrait* requirements [[meta.rqmts]] with a member
|
| 3503 |
+
typedef `type` that names the type `add_const_t<VA::type>`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3504 |
|
| 3505 |
``` cpp
|
| 3506 |
variant_alternative<I, variant<Types...>>::type
|
| 3507 |
```
|
| 3508 |
|
| 3509 |
+
*Mandates:* `I` < `sizeof...(Types)`.
|
| 3510 |
|
| 3511 |
+
*Type:* The type `T_I`.
|
| 3512 |
|
| 3513 |
### Value access <a id="variant.get">[[variant.get]]</a>
|
| 3514 |
|
| 3515 |
``` cpp
|
| 3516 |
template<class T, class... Types>
|
| 3517 |
constexpr bool holds_alternative(const variant<Types...>& v) noexcept;
|
| 3518 |
```
|
| 3519 |
|
| 3520 |
+
*Mandates:* The type `T` occurs exactly once in `Types`.
|
|
|
|
| 3521 |
|
| 3522 |
*Returns:* `true` if `index()` is equal to the zero-based index of `T`
|
| 3523 |
+
in `Types`.
|
| 3524 |
|
| 3525 |
``` cpp
|
| 3526 |
template<size_t I, class... Types>
|
| 3527 |
constexpr variant_alternative_t<I, variant<Types...>>& get(variant<Types...>& v);
|
| 3528 |
template<size_t I, class... Types>
|
|
|
|
| 3531 |
constexpr const variant_alternative_t<I, variant<Types...>>& get(const variant<Types...>& v);
|
| 3532 |
template<size_t I, class... Types>
|
| 3533 |
constexpr const variant_alternative_t<I, variant<Types...>>&& get(const variant<Types...>&& v);
|
| 3534 |
```
|
| 3535 |
|
| 3536 |
+
*Mandates:* `I` < `sizeof...(Types)`.
|
| 3537 |
|
| 3538 |
*Effects:* If `v.index()` is `I`, returns a reference to the object
|
| 3539 |
stored in the `variant`. Otherwise, throws an exception of type
|
| 3540 |
`bad_variant_access`.
|
| 3541 |
|
|
|
|
| 3544 |
template<class T, class... Types> constexpr T&& get(variant<Types...>&& v);
|
| 3545 |
template<class T, class... Types> constexpr const T& get(const variant<Types...>& v);
|
| 3546 |
template<class T, class... Types> constexpr const T&& get(const variant<Types...>&& v);
|
| 3547 |
```
|
| 3548 |
|
| 3549 |
+
*Mandates:* The type `T` occurs exactly once in `Types`.
|
|
|
|
| 3550 |
|
| 3551 |
*Effects:* If `v` holds a value of type `T`, returns a reference to that
|
| 3552 |
value. Otherwise, throws an exception of type `bad_variant_access`.
|
| 3553 |
|
| 3554 |
``` cpp
|
|
|
|
| 3558 |
template<size_t I, class... Types>
|
| 3559 |
constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...>>>
|
| 3560 |
get_if(const variant<Types...>* v) noexcept;
|
| 3561 |
```
|
| 3562 |
|
| 3563 |
+
*Mandates:* `I` < `sizeof...(Types)`.
|
| 3564 |
|
| 3565 |
*Returns:* A pointer to the value stored in the `variant`, if
|
| 3566 |
`v != nullptr` and `v->index() == I`. Otherwise, returns `nullptr`.
|
| 3567 |
|
| 3568 |
``` cpp
|
|
|
|
| 3572 |
template<class T, class... Types>
|
| 3573 |
constexpr add_pointer_t<const T>
|
| 3574 |
get_if(const variant<Types...>* v) noexcept;
|
| 3575 |
```
|
| 3576 |
|
| 3577 |
+
*Mandates:* The type `T` occurs exactly once in `Types`.
|
|
|
|
| 3578 |
|
| 3579 |
*Effects:* Equivalent to: `return get_if<`i`>(v);` with i being the
|
| 3580 |
+
zero-based index of `T` in `Types`.
|
| 3581 |
|
| 3582 |
### Relational operators <a id="variant.relops">[[variant.relops]]</a>
|
| 3583 |
|
| 3584 |
``` cpp
|
| 3585 |
template<class... Types>
|
| 3586 |
constexpr bool operator==(const variant<Types...>& v, const variant<Types...>& w);
|
| 3587 |
```
|
| 3588 |
|
| 3589 |
+
*Mandates:* `get<`i`>(v) == get<`i`>(w)` is a valid expression that is
|
| 3590 |
+
convertible to `bool`, for all i.
|
| 3591 |
|
| 3592 |
*Returns:* If `v.index() != w.index()`, `false`; otherwise if
|
| 3593 |
`v.valueless_by_exception()`, `true`; otherwise
|
| 3594 |
`get<`i`>(v) == get<`i`>(w)` with i being `v.index()`.
|
| 3595 |
|
| 3596 |
``` cpp
|
| 3597 |
template<class... Types>
|
| 3598 |
constexpr bool operator!=(const variant<Types...>& v, const variant<Types...>& w);
|
| 3599 |
```
|
| 3600 |
|
| 3601 |
+
*Mandates:* `get<`i`>(v) != get<`i`>(w)` is a valid expression that is
|
| 3602 |
+
convertible to `bool`, for all i.
|
| 3603 |
|
| 3604 |
*Returns:* If `v.index() != w.index()`, `true`; otherwise if
|
| 3605 |
`v.valueless_by_exception()`, `false`; otherwise
|
| 3606 |
`get<`i`>(v) != get<`i`>(w)` with i being `v.index()`.
|
| 3607 |
|
| 3608 |
``` cpp
|
| 3609 |
template<class... Types>
|
| 3610 |
constexpr bool operator<(const variant<Types...>& v, const variant<Types...>& w);
|
| 3611 |
```
|
| 3612 |
|
| 3613 |
+
*Mandates:* `get<`i`>(v) < get<`i`>(w)` is a valid expression that is
|
| 3614 |
+
convertible to `bool`, for all i.
|
| 3615 |
|
| 3616 |
*Returns:* If `w.valueless_by_exception()`, `false`; otherwise if
|
| 3617 |
`v.valueless_by_exception()`, `true`; otherwise, if
|
| 3618 |
`v.index() < w.index()`, `true`; otherwise if `v.index() > w.index()`,
|
| 3619 |
`false`; otherwise `get<`i`>(v) < get<`i`>(w)` with i being `v.index()`.
|
|
|
|
| 3621 |
``` cpp
|
| 3622 |
template<class... Types>
|
| 3623 |
constexpr bool operator>(const variant<Types...>& v, const variant<Types...>& w);
|
| 3624 |
```
|
| 3625 |
|
| 3626 |
+
*Mandates:* `get<`i`>(v) > get<`i`>(w)` is a valid expression that is
|
| 3627 |
+
convertible to `bool`, for all i.
|
| 3628 |
|
| 3629 |
*Returns:* If `v.valueless_by_exception()`, `false`; otherwise if
|
| 3630 |
`w.valueless_by_exception()`, `true`; otherwise, if
|
| 3631 |
`v.index() > w.index()`, `true`; otherwise if `v.index() < w.index()`,
|
| 3632 |
`false`; otherwise `get<`i`>(v) > get<`i`>(w)` with i being `v.index()`.
|
|
|
|
| 3634 |
``` cpp
|
| 3635 |
template<class... Types>
|
| 3636 |
constexpr bool operator<=(const variant<Types...>& v, const variant<Types...>& w);
|
| 3637 |
```
|
| 3638 |
|
| 3639 |
+
*Mandates:* `get<`i`>(v) <= get<`i`>(w)` is a valid expression that is
|
| 3640 |
+
convertible to `bool`, for all i.
|
| 3641 |
|
| 3642 |
*Returns:* If `v.valueless_by_exception()`, `true`; otherwise if
|
| 3643 |
`w.valueless_by_exception()`, `false`; otherwise, if
|
| 3644 |
`v.index() < w.index()`, `true`; otherwise if `v.index() > w.index()`,
|
| 3645 |
`false`; otherwise `get<`i`>(v) <= get<`i`>(w)` with i being
|
|
|
|
| 3648 |
``` cpp
|
| 3649 |
template<class... Types>
|
| 3650 |
constexpr bool operator>=(const variant<Types...>& v, const variant<Types...>& w);
|
| 3651 |
```
|
| 3652 |
|
| 3653 |
+
*Mandates:* `get<`i`>(v) >= get<`i`>(w)` is a valid expression that is
|
| 3654 |
+
convertible to `bool`, for all i.
|
| 3655 |
|
| 3656 |
*Returns:* If `w.valueless_by_exception()`, `true`; otherwise if
|
| 3657 |
`v.valueless_by_exception()`, `false`; otherwise, if
|
| 3658 |
`v.index() > w.index()`, `true`; otherwise if `v.index() < w.index()`,
|
| 3659 |
`false`; otherwise `get<`i`>(v) >= get<`i`>(w)` with i being
|
| 3660 |
`v.index()`.
|
| 3661 |
|
| 3662 |
+
``` cpp
|
| 3663 |
+
template<class... Types> requires (three_way_comparable<Types> && ...)
|
| 3664 |
+
constexpr common_comparison_category_t<compare_three_way_result_t<Types>...>
|
| 3665 |
+
operator<=>(const variant<Types...>& v, const variant<Types...>& w);
|
| 3666 |
+
```
|
| 3667 |
+
|
| 3668 |
+
*Effects:* Equivalent to:
|
| 3669 |
+
|
| 3670 |
+
``` cpp
|
| 3671 |
+
if (v.valueless_by_exception() && w.valueless_by_exception())
|
| 3672 |
+
return strong_ordering::equal;
|
| 3673 |
+
if (v.valueless_by_exception()) return strong_ordering::less;
|
| 3674 |
+
if (w.valueless_by_exception()) return strong_ordering::greater;
|
| 3675 |
+
if (auto c = v.index() <=> w.index(); c != 0) return c;
|
| 3676 |
+
return get<i>(v) <=> get<i>(w);
|
| 3677 |
+
```
|
| 3678 |
+
|
| 3679 |
+
with i being `v.index()`.
|
| 3680 |
+
|
| 3681 |
### Visitation <a id="variant.visit">[[variant.visit]]</a>
|
| 3682 |
|
| 3683 |
``` cpp
|
| 3684 |
template<class Visitor, class... Variants>
|
| 3685 |
constexpr see below visit(Visitor&& vis, Variants&&... vars);
|
| 3686 |
+
template<class R, class Visitor, class... Variants>
|
| 3687 |
+
constexpr R visit(Visitor&& vis, Variants&&... vars);
|
| 3688 |
```
|
| 3689 |
|
| 3690 |
+
Let n be `sizeof...(Variants)`. Let `m` be a pack of n values of type
|
| 3691 |
+
`size_t`. Such a pack is called valid if 0 ≤
|
| 3692 |
+
`mᵢ` < `variant_size_v<remove_reference_t<Variantsᵢ``>>` for all
|
| 3693 |
+
0 ≤ i < n. For each valid pack `m`, let e(`m`) denote the expression:
|
| 3694 |
|
| 3695 |
+
``` cpp
|
| 3696 |
+
INVOKE(std::forward<Visitor>(vis), get<m>(std::forward<Variants>(vars))...) // see [func.require]
|
| 3697 |
+
```
|
| 3698 |
+
|
| 3699 |
+
for the first form and
|
| 3700 |
+
|
| 3701 |
+
``` cpp
|
| 3702 |
+
INVOKE<R>(std::forward<Visitor>(vis), get<m>(std::forward<Variants>(vars))...) // see [func.require]
|
| 3703 |
+
```
|
| 3704 |
+
|
| 3705 |
+
for the second form.
|
| 3706 |
+
|
| 3707 |
+
*Mandates:* For each valid pack `m`, e(`m`) is a valid expression. All
|
| 3708 |
+
such expressions are of the same type and value category.
|
| 3709 |
|
| 3710 |
+
*Returns:* e(`m`), where `m` is the pack for which `mᵢ` is
|
| 3711 |
+
`vars`ᵢ`.index()` for all 0 ≤ i < n. The return type is
|
| 3712 |
+
`decltype(`e(`m`)`)` for the first form.
|
| 3713 |
|
| 3714 |
*Throws:* `bad_variant_access` if any `variant` in `vars` is
|
| 3715 |
`valueless_by_exception()`.
|
| 3716 |
|
| 3717 |
+
*Complexity:* For n ≤ 1, the invocation of the callable object is
|
| 3718 |
+
implemented in constant time, i.e., for n = 1, it does not depend on the
|
| 3719 |
+
number of alternative types of `Variants₀`. For n > 1, the invocation of
|
| 3720 |
the callable object has no complexity requirements.
|
| 3721 |
|
| 3722 |
### Class `monostate` <a id="variant.monostate">[[variant.monostate]]</a>
|
| 3723 |
|
| 3724 |
``` cpp
|
|
|
|
| 3729 |
`variant` to make the `variant` type default constructible.
|
| 3730 |
|
| 3731 |
### `monostate` relational operators <a id="variant.monostate.relops">[[variant.monostate.relops]]</a>
|
| 3732 |
|
| 3733 |
``` cpp
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3734 |
constexpr bool operator==(monostate, monostate) noexcept { return true; }
|
| 3735 |
+
constexpr strong_ordering operator<=>(monostate, monostate) noexcept
|
| 3736 |
+
{ return strong_ordering::equal; }
|
| 3737 |
```
|
| 3738 |
|
| 3739 |
[*Note 1*: `monostate` objects have only a single state; they thus
|
| 3740 |
always compare equal. — *end note*]
|
| 3741 |
|
|
|
|
| 3744 |
``` cpp
|
| 3745 |
template<class... Types>
|
| 3746 |
void swap(variant<Types...>& v, variant<Types...>& w) noexcept(see below);
|
| 3747 |
```
|
| 3748 |
|
| 3749 |
+
*Constraints:*
|
| 3750 |
+
`is_move_constructible_v<``Tᵢ``> && is_swappable_v<``Tᵢ``>` is `true`
|
| 3751 |
+
for all i.
|
| 3752 |
+
|
| 3753 |
*Effects:* Equivalent to `v.swap(w)`.
|
| 3754 |
|
| 3755 |
+
*Remarks:* The expression inside `noexcept` is equivalent to
|
|
|
|
|
|
|
| 3756 |
`noexcept(v.swap(w))`.
|
| 3757 |
|
| 3758 |
### Class `bad_variant_access` <a id="variant.bad.access">[[variant.bad.access]]</a>
|
| 3759 |
|
| 3760 |
``` cpp
|
| 3761 |
class bad_variant_access : public exception {
|
| 3762 |
public:
|
| 3763 |
+
// see [exception] for the specification of the special member functions
|
| 3764 |
const char* what() const noexcept override;
|
| 3765 |
};
|
| 3766 |
```
|
| 3767 |
|
| 3768 |
Objects of type `bad_variant_access` are thrown to report invalid
|
| 3769 |
accesses to the value of a `variant` object.
|
| 3770 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3771 |
``` cpp
|
| 3772 |
const char* what() const noexcept override;
|
| 3773 |
```
|
| 3774 |
|
| 3775 |
*Returns:* An *implementation-defined* NTBS.
|
|
|
|
| 3778 |
|
| 3779 |
``` cpp
|
| 3780 |
template<class... Types> struct hash<variant<Types...>>;
|
| 3781 |
```
|
| 3782 |
|
| 3783 |
+
The specialization `hash<variant<Types...>>` is enabled [[unord.hash]]
|
| 3784 |
+
if and only if every specialization in `hash<remove_const_t<Types>>...`
|
| 3785 |
+
is enabled. The member functions are not guaranteed to be `noexcept`.
|
|
|
|
| 3786 |
|
| 3787 |
``` cpp
|
| 3788 |
template<> struct hash<monostate>;
|
| 3789 |
```
|
| 3790 |
|
| 3791 |
+
The specialization is enabled [[unord.hash]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3792 |
|
| 3793 |
## Storage for any type <a id="any">[[any]]</a>
|
| 3794 |
|
| 3795 |
+
This subclause describes components that C++ programs may use to perform
|
| 3796 |
operations on objects of a discriminated type.
|
| 3797 |
|
| 3798 |
[*Note 1*: The discriminated type may contain values of different types
|
| 3799 |
+
but does not attempt conversion between them, i.e., `5` is held strictly
|
| 3800 |
as an `int` and is not implicitly convertible either to `"5"` or to
|
| 3801 |
`5.0`. This indifference to interpretation but awareness of type
|
| 3802 |
effectively allows safe, generic containers of single values, with no
|
| 3803 |
scope for surprises from ambiguous conversions. — *end note*]
|
| 3804 |
|
| 3805 |
### Header `<any>` synopsis <a id="any.synop">[[any.synop]]</a>
|
| 3806 |
|
| 3807 |
``` cpp
|
| 3808 |
namespace std {
|
| 3809 |
+
// [any.bad.any.cast], class bad_any_cast
|
| 3810 |
class bad_any_cast;
|
| 3811 |
|
| 3812 |
// [any.class], class any
|
| 3813 |
class any;
|
| 3814 |
|
|
|
|
| 3832 |
template<class T>
|
| 3833 |
T* any_cast(any* operand) noexcept;
|
| 3834 |
}
|
| 3835 |
```
|
| 3836 |
|
| 3837 |
+
### Class `bad_any_cast` <a id="any.bad.any.cast">[[any.bad.any.cast]]</a>
|
| 3838 |
|
| 3839 |
``` cpp
|
| 3840 |
class bad_any_cast : public bad_cast {
|
| 3841 |
public:
|
| 3842 |
+
// see [exception] for the specification of the special member functions
|
| 3843 |
const char* what() const noexcept override;
|
| 3844 |
};
|
| 3845 |
```
|
| 3846 |
|
| 3847 |
+
Objects of type `bad_any_cast` are thrown by a failed `any_cast`
|
| 3848 |
+
[[any.nonmembers]].
|
| 3849 |
|
| 3850 |
``` cpp
|
| 3851 |
const char* what() const noexcept override;
|
| 3852 |
```
|
| 3853 |
|
| 3854 |
*Returns:* An *implementation-defined* NTBS.
|
| 3855 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3856 |
### Class `any` <a id="any.class">[[any.class]]</a>
|
| 3857 |
|
| 3858 |
``` cpp
|
| 3859 |
+
namespace std {
|
| 3860 |
class any {
|
| 3861 |
public:
|
| 3862 |
// [any.cons], construction and destruction
|
| 3863 |
constexpr any() noexcept;
|
| 3864 |
|
| 3865 |
any(const any& other);
|
| 3866 |
any(any&& other) noexcept;
|
| 3867 |
|
| 3868 |
+
template<class T>
|
| 3869 |
+
any(T&& value);
|
| 3870 |
|
| 3871 |
template<class T, class... Args>
|
| 3872 |
explicit any(in_place_type_t<T>, Args&&...);
|
| 3873 |
template<class T, class U, class... Args>
|
| 3874 |
explicit any(in_place_type_t<T>, initializer_list<U>, Args&&...);
|
|
|
|
| 3877 |
|
| 3878 |
// [any.assign], assignments
|
| 3879 |
any& operator=(const any& rhs);
|
| 3880 |
any& operator=(any&& rhs) noexcept;
|
| 3881 |
|
| 3882 |
+
template<class T>
|
| 3883 |
+
any& operator=(T&& rhs);
|
| 3884 |
|
| 3885 |
// [any.modifiers], modifiers
|
| 3886 |
template<class T, class... Args>
|
| 3887 |
decay_t<T>& emplace(Args&&...);
|
| 3888 |
template<class T, class U, class... Args>
|
|
|
|
| 3892 |
|
| 3893 |
// [any.observers], observers
|
| 3894 |
bool has_value() const noexcept;
|
| 3895 |
const type_info& type() const noexcept;
|
| 3896 |
};
|
| 3897 |
+
}
|
| 3898 |
```
|
| 3899 |
|
| 3900 |
+
An object of class `any` stores an instance of any type that meets the
|
| 3901 |
+
constructor requirements or it has no value, and this is referred to as
|
| 3902 |
+
the *state* of the class `any` object. The stored instance is called the
|
| 3903 |
+
*contained value*. Two states are equivalent if either they both have no
|
| 3904 |
+
value, or they both have a value and the contained values are
|
| 3905 |
equivalent.
|
| 3906 |
|
| 3907 |
The non-member `any_cast` functions provide type-safe access to the
|
| 3908 |
contained value.
|
| 3909 |
|
| 3910 |
Implementations should avoid the use of dynamically allocated memory for
|
| 3911 |
+
a small contained value. However, any such small-object optimization
|
| 3912 |
+
shall only be applied to types `T` for which
|
| 3913 |
+
`is_nothrow_move_constructible_v<T>` is `true`.
|
| 3914 |
|
| 3915 |
+
[*Example 1*: A contained value of type `int` could be stored in an
|
| 3916 |
+
internal buffer, not in separately-allocated memory. — *end example*]
|
|
|
|
|
|
|
|
|
|
| 3917 |
|
| 3918 |
#### Construction and destruction <a id="any.cons">[[any.cons]]</a>
|
| 3919 |
|
| 3920 |
``` cpp
|
| 3921 |
constexpr any() noexcept;
|
| 3922 |
```
|
| 3923 |
|
| 3924 |
+
*Ensures:* `has_value()` is `false`.
|
| 3925 |
|
| 3926 |
``` cpp
|
| 3927 |
any(const any& other);
|
| 3928 |
```
|
| 3929 |
|
| 3930 |
*Effects:* If `other.has_value()` is `false`, constructs an object that
|
| 3931 |
has no value. Otherwise, equivalent to
|
| 3932 |
+
`any(in_place_type<T>, any_cast<const T&>(other))` where `T` is the type
|
| 3933 |
+
of the contained value.
|
| 3934 |
|
| 3935 |
*Throws:* Any exceptions arising from calling the selected constructor
|
| 3936 |
for the contained value.
|
| 3937 |
|
| 3938 |
``` cpp
|
| 3939 |
any(any&& other) noexcept;
|
| 3940 |
```
|
| 3941 |
|
| 3942 |
*Effects:* If `other.has_value()` is `false`, constructs an object that
|
| 3943 |
has no value. Otherwise, constructs an object of type `any` that
|
| 3944 |
+
contains either the contained value of `other`, or contains an object of
|
| 3945 |
+
the same type constructed from the contained value of `other`
|
| 3946 |
+
considering that contained value as an rvalue.
|
|
|
|
|
|
|
|
|
|
| 3947 |
|
| 3948 |
``` cpp
|
| 3949 |
template<class T>
|
| 3950 |
any(T&& value);
|
| 3951 |
```
|
| 3952 |
|
| 3953 |
Let `VT` be `decay_t<T>`.
|
| 3954 |
|
| 3955 |
+
*Constraints:* `VT` is not the same type as `any`, `VT` is not a
|
| 3956 |
+
specialization of `in_place_type_t`, and `is_copy_constructible_v<VT>`
|
| 3957 |
+
is `true`.
|
| 3958 |
+
|
| 3959 |
+
*Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
|
| 3960 |
|
| 3961 |
*Effects:* Constructs an object of type `any` that contains an object of
|
| 3962 |
type `VT` direct-initialized with `std::forward<T>(value)`.
|
| 3963 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3964 |
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 3965 |
|
| 3966 |
``` cpp
|
| 3967 |
template<class T, class... Args>
|
| 3968 |
explicit any(in_place_type_t<T>, Args&&... args);
|
| 3969 |
```
|
| 3970 |
|
| 3971 |
Let `VT` be `decay_t<T>`.
|
| 3972 |
|
| 3973 |
+
*Constraints:* `is_copy_constructible_v<VT>` is `true` and
|
| 3974 |
+
`is_constructible_v<VT, Args...>` is `true`.
|
| 3975 |
+
|
| 3976 |
+
*Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
|
| 3977 |
|
| 3978 |
*Effects:* Initializes the contained value as if
|
| 3979 |
direct-non-list-initializing an object of type `VT` with the arguments
|
| 3980 |
`std::forward<Args>(args)...`.
|
| 3981 |
|
| 3982 |
+
*Ensures:* `*this` contains a value of type `VT`.
|
| 3983 |
|
| 3984 |
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 3985 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3986 |
``` cpp
|
| 3987 |
template<class T, class U, class... Args>
|
| 3988 |
explicit any(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
|
| 3989 |
```
|
| 3990 |
|
| 3991 |
Let `VT` be `decay_t<T>`.
|
| 3992 |
|
| 3993 |
+
*Constraints:* `is_copy_constructible_v<VT>` is `true` and
|
| 3994 |
+
`is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
|
| 3995 |
+
|
| 3996 |
+
*Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
|
| 3997 |
|
| 3998 |
*Effects:* Initializes the contained value as if
|
| 3999 |
direct-non-list-initializing an object of type `VT` with the arguments
|
| 4000 |
`il, std::forward<Args>(args)...`.
|
| 4001 |
|
| 4002 |
+
*Ensures:* `*this` contains a value.
|
| 4003 |
|
| 4004 |
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 4005 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4006 |
``` cpp
|
| 4007 |
~any();
|
| 4008 |
```
|
| 4009 |
|
| 4010 |
*Effects:* As if by `reset()`.
|
|
|
|
| 4029 |
|
| 4030 |
*Effects:* As if by `any(std::move(rhs)).swap(*this)`.
|
| 4031 |
|
| 4032 |
*Returns:* `*this`.
|
| 4033 |
|
| 4034 |
+
*Ensures:* The state of `*this` is equivalent to the original state of
|
| 4035 |
+
`rhs`.
|
|
|
|
| 4036 |
|
| 4037 |
``` cpp
|
| 4038 |
template<class T>
|
| 4039 |
any& operator=(T&& rhs);
|
| 4040 |
```
|
| 4041 |
|
| 4042 |
Let `VT` be `decay_t<T>`.
|
| 4043 |
|
| 4044 |
+
*Constraints:* `VT` is not the same type as `any` and
|
| 4045 |
+
`is_copy_constructible_v<VT>` is `true`.
|
| 4046 |
+
|
| 4047 |
+
*Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
|
| 4048 |
|
| 4049 |
*Effects:* Constructs an object `tmp` of type `any` that contains an
|
| 4050 |
object of type `VT` direct-initialized with `std::forward<T>(rhs)`, and
|
| 4051 |
`tmp.swap(*this)`. No effects if an exception is thrown.
|
| 4052 |
|
| 4053 |
*Returns:* `*this`.
|
| 4054 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4055 |
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 4056 |
|
| 4057 |
#### Modifiers <a id="any.modifiers">[[any.modifiers]]</a>
|
| 4058 |
|
| 4059 |
``` cpp
|
|
|
|
| 4061 |
decay_t<T>& emplace(Args&&... args);
|
| 4062 |
```
|
| 4063 |
|
| 4064 |
Let `VT` be `decay_t<T>`.
|
| 4065 |
|
| 4066 |
+
*Constraints:* `is_copy_constructible_v<VT>` is `true` and
|
| 4067 |
+
`is_constructible_v<VT, Args...>` is `true`.
|
| 4068 |
+
|
| 4069 |
+
*Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
|
| 4070 |
|
| 4071 |
*Effects:* Calls `reset()`. Then initializes the contained value as if
|
| 4072 |
direct-non-list-initializing an object of type `VT` with the arguments
|
| 4073 |
`std::forward<Args>(args)...`.
|
| 4074 |
|
| 4075 |
+
*Ensures:* `*this` contains a value.
|
| 4076 |
|
| 4077 |
*Returns:* A reference to the new contained value.
|
| 4078 |
|
| 4079 |
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 4080 |
|
| 4081 |
*Remarks:* If an exception is thrown during the call to `VT`’s
|
| 4082 |
constructor, `*this` does not contain a value, and any previously
|
| 4083 |
+
contained value has been destroyed.
|
|
|
|
|
|
|
| 4084 |
|
| 4085 |
``` cpp
|
| 4086 |
template<class T, class U, class... Args>
|
| 4087 |
decay_t<T>& emplace(initializer_list<U> il, Args&&... args);
|
| 4088 |
```
|
| 4089 |
|
| 4090 |
Let `VT` be `decay_t<T>`.
|
| 4091 |
|
| 4092 |
+
*Constraints:* `is_copy_constructible_v<VT>` is `true` and
|
| 4093 |
+
`is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
|
| 4094 |
+
|
| 4095 |
+
*Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
|
| 4096 |
|
| 4097 |
*Effects:* Calls `reset()`. Then initializes the contained value as if
|
| 4098 |
direct-non-list-initializing an object of type `VT` with the arguments
|
| 4099 |
`il, std::forward<Args>(args)...`.
|
| 4100 |
|
| 4101 |
+
*Ensures:* `*this` contains a value.
|
| 4102 |
|
| 4103 |
*Returns:* A reference to the new contained value.
|
| 4104 |
|
| 4105 |
*Throws:* Any exception thrown by the selected constructor of `VT`.
|
| 4106 |
|
| 4107 |
*Remarks:* If an exception is thrown during the call to `VT`’s
|
| 4108 |
constructor, `*this` does not contain a value, and any previously
|
| 4109 |
+
contained value has been destroyed.
|
|
|
|
|
|
|
| 4110 |
|
| 4111 |
``` cpp
|
| 4112 |
void reset() noexcept;
|
| 4113 |
```
|
| 4114 |
|
| 4115 |
*Effects:* If `has_value()` is `true`, destroys the contained value.
|
| 4116 |
|
| 4117 |
+
*Ensures:* `has_value()` is `false`.
|
| 4118 |
|
| 4119 |
``` cpp
|
| 4120 |
void swap(any& rhs) noexcept;
|
| 4121 |
```
|
| 4122 |
|
|
|
|
| 4144 |
|
| 4145 |
``` cpp
|
| 4146 |
void swap(any& x, any& y) noexcept;
|
| 4147 |
```
|
| 4148 |
|
| 4149 |
+
*Effects:* Equivalent to `x.swap(y)`.
|
| 4150 |
|
| 4151 |
``` cpp
|
| 4152 |
template<class T, class... Args>
|
| 4153 |
any make_any(Args&&... args);
|
| 4154 |
```
|
|
|
|
| 4171 |
T any_cast(any& operand);
|
| 4172 |
template<class T>
|
| 4173 |
T any_cast(any&& operand);
|
| 4174 |
```
|
| 4175 |
|
| 4176 |
+
Let `U` be the type `remove_cvref_t<T>`.
|
| 4177 |
|
| 4178 |
+
*Mandates:* For the first overload, `is_constructible_v<T, const U&>` is
|
| 4179 |
+
`true`. For the second overload, `is_constructible_v<T, U&>` is `true`.
|
| 4180 |
+
For the third overload, `is_constructible_v<T, U>` is `true`.
|
|
|
|
|
|
|
| 4181 |
|
| 4182 |
*Returns:* For the first and second overload,
|
| 4183 |
+
`static_cast<T>(*any_cast<U>(&operand))`. For the third overload,
|
| 4184 |
+
`static_cast<T>(std::move(*any_cast<U>(&operand)))`.
|
| 4185 |
|
| 4186 |
*Throws:* `bad_any_cast` if
|
| 4187 |
`operand.type() != typeid(remove_reference_t<T>)`.
|
| 4188 |
|
| 4189 |
[*Example 1*:
|
|
|
|
| 4208 |
|
| 4209 |
string cat("Meow");
|
| 4210 |
const any y(cat); // const y holds string
|
| 4211 |
assert(any_cast<const string&>(y) == cat);
|
| 4212 |
|
| 4213 |
+
any_cast<string&>(y); // error: cannot any_cast away const
|
|
|
|
| 4214 |
```
|
| 4215 |
|
| 4216 |
— *end example*]
|
| 4217 |
|
| 4218 |
``` cpp
|
|
|
|
| 4237 |
|
| 4238 |
## Bitsets <a id="bitset">[[bitset]]</a>
|
| 4239 |
|
| 4240 |
### Header `<bitset>` synopsis <a id="bitset.syn">[[bitset.syn]]</a>
|
| 4241 |
|
| 4242 |
+
The header `<bitset>` defines a class template and several related
|
| 4243 |
+
functions for representing and manipulating fixed-size sequences of
|
| 4244 |
+
bits.
|
| 4245 |
+
|
| 4246 |
``` cpp
|
| 4247 |
#include <string>
|
| 4248 |
+
#include <iosfwd> // for istream[istream.syn], ostream[ostream.syn], see [iosfwd.syn]
|
| 4249 |
|
| 4250 |
namespace std {
|
| 4251 |
template<size_t N> class bitset;
|
| 4252 |
|
| 4253 |
// [bitset.operators], bitset operators
|
|
|
|
| 4264 |
basic_ostream<charT, traits>&
|
| 4265 |
operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
|
| 4266 |
}
|
| 4267 |
```
|
| 4268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4269 |
### Class template `bitset` <a id="template.bitset">[[template.bitset]]</a>
|
| 4270 |
|
| 4271 |
``` cpp
|
| 4272 |
namespace std {
|
| 4273 |
template<size_t N> class bitset {
|
| 4274 |
public:
|
| 4275 |
+
// bit reference
|
| 4276 |
class reference {
|
| 4277 |
friend class bitset;
|
| 4278 |
reference() noexcept;
|
| 4279 |
+
|
| 4280 |
public:
|
| 4281 |
+
reference(const reference&) = default;
|
| 4282 |
+
~reference();
|
| 4283 |
reference& operator=(bool x) noexcept; // for b[i] = x;
|
| 4284 |
reference& operator=(const reference&) noexcept; // for b[i] = b[j];
|
| 4285 |
bool operator~() const noexcept; // flips the bit
|
| 4286 |
operator bool() const noexcept; // for x = b[i];
|
| 4287 |
reference& flip() noexcept; // for b[i].flip();
|
|
|
|
| 4292 |
constexpr bitset(unsigned long long val) noexcept;
|
| 4293 |
template<class charT, class traits, class Allocator>
|
| 4294 |
explicit bitset(
|
| 4295 |
const basic_string<charT, traits, Allocator>& str,
|
| 4296 |
typename basic_string<charT, traits, Allocator>::size_type pos = 0,
|
| 4297 |
+
typename basic_string<charT, traits, Allocator>::size_type n
|
| 4298 |
+
= basic_string<charT, traits, Allocator>::npos,
|
| 4299 |
charT zero = charT('0'),
|
| 4300 |
charT one = charT('1'));
|
| 4301 |
template<class charT>
|
| 4302 |
explicit bitset(
|
| 4303 |
const charT* str,
|
|
|
|
| 4317 |
bitset<N>& reset(size_t pos);
|
| 4318 |
bitset<N> operator~() const noexcept;
|
| 4319 |
bitset<N>& flip() noexcept;
|
| 4320 |
bitset<N>& flip(size_t pos);
|
| 4321 |
|
| 4322 |
+
// element access
|
| 4323 |
constexpr bool operator[](size_t pos) const; // for b[i];
|
| 4324 |
reference operator[](size_t pos); // for b[i];
|
| 4325 |
|
| 4326 |
unsigned long to_ulong() const;
|
| 4327 |
unsigned long long to_ullong() const;
|
|
|
|
| 4332 |
to_string(charT zero = charT('0'), charT one = charT('1')) const;
|
| 4333 |
|
| 4334 |
size_t count() const noexcept;
|
| 4335 |
constexpr size_t size() const noexcept;
|
| 4336 |
bool operator==(const bitset<N>& rhs) const noexcept;
|
|
|
|
| 4337 |
bool test(size_t pos) const;
|
| 4338 |
bool all() const noexcept;
|
| 4339 |
bool any() const noexcept;
|
| 4340 |
bool none() const noexcept;
|
| 4341 |
bitset<N> operator<<(size_t pos) const noexcept;
|
|
|
|
| 4361 |
|
| 4362 |
The functions described in this subclause can report three kinds of
|
| 4363 |
errors, each associated with a distinct exception:
|
| 4364 |
|
| 4365 |
- an *invalid-argument* error is associated with exceptions of type
|
| 4366 |
+
`invalid_argument` [[invalid.argument]];
|
| 4367 |
- an *out-of-range* error is associated with exceptions of type
|
| 4368 |
+
`out_of_range` [[out.of.range]];
|
| 4369 |
- an *overflow* error is associated with exceptions of type
|
| 4370 |
+
`overflow_error` [[overflow.error]].
|
| 4371 |
|
| 4372 |
+
#### Constructors <a id="bitset.cons">[[bitset.cons]]</a>
|
| 4373 |
|
| 4374 |
``` cpp
|
| 4375 |
constexpr bitset() noexcept;
|
| 4376 |
```
|
| 4377 |
|
| 4378 |
+
*Effects:* Initializes all bits in `*this` to zero.
|
|
|
|
| 4379 |
|
| 4380 |
``` cpp
|
| 4381 |
constexpr bitset(unsigned long long val) noexcept;
|
| 4382 |
```
|
| 4383 |
|
| 4384 |
+
*Effects:* Initializes the first `M` bit positions to the corresponding
|
| 4385 |
+
bit values in `val`. `M` is the smaller of `N` and the number of bits in
|
| 4386 |
+
the value representation [[basic.types]] of `unsigned long long`. If
|
| 4387 |
+
`M < N`, the remaining bit positions are initialized to zero.
|
|
|
|
| 4388 |
|
| 4389 |
``` cpp
|
| 4390 |
template<class charT, class traits, class Allocator>
|
| 4391 |
+
explicit bitset(
|
| 4392 |
+
const basic_string<charT, traits, Allocator>& str,
|
| 4393 |
typename basic_string<charT, traits, Allocator>::size_type pos = 0,
|
| 4394 |
+
typename basic_string<charT, traits, Allocator>::size_type n
|
| 4395 |
+
= basic_string<charT, traits, Allocator>::npos,
|
| 4396 |
+
charT zero = charT('0'),
|
| 4397 |
+
charT one = charT('1'));
|
| 4398 |
```
|
| 4399 |
|
|
|
|
|
|
|
|
|
|
| 4400 |
*Effects:* Determines the effective length `rlen` of the initializing
|
| 4401 |
+
string as the smaller of `n` and `str.size() - pos`. Initializes the
|
| 4402 |
+
first `M` bit positions to values determined from the corresponding
|
| 4403 |
+
characters in the string `str`. `M` is the smaller of `N` and `rlen`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4404 |
|
| 4405 |
An element of the constructed object has value zero if the corresponding
|
| 4406 |
character in `str`, beginning at position `pos`, is `zero`. Otherwise,
|
| 4407 |
the element has the value one. Character position `pos + M - 1`
|
| 4408 |
corresponds to bit position zero. Subsequent decreasing character
|
| 4409 |
positions correspond to increasing bit positions.
|
| 4410 |
|
| 4411 |
If `M < N`, remaining bit positions are initialized to zero.
|
| 4412 |
|
| 4413 |
+
The function uses `traits::eq` to compare the character values.
|
| 4414 |
+
|
| 4415 |
+
*Throws:* `out_of_range` if `pos > str.size()` or `invalid_argument` if
|
| 4416 |
+
any of the `rlen` characters in `str` beginning at position `pos` is
|
| 4417 |
+
other than `zero` or `one`.
|
| 4418 |
+
|
| 4419 |
``` cpp
|
| 4420 |
template<class charT>
|
| 4421 |
explicit bitset(
|
| 4422 |
const charT* str,
|
| 4423 |
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
|
| 4424 |
+
charT zero = charT('0'),
|
| 4425 |
+
charT one = charT('1'));
|
| 4426 |
```
|
| 4427 |
|
| 4428 |
+
*Effects:* As if by:
|
| 4429 |
|
| 4430 |
``` cpp
|
| 4431 |
+
bitset(n == basic_string<charT>::npos
|
|
|
|
| 4432 |
? basic_string<charT>(str)
|
| 4433 |
: basic_string<charT>(str, n),
|
| 4434 |
0, n, zero, one)
|
| 4435 |
```
|
| 4436 |
|
| 4437 |
+
#### Members <a id="bitset.members">[[bitset.members]]</a>
|
| 4438 |
|
| 4439 |
``` cpp
|
| 4440 |
bitset<N>& operator&=(const bitset<N>& rhs) noexcept;
|
| 4441 |
```
|
| 4442 |
|
|
|
|
| 4499 |
|
| 4500 |
``` cpp
|
| 4501 |
bitset<N>& set(size_t pos, bool val = true);
|
| 4502 |
```
|
| 4503 |
|
|
|
|
|
|
|
|
|
|
| 4504 |
*Effects:* Stores a new value in the bit at position `pos` in `*this`.
|
| 4505 |
+
If `val` is `true`, the stored value is one, otherwise it is zero.
|
| 4506 |
|
| 4507 |
*Returns:* `*this`.
|
| 4508 |
|
| 4509 |
+
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 4510 |
+
position.
|
| 4511 |
+
|
| 4512 |
``` cpp
|
| 4513 |
bitset<N>& reset() noexcept;
|
| 4514 |
```
|
| 4515 |
|
| 4516 |
*Effects:* Resets all bits in `*this`.
|
|
|
|
| 4519 |
|
| 4520 |
``` cpp
|
| 4521 |
bitset<N>& reset(size_t pos);
|
| 4522 |
```
|
| 4523 |
|
|
|
|
|
|
|
|
|
|
| 4524 |
*Effects:* Resets the bit at position `pos` in `*this`.
|
| 4525 |
|
| 4526 |
*Returns:* `*this`.
|
| 4527 |
|
| 4528 |
+
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 4529 |
+
position.
|
| 4530 |
+
|
| 4531 |
``` cpp
|
| 4532 |
bitset<N> operator~() const noexcept;
|
| 4533 |
```
|
| 4534 |
|
| 4535 |
*Effects:* Constructs an object `x` of class `bitset<N>` and initializes
|
|
|
|
| 4547 |
|
| 4548 |
``` cpp
|
| 4549 |
bitset<N>& flip(size_t pos);
|
| 4550 |
```
|
| 4551 |
|
|
|
|
|
|
|
|
|
|
| 4552 |
*Effects:* Toggles the bit at position `pos` in `*this`.
|
| 4553 |
|
| 4554 |
*Returns:* `*this`.
|
| 4555 |
|
| 4556 |
+
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 4557 |
+
position.
|
| 4558 |
+
|
| 4559 |
``` cpp
|
| 4560 |
unsigned long to_ulong() const;
|
| 4561 |
```
|
| 4562 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4563 |
*Returns:* `x`.
|
| 4564 |
|
| 4565 |
+
*Throws:* `overflow_error` if the integral value `x` corresponding to
|
| 4566 |
+
the bits in `*this` cannot be represented as type `unsigned long`.
|
| 4567 |
+
|
| 4568 |
``` cpp
|
| 4569 |
unsigned long long to_ullong() const;
|
| 4570 |
```
|
| 4571 |
|
| 4572 |
+
*Returns:* `x`.
|
| 4573 |
+
|
| 4574 |
*Throws:* `overflow_error` if the integral value `x` corresponding to
|
| 4575 |
the bits in `*this` cannot be represented as type `unsigned long long`.
|
| 4576 |
|
|
|
|
|
|
|
| 4577 |
``` cpp
|
| 4578 |
template<class charT = char,
|
| 4579 |
class traits = char_traits<charT>,
|
| 4580 |
class Allocator = allocator<charT>>
|
| 4581 |
basic_string<charT, traits, Allocator>
|
|
|
|
| 4609 |
```
|
| 4610 |
|
| 4611 |
*Returns:* `true` if the value of each bit in `*this` equals the value
|
| 4612 |
of the corresponding bit in `rhs`.
|
| 4613 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4614 |
``` cpp
|
| 4615 |
bool test(size_t pos) const;
|
| 4616 |
```
|
| 4617 |
|
|
|
|
|
|
|
|
|
|
| 4618 |
*Returns:* `true` if the bit at position `pos` in `*this` has the value
|
| 4619 |
one.
|
| 4620 |
|
| 4621 |
+
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 4622 |
+
position.
|
| 4623 |
+
|
| 4624 |
``` cpp
|
| 4625 |
bool all() const noexcept;
|
| 4626 |
```
|
| 4627 |
|
| 4628 |
*Returns:* `count() == size()`.
|
|
|
|
| 4653 |
|
| 4654 |
``` cpp
|
| 4655 |
constexpr bool operator[](size_t pos) const;
|
| 4656 |
```
|
| 4657 |
|
| 4658 |
+
*Preconditions:* `pos` is valid.
|
| 4659 |
|
| 4660 |
*Returns:* `true` if the bit at position `pos` in `*this` has the value
|
| 4661 |
one, otherwise `false`.
|
| 4662 |
|
| 4663 |
*Throws:* Nothing.
|
| 4664 |
|
| 4665 |
``` cpp
|
| 4666 |
bitset<N>::reference operator[](size_t pos);
|
| 4667 |
```
|
| 4668 |
|
| 4669 |
+
*Preconditions:* `pos` is valid.
|
| 4670 |
|
| 4671 |
*Returns:* An object of type `bitset<N>::reference` such that
|
| 4672 |
`(*this)[pos] == this->test(pos)`, and such that `(*this)[pos] = val` is
|
| 4673 |
equivalent to `this->set(pos, val)`.
|
| 4674 |
|
| 4675 |
*Throws:* Nothing.
|
| 4676 |
|
| 4677 |
*Remarks:* For the purpose of determining the presence of a data
|
| 4678 |
+
race [[intro.multithread]], any access or update through the resulting
|
| 4679 |
+
reference potentially accesses or modifies, respectively, the entire
|
| 4680 |
+
underlying bitset.
|
| 4681 |
|
| 4682 |
### `bitset` hash support <a id="bitset.hash">[[bitset.hash]]</a>
|
| 4683 |
|
| 4684 |
``` cpp
|
| 4685 |
template<size_t N> struct hash<bitset<N>>;
|
| 4686 |
```
|
| 4687 |
|
| 4688 |
+
The specialization is enabled [[unord.hash]].
|
| 4689 |
|
| 4690 |
### `bitset` operators <a id="bitset.operators">[[bitset.operators]]</a>
|
| 4691 |
|
| 4692 |
``` cpp
|
| 4693 |
bitset<N> operator&(const bitset<N>& lhs, const bitset<N>& rhs) noexcept;
|
|
|
|
| 4711 |
template<class charT, class traits, size_t N>
|
| 4712 |
basic_istream<charT, traits>&
|
| 4713 |
operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
|
| 4714 |
```
|
| 4715 |
|
| 4716 |
+
A formatted input function [[istream.formatted]].
|
| 4717 |
|
| 4718 |
*Effects:* Extracts up to `N` characters from `is`. Stores these
|
| 4719 |
characters in a temporary object `str` of type
|
| 4720 |
`basic_string<charT, traits>`, then evaluates the expression
|
| 4721 |
`x = bitset<N>(str)`. Characters are extracted and stored until any of
|
|
|
|
| 4724 |
- `N` characters have been extracted and stored;
|
| 4725 |
- end-of-file occurs on the input sequence;
|
| 4726 |
- the next input character is neither `is.widen(’0’)` nor
|
| 4727 |
`is.widen(’1’)` (in which case the input character is not extracted).
|
| 4728 |
|
| 4729 |
+
If `N > 0` and no characters are stored in `str`, calls
|
| 4730 |
+
`is.setstate(ios_base::failbit)` (which may throw `ios_base::failure`
|
| 4731 |
+
[[iostate.flags]]).
|
| 4732 |
|
| 4733 |
*Returns:* `is`.
|
| 4734 |
|
| 4735 |
``` cpp
|
| 4736 |
template<class charT, class traits, size_t N>
|
|
|
|
| 4750 |
|
| 4751 |
## Memory <a id="memory">[[memory]]</a>
|
| 4752 |
|
| 4753 |
### In general <a id="memory.general">[[memory.general]]</a>
|
| 4754 |
|
| 4755 |
+
Subclause [[memory]] describes the contents of the header `<memory>`
|
| 4756 |
+
and some of the contents of the header `<cstdlib>`.
|
|
|
|
| 4757 |
|
| 4758 |
### Header `<memory>` synopsis <a id="memory.syn">[[memory.syn]]</a>
|
| 4759 |
|
| 4760 |
The header `<memory>` defines several types and function templates that
|
| 4761 |
describe properties of pointers and pointer-like types, manage memory
|
| 4762 |
for containers and other template types, destroy objects, and construct
|
| 4763 |
+
objects in uninitialized memory buffers ([[pointer.traits]]–
|
| 4764 |
+
[[specialized.addressof]] and [[specialized.algorithms]]). The header
|
| 4765 |
+
also defines the templates `unique_ptr`, `shared_ptr`, `weak_ptr`, and
|
| 4766 |
+
various function templates that operate on objects of these types
|
| 4767 |
+
[[smartptr]].
|
| 4768 |
|
| 4769 |
``` cpp
|
| 4770 |
+
#include <compare> // see [compare.syn]
|
| 4771 |
+
|
| 4772 |
namespace std {
|
| 4773 |
// [pointer.traits], pointer traits
|
| 4774 |
template<class Ptr> struct pointer_traits;
|
| 4775 |
template<class T> struct pointer_traits<T*>;
|
| 4776 |
|
| 4777 |
+
// [pointer.conversion], pointer conversion
|
| 4778 |
+
template<class T>
|
| 4779 |
+
constexpr T* to_address(T* p) noexcept;
|
| 4780 |
+
template<class Ptr>
|
| 4781 |
+
constexpr auto to_address(const Ptr& p) noexcept;
|
| 4782 |
+
|
| 4783 |
+
// [util.dynamic.safety], pointer safety%
|
| 4784 |
+
%
|
| 4785 |
+
{pointer_safety{pointer_safety{pointer_safety}
|
| 4786 |
enum class pointer_safety { relaxed, preferred, strict };
|
| 4787 |
void declare_reachable(void* p);
|
| 4788 |
+
template<class T>
|
| 4789 |
+
T* undeclare_reachable(T* p);
|
| 4790 |
void declare_no_pointers(char* p, size_t n);
|
| 4791 |
void undeclare_no_pointers(char* p, size_t n);
|
| 4792 |
pointer_safety get_pointer_safety() noexcept;
|
| 4793 |
|
| 4794 |
+
// [ptr.align], pointer alignment
|
| 4795 |
void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
|
| 4796 |
+
template<size_t N, class T>
|
| 4797 |
+
[[nodiscard]] constexpr T* assume_aligned(T* ptr);
|
| 4798 |
|
| 4799 |
// [allocator.tag], allocator argument tag
|
| 4800 |
struct allocator_arg_t { explicit allocator_arg_t() = default; };
|
| 4801 |
inline constexpr allocator_arg_t allocator_arg{};
|
| 4802 |
|
| 4803 |
// [allocator.uses], uses_allocator
|
| 4804 |
template<class T, class Alloc> struct uses_allocator;
|
| 4805 |
|
| 4806 |
+
// [allocator.uses.trait], uses_allocator
|
| 4807 |
+
template<class T, class Alloc>
|
| 4808 |
+
inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
|
| 4809 |
+
|
| 4810 |
+
// [allocator.uses.construction], uses-allocator construction
|
| 4811 |
+
template<class T, class Alloc, class... Args>
|
| 4812 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
|
| 4813 |
+
Args&&... args) noexcept -> see below;
|
| 4814 |
+
template<class T, class Alloc, class Tuple1, class Tuple2>
|
| 4815 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t,
|
| 4816 |
+
Tuple1&& x, Tuple2&& y)
|
| 4817 |
+
noexcept -> see below;
|
| 4818 |
+
template<class T, class Alloc>
|
| 4819 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept -> see below;
|
| 4820 |
+
template<class T, class Alloc, class U, class V>
|
| 4821 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
|
| 4822 |
+
U&& u, V&& v) noexcept -> see below;
|
| 4823 |
+
template<class T, class Alloc, class U, class V>
|
| 4824 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
|
| 4825 |
+
const pair<U,V>& pr) noexcept -> see below;
|
| 4826 |
+
template<class T, class Alloc, class U, class V>
|
| 4827 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
|
| 4828 |
+
pair<U,V>&& pr) noexcept -> see below;
|
| 4829 |
+
template<class T, class Alloc, class... Args>
|
| 4830 |
+
constexpr T make_obj_using_allocator(const Alloc& alloc, Args&&... args);
|
| 4831 |
+
template<class T, class Alloc, class... Args>
|
| 4832 |
+
constexpr T* uninitialized_construct_using_allocator(T* p, const Alloc& alloc,
|
| 4833 |
+
Args&&... args);
|
| 4834 |
+
|
| 4835 |
// [allocator.traits], allocator traits
|
| 4836 |
template<class Alloc> struct allocator_traits;
|
| 4837 |
|
| 4838 |
// [default.allocator], the default allocator
|
| 4839 |
template<class T> class allocator;
|
| 4840 |
template<class T, class U>
|
| 4841 |
+
constexpr bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
|
| 4842 |
+
|
| 4843 |
+
// [specialized.addressof], addressof
|
| 4844 |
+
template<class T>
|
| 4845 |
+
constexpr T* addressof(T& r) noexcept;
|
| 4846 |
+
template<class T>
|
| 4847 |
+
const T* addressof(const T&&) = delete;
|
| 4848 |
|
| 4849 |
// [specialized.algorithms], specialized algorithms
|
| 4850 |
+
// [special.mem.concepts], special memory concepts
|
| 4851 |
+
template<class I>
|
| 4852 |
+
concept no-throw-input-iterator = see below; // exposition only
|
| 4853 |
+
template<class I>
|
| 4854 |
+
concept no-throw-forward-iterator = see below; // exposition only
|
| 4855 |
+
template<class S, class I>
|
| 4856 |
+
concept no-throw-sentinel = see below; // exposition only
|
| 4857 |
+
template<class R>
|
| 4858 |
+
concept no-throw-input-range = see below; // exposition only
|
| 4859 |
+
template<class R>
|
| 4860 |
+
concept no-throw-forward-range = see below; // exposition only
|
| 4861 |
+
|
| 4862 |
+
template<class NoThrowForwardIterator>
|
| 4863 |
+
void uninitialized_default_construct(NoThrowForwardIterator first,
|
| 4864 |
+
NoThrowForwardIterator last);
|
| 4865 |
+
template<class ExecutionPolicy, class NoThrowForwardIterator>
|
| 4866 |
void uninitialized_default_construct(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 4867 |
+
NoThrowForwardIterator first,
|
| 4868 |
+
NoThrowForwardIterator last);
|
| 4869 |
+
template<class NoThrowForwardIterator, class Size>
|
| 4870 |
+
NoThrowForwardIterator
|
| 4871 |
+
uninitialized_default_construct_n(NoThrowForwardIterator first, Size n);
|
| 4872 |
+
template<class ExecutionPolicy, class NoThrowForwardIterator, class Size>
|
| 4873 |
+
NoThrowForwardIterator
|
| 4874 |
+
uninitialized_default_construct_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 4875 |
+
NoThrowForwardIterator first, Size n);
|
| 4876 |
+
|
| 4877 |
+
namespace ranges {
|
| 4878 |
+
template<no-throw-forward-iterator I, no-throw-sentinel<I> S>
|
| 4879 |
+
requires default_initializable<iter_value_t<I>>
|
| 4880 |
+
I uninitialized_default_construct(I first, S last);
|
| 4881 |
+
template<no-throw-forward-range R>
|
| 4882 |
+
requires default_initializable<range_value_t<R>>
|
| 4883 |
+
borrowed_iterator_t<R> uninitialized_default_construct(R&& r);
|
| 4884 |
+
|
| 4885 |
+
template<no-throw-forward-iterator I>
|
| 4886 |
+
requires default_initializable<iter_value_t<I>>
|
| 4887 |
+
I uninitialized_default_construct_n(I first, iter_difference_t<I> n);
|
| 4888 |
+
}
|
| 4889 |
+
|
| 4890 |
+
template<class NoThrowForwardIterator>
|
| 4891 |
+
void uninitialized_value_construct(NoThrowForwardIterator first,
|
| 4892 |
+
NoThrowForwardIterator last);
|
| 4893 |
+
template<class ExecutionPolicy, class NoThrowForwardIterator>
|
| 4894 |
void uninitialized_value_construct(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 4895 |
+
NoThrowForwardIterator first,
|
| 4896 |
+
NoThrowForwardIterator last);
|
| 4897 |
+
template<class NoThrowForwardIterator, class Size>
|
| 4898 |
+
NoThrowForwardIterator
|
| 4899 |
+
uninitialized_value_construct_n(NoThrowForwardIterator first, Size n);
|
| 4900 |
+
template<class ExecutionPolicy, class NoThrowForwardIterator, class Size>
|
| 4901 |
+
NoThrowForwardIterator
|
| 4902 |
+
uninitialized_value_construct_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 4903 |
+
NoThrowForwardIterator first, Size n);
|
| 4904 |
+
|
| 4905 |
+
namespace ranges {
|
| 4906 |
+
template<no-throw-forward-iterator I, no-throw-sentinel<I> S>
|
| 4907 |
+
requires default_initializable<iter_value_t<I>>
|
| 4908 |
+
I uninitialized_value_construct(I first, S last);
|
| 4909 |
+
template<no-throw-forward-range R>
|
| 4910 |
+
requires default_initializable<range_value_t<R>>
|
| 4911 |
+
borrowed_iterator_t<R> uninitialized_value_construct(R&& r);
|
| 4912 |
+
|
| 4913 |
+
template<no-throw-forward-iterator I>
|
| 4914 |
+
requires default_initializable<iter_value_t<I>>
|
| 4915 |
+
I uninitialized_value_construct_n(I first, iter_difference_t<I> n);
|
| 4916 |
+
}
|
| 4917 |
+
|
| 4918 |
+
template<class InputIterator, class NoThrowForwardIterator>
|
| 4919 |
+
NoThrowForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
|
| 4920 |
+
NoThrowForwardIterator result);
|
| 4921 |
+
template<class ExecutionPolicy, class InputIterator, class NoThrowForwardIterator>
|
| 4922 |
+
NoThrowForwardIterator uninitialized_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 4923 |
InputIterator first, InputIterator last,
|
| 4924 |
+
NoThrowForwardIterator result);
|
| 4925 |
+
template<class InputIterator, class Size, class NoThrowForwardIterator>
|
| 4926 |
+
NoThrowForwardIterator uninitialized_copy_n(InputIterator first, Size n,
|
| 4927 |
+
NoThrowForwardIterator result);
|
| 4928 |
+
template<class ExecutionPolicy, class InputIterator, class Size, class NoThrowForwardIterator>
|
| 4929 |
+
NoThrowForwardIterator uninitialized_copy_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 4930 |
InputIterator first, Size n,
|
| 4931 |
+
NoThrowForwardIterator result);
|
| 4932 |
+
|
| 4933 |
+
namespace ranges {
|
| 4934 |
+
template<class I, class O>
|
| 4935 |
+
using uninitialized_copy_result = in_out_result<I, O>;
|
| 4936 |
+
template<input_iterator I, sentinel_for<I> S1,
|
| 4937 |
+
no-throw-forward-iterator O, no-throw-sentinel<O> S2>
|
| 4938 |
+
requires constructible_from<iter_value_t<O>, iter_reference_t<I>>
|
| 4939 |
+
uninitialized_copy_result<I, O>
|
| 4940 |
+
uninitialized_copy(I ifirst, S1 ilast, O ofirst, S2 olast);
|
| 4941 |
+
template<input_range IR, no-throw-forward-range OR>
|
| 4942 |
+
requires constructible_from<range_value_t<OR>, range_reference_t<IR>>
|
| 4943 |
+
uninitialized_copy_result<borrowed_iterator_t<IR>, borrowed_iterator_t<OR>>
|
| 4944 |
+
uninitialized_copy(IR&& in_range, OR&& out_range);
|
| 4945 |
+
|
| 4946 |
+
template<class I, class O>
|
| 4947 |
+
using uninitialized_copy_n_result = in_out_result<I, O>;
|
| 4948 |
+
template<input_iterator I, no-throw-forward-iterator O, no-throw-sentinel<O> S>
|
| 4949 |
+
requires constructible_from<iter_value_t<O>, iter_reference_t<I>>
|
| 4950 |
+
uninitialized_copy_n_result<I, O>
|
| 4951 |
+
uninitialized_copy_n(I ifirst, iter_difference_t<I> n, O ofirst, S olast);
|
| 4952 |
+
}
|
| 4953 |
+
|
| 4954 |
+
template<class InputIterator, class NoThrowForwardIterator>
|
| 4955 |
+
NoThrowForwardIterator uninitialized_move(InputIterator first, InputIterator last,
|
| 4956 |
+
NoThrowForwardIterator result);
|
| 4957 |
+
template<class ExecutionPolicy, class InputIterator, class NoThrowForwardIterator>
|
| 4958 |
+
NoThrowForwardIterator uninitialized_move(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 4959 |
InputIterator first, InputIterator last,
|
| 4960 |
+
NoThrowForwardIterator result);
|
| 4961 |
+
template<class InputIterator, class Size, class NoThrowForwardIterator>
|
| 4962 |
+
pair<InputIterator, NoThrowForwardIterator>
|
| 4963 |
+
uninitialized_move_n(InputIterator first, Size n, NoThrowForwardIterator result);
|
| 4964 |
+
template<class ExecutionPolicy, class InputIterator, class Size, class NoThrowForwardIterator>
|
| 4965 |
+
pair<InputIterator, NoThrowForwardIterator>
|
| 4966 |
uninitialized_move_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 4967 |
+
InputIterator first, Size n, NoThrowForwardIterator result);
|
| 4968 |
+
|
| 4969 |
+
namespace ranges {
|
| 4970 |
+
template<class I, class O>
|
| 4971 |
+
using uninitialized_move_result = in_out_result<I, O>;
|
| 4972 |
+
template<input_iterator I, sentinel_for<I> S1,
|
| 4973 |
+
no-throw-forward-iterator O, no-throw-sentinel<O> S2>
|
| 4974 |
+
requires constructible_from<iter_value_t<O>, iter_rvalue_reference_t<I>>
|
| 4975 |
+
uninitialized_move_result<I, O>
|
| 4976 |
+
uninitialized_move(I ifirst, S1 ilast, O ofirst, S2 olast);
|
| 4977 |
+
template<input_range IR, no-throw-forward-range OR>
|
| 4978 |
+
requires constructible_from<range_value_t<OR>, range_rvalue_reference_t<IR>>
|
| 4979 |
+
uninitialized_move_result<borrowed_iterator_t<IR>, borrowed_iterator_t<OR>>
|
| 4980 |
+
uninitialized_move(IR&& in_range, OR&& out_range);
|
| 4981 |
+
|
| 4982 |
+
template<class I, class O>
|
| 4983 |
+
using uninitialized_move_n_result = in_out_result<I, O>;
|
| 4984 |
+
template<input_iterator I,
|
| 4985 |
+
no-throw-forward-iterator O, no-throw-sentinel<O> S>
|
| 4986 |
+
requires constructible_from<iter_value_t<O>, iter_rvalue_reference_t<I>>
|
| 4987 |
+
uninitialized_move_n_result<I, O>
|
| 4988 |
+
uninitialized_move_n(I ifirst, iter_difference_t<I> n, O ofirst, S olast);
|
| 4989 |
+
}
|
| 4990 |
+
|
| 4991 |
+
template<class NoThrowForwardIterator, class T>
|
| 4992 |
+
void uninitialized_fill(NoThrowForwardIterator first, NoThrowForwardIterator last,
|
| 4993 |
const T& x);
|
| 4994 |
+
template<class ExecutionPolicy, class NoThrowForwardIterator, class T>
|
| 4995 |
void uninitialized_fill(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 4996 |
+
NoThrowForwardIterator first, NoThrowForwardIterator last,
|
| 4997 |
const T& x);
|
| 4998 |
+
template<class NoThrowForwardIterator, class Size, class T>
|
| 4999 |
+
NoThrowForwardIterator
|
| 5000 |
+
uninitialized_fill_n(NoThrowForwardIterator first, Size n, const T& x);
|
| 5001 |
+
template<class ExecutionPolicy, class NoThrowForwardIterator, class Size, class T>
|
| 5002 |
+
NoThrowForwardIterator
|
| 5003 |
+
uninitialized_fill_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5004 |
+
NoThrowForwardIterator first, Size n, const T& x);
|
| 5005 |
+
|
| 5006 |
+
namespace ranges {
|
| 5007 |
+
template<no-throw-forward-iterator I, no-throw-sentinel<I> S, class T>
|
| 5008 |
+
requires constructible_from<iter_value_t<I>, const T&>
|
| 5009 |
+
I uninitialized_fill(I first, S last, const T& x);
|
| 5010 |
+
template<no-throw-forward-range R, class T>
|
| 5011 |
+
requires constructible_from<range_value_t<R>, const T&>
|
| 5012 |
+
borrowed_iterator_t<R> uninitialized_fill(R&& r, const T& x);
|
| 5013 |
+
|
| 5014 |
+
template<no-throw-forward-iterator I, class T>
|
| 5015 |
+
requires constructible_from<iter_value_t<I>, const T&>
|
| 5016 |
+
I uninitialized_fill_n(I first, iter_difference_t<I> n, const T& x);
|
| 5017 |
+
}
|
| 5018 |
+
|
| 5019 |
+
// [specialized.construct], construct_at
|
| 5020 |
+
template<class T, class... Args>
|
| 5021 |
+
constexpr T* construct_at(T* location, Args&&... args);
|
| 5022 |
+
|
| 5023 |
+
namespace ranges {
|
| 5024 |
+
template<class T, class... Args>
|
| 5025 |
+
constexpr T* construct_at(T* location, Args&&... args);
|
| 5026 |
+
}
|
| 5027 |
+
|
| 5028 |
+
// [specialized.destroy], destroy
|
| 5029 |
template<class T>
|
| 5030 |
+
constexpr void destroy_at(T* location);
|
| 5031 |
+
template<class NoThrowForwardIterator>
|
| 5032 |
+
constexpr void destroy(NoThrowForwardIterator first, NoThrowForwardIterator last);
|
| 5033 |
+
template<class ExecutionPolicy, class NoThrowForwardIterator>
|
| 5034 |
void destroy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5035 |
+
NoThrowForwardIterator first, NoThrowForwardIterator last);
|
| 5036 |
+
template<class NoThrowForwardIterator, class Size>
|
| 5037 |
+
constexpr NoThrowForwardIterator destroy_n(NoThrowForwardIterator first, Size n);
|
| 5038 |
+
template<class ExecutionPolicy, class NoThrowForwardIterator, class Size>
|
| 5039 |
+
NoThrowForwardIterator destroy_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 5040 |
+
NoThrowForwardIterator first, Size n);
|
| 5041 |
+
|
| 5042 |
+
namespace ranges {
|
| 5043 |
+
template<destructible T>
|
| 5044 |
+
constexpr void destroy_at(T* location) noexcept;
|
| 5045 |
+
|
| 5046 |
+
template<no-throw-input-iterator I, no-throw-sentinel<I> S>
|
| 5047 |
+
requires destructible<iter_value_t<I>>
|
| 5048 |
+
constexpr I destroy(I first, S last) noexcept;
|
| 5049 |
+
template<no-throw-input-range R>
|
| 5050 |
+
requires destructible<range_value_t<R>>
|
| 5051 |
+
constexpr borrowed_iterator_t<R> destroy(R&& r) noexcept;
|
| 5052 |
+
|
| 5053 |
+
template<no-throw-input-iterator I>
|
| 5054 |
+
requires destructible<iter_value_t<I>>
|
| 5055 |
+
constexpr I destroy_n(I first, iter_difference_t<I> n) noexcept;
|
| 5056 |
+
}
|
| 5057 |
|
| 5058 |
// [unique.ptr], class template unique_ptr
|
| 5059 |
template<class T> struct default_delete;
|
| 5060 |
template<class T> struct default_delete<T[]>;
|
| 5061 |
template<class T, class D = default_delete<T>> class unique_ptr;
|
| 5062 |
template<class T, class D> class unique_ptr<T[], D>;
|
| 5063 |
|
| 5064 |
+
template<class T, class... Args>
|
| 5065 |
+
unique_ptr<T> make_unique(Args&&... args); // T is not array
|
| 5066 |
+
template<class T>
|
| 5067 |
+
unique_ptr<T> make_unique(size_t n); // T is U[]
|
| 5068 |
+
template<class T, class... Args>
|
| 5069 |
+
unspecified make_unique(Args&&...) = delete; // T is U[N]
|
| 5070 |
|
| 5071 |
+
template<class T>
|
| 5072 |
+
unique_ptr<T> make_unique_for_overwrite(); // T is not array
|
| 5073 |
+
template<class T>
|
| 5074 |
+
unique_ptr<T> make_unique_for_overwrite(size_t n); // T is U[]
|
| 5075 |
+
template<class T, class... Args>
|
| 5076 |
+
unspecified make_unique_for_overwrite(Args&&...) = delete; // T is U[N]
|
| 5077 |
+
|
| 5078 |
+
template<class T, class D>
|
| 5079 |
+
void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
|
| 5080 |
|
| 5081 |
template<class T1, class D1, class T2, class D2>
|
| 5082 |
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
|
|
|
|
|
| 5083 |
template<class T1, class D1, class T2, class D2>
|
| 5084 |
bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
|
|
|
|
|
| 5085 |
template<class T1, class D1, class T2, class D2>
|
| 5086 |
bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 5087 |
+
template<class T1, class D1, class T2, class D2>
|
| 5088 |
+
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 5089 |
template<class T1, class D1, class T2, class D2>
|
| 5090 |
bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 5091 |
+
template<class T1, class D1, class T2, class D2>
|
| 5092 |
+
requires three_way_comparable_with<typename unique_ptr<T1, D1>::pointer,
|
| 5093 |
+
typename unique_ptr<T2, D2>::pointer>
|
| 5094 |
+
compare_three_way_result_t<typename unique_ptr<T1, D1>::pointer,
|
| 5095 |
+
typename unique_ptr<T2, D2>::pointer>
|
| 5096 |
+
operator<=>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 5097 |
|
| 5098 |
template<class T, class D>
|
| 5099 |
bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5100 |
template<class T, class D>
|
| 5101 |
bool operator<(const unique_ptr<T, D>& x, nullptr_t);
|
| 5102 |
template<class T, class D>
|
| 5103 |
bool operator<(nullptr_t, const unique_ptr<T, D>& y);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5104 |
template<class T, class D>
|
| 5105 |
bool operator>(const unique_ptr<T, D>& x, nullptr_t);
|
| 5106 |
template<class T, class D>
|
| 5107 |
bool operator>(nullptr_t, const unique_ptr<T, D>& y);
|
| 5108 |
+
template<class T, class D>
|
| 5109 |
+
bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
|
| 5110 |
+
template<class T, class D>
|
| 5111 |
+
bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
|
| 5112 |
template<class T, class D>
|
| 5113 |
bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
|
| 5114 |
template<class T, class D>
|
| 5115 |
bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
|
| 5116 |
+
template<class T, class D>
|
| 5117 |
+
requires three_way_comparable_with<typename unique_ptr<T, D>::pointer, nullptr_t>
|
| 5118 |
+
compare_three_way_result_t<typename unique_ptr<T, D>::pointer, nullptr_t>
|
| 5119 |
+
operator<=>(const unique_ptr<T, D>& x, nullptr_t);
|
| 5120 |
+
|
| 5121 |
+
template<class E, class T, class Y, class D>
|
| 5122 |
+
basic_ostream<E, T>& operator<<(basic_ostream<E, T>& os, const unique_ptr<Y, D>& p);
|
| 5123 |
|
| 5124 |
// [util.smartptr.weak.bad], class bad_weak_ptr
|
| 5125 |
class bad_weak_ptr;
|
| 5126 |
|
| 5127 |
// [util.smartptr.shared], class template shared_ptr
|
| 5128 |
template<class T> class shared_ptr;
|
| 5129 |
|
| 5130 |
// [util.smartptr.shared.create], shared_ptr creation
|
| 5131 |
template<class T, class... Args>
|
| 5132 |
+
shared_ptr<T> make_shared(Args&&... args); // T is not array
|
| 5133 |
template<class T, class A, class... Args>
|
| 5134 |
+
shared_ptr<T> allocate_shared(const A& a, Args&&... args); // T is not array
|
| 5135 |
+
|
| 5136 |
+
template<class T>
|
| 5137 |
+
shared_ptr<T> make_shared(size_t N); // T is U[]
|
| 5138 |
+
template<class T, class A>
|
| 5139 |
+
shared_ptr<T> allocate_shared(const A& a, size_t N); // T is U[]
|
| 5140 |
+
|
| 5141 |
+
template<class T>
|
| 5142 |
+
shared_ptr<T> make_shared(); // T is U[N]
|
| 5143 |
+
template<class T, class A>
|
| 5144 |
+
shared_ptr<T> allocate_shared(const A& a); // T is U[N]
|
| 5145 |
+
|
| 5146 |
+
template<class T>
|
| 5147 |
+
shared_ptr<T> make_shared(size_t N, const remove_extent_t<T>& u); // T is U[]
|
| 5148 |
+
template<class T, class A>
|
| 5149 |
+
shared_ptr<T> allocate_shared(const A& a, size_t N,
|
| 5150 |
+
const remove_extent_t<T>& u); // T is U[]
|
| 5151 |
+
|
| 5152 |
+
template<class T>
|
| 5153 |
+
shared_ptr<T> make_shared(const remove_extent_t<T>& u); // T is U[N]
|
| 5154 |
+
template<class T, class A>
|
| 5155 |
+
shared_ptr<T> allocate_shared(const A& a, const remove_extent_t<T>& u); // T is U[N]
|
| 5156 |
+
|
| 5157 |
+
template<class T>
|
| 5158 |
+
shared_ptr<T> make_shared_for_overwrite(); // T is not U[]
|
| 5159 |
+
template<class T, class A>
|
| 5160 |
+
shared_ptr<T> allocate_shared_for_overwrite(const A& a); // T is not U[]
|
| 5161 |
+
|
| 5162 |
+
template<class T>
|
| 5163 |
+
shared_ptr<T> make_shared_for_overwrite(size_t N); // T is U[]
|
| 5164 |
+
template<class T, class A>
|
| 5165 |
+
shared_ptr<T> allocate_shared_for_overwrite(const A& a, size_t N); // T is U[]
|
| 5166 |
|
| 5167 |
// [util.smartptr.shared.cmp], shared_ptr comparisons
|
| 5168 |
template<class T, class U>
|
| 5169 |
bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 5170 |
template<class T, class U>
|
| 5171 |
+
strong_ordering operator<=>(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5172 |
|
| 5173 |
template<class T>
|
| 5174 |
bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
|
| 5175 |
template<class T>
|
| 5176 |
+
strong_ordering operator<=>(const shared_ptr<T>& x, nullptr_t) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5177 |
|
| 5178 |
// [util.smartptr.shared.spec], shared_ptr specialized algorithms
|
| 5179 |
template<class T>
|
| 5180 |
void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
|
| 5181 |
|
| 5182 |
// [util.smartptr.shared.cast], shared_ptr casts
|
| 5183 |
template<class T, class U>
|
| 5184 |
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 5185 |
+
template<class T, class U>
|
| 5186 |
+
shared_ptr<T> static_pointer_cast(shared_ptr<U>&& r) noexcept;
|
| 5187 |
template<class T, class U>
|
| 5188 |
shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 5189 |
+
template<class T, class U>
|
| 5190 |
+
shared_ptr<T> dynamic_pointer_cast(shared_ptr<U>&& r) noexcept;
|
| 5191 |
template<class T, class U>
|
| 5192 |
shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 5193 |
+
template<class T, class U>
|
| 5194 |
+
shared_ptr<T> const_pointer_cast(shared_ptr<U>&& r) noexcept;
|
| 5195 |
+
template<class T, class U>
|
| 5196 |
+
shared_ptr<T> reinterpret_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 5197 |
+
template<class T, class U>
|
| 5198 |
+
shared_ptr<T> reinterpret_pointer_cast(shared_ptr<U>&& r) noexcept;
|
| 5199 |
|
| 5200 |
// [util.smartptr.getdeleter], shared_ptr get_deleter
|
| 5201 |
template<class D, class T>
|
| 5202 |
D* get_deleter(const shared_ptr<T>& p) noexcept;
|
| 5203 |
|
|
|
|
| 5215 |
template<class T = void> struct owner_less;
|
| 5216 |
|
| 5217 |
// [util.smartptr.enab], class template enable_shared_from_this
|
| 5218 |
template<class T> class enable_shared_from_this;
|
| 5219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5220 |
// [util.smartptr.hash], hash support
|
| 5221 |
template<class T> struct hash;
|
| 5222 |
template<class T, class D> struct hash<unique_ptr<T, D>>;
|
| 5223 |
template<class T> struct hash<shared_ptr<T>>;
|
| 5224 |
|
| 5225 |
+
// [util.smartptr.atomic], atomic smart pointers
|
| 5226 |
+
template<class T> struct atomic;
|
| 5227 |
+
template<class T> struct atomic<shared_ptr<T>>;
|
| 5228 |
+
template<class T> struct atomic<weak_ptr<T>>;
|
| 5229 |
}
|
| 5230 |
```
|
| 5231 |
|
| 5232 |
### Pointer traits <a id="pointer.traits">[[pointer.traits]]</a>
|
| 5233 |
|
|
|
|
| 5251 |
using element_type = T;
|
| 5252 |
using difference_type = ptrdiff_t;
|
| 5253 |
|
| 5254 |
template<class U> using rebind = U*;
|
| 5255 |
|
| 5256 |
+
static constexpr pointer pointer_to(see below r) noexcept;
|
| 5257 |
};
|
| 5258 |
}
|
| 5259 |
```
|
| 5260 |
|
| 5261 |
+
#### Member types <a id="pointer.traits.types">[[pointer.traits.types]]</a>
|
| 5262 |
|
| 5263 |
``` cpp
|
| 5264 |
using element_type = see below;
|
| 5265 |
```
|
| 5266 |
|
| 5267 |
*Type:* `Ptr::element_type` if the *qualified-id* `Ptr::element_type` is
|
| 5268 |
+
valid and denotes a type [[temp.deduct]]; otherwise, `T` if `Ptr` is a
|
| 5269 |
+
class template instantiation of the form `SomePointer<T, Args>`, where
|
| 5270 |
`Args` is zero or more type arguments; otherwise, the specialization is
|
| 5271 |
ill-formed.
|
| 5272 |
|
| 5273 |
``` cpp
|
| 5274 |
using difference_type = see below;
|
| 5275 |
```
|
| 5276 |
|
| 5277 |
*Type:* `Ptr::difference_type` if the *qualified-id*
|
| 5278 |
+
`Ptr::difference_type` is valid and denotes a type [[temp.deduct]];
|
| 5279 |
otherwise, `ptrdiff_t`.
|
| 5280 |
|
| 5281 |
``` cpp
|
| 5282 |
template<class U> using rebind = see below;
|
| 5283 |
```
|
| 5284 |
|
| 5285 |
*Alias template:* `Ptr::rebind<U>` if the *qualified-id*
|
| 5286 |
+
`Ptr::rebind<U>` is valid and denotes a type [[temp.deduct]]; otherwise,
|
| 5287 |
+
`SomePointer<U, Args>` if `Ptr` is a class template instantiation of the
|
| 5288 |
+
form `SomePointer<T, Args>`, where `Args` is zero or more type
|
| 5289 |
+
arguments; otherwise, the instantiation of `rebind` is ill-formed.
|
|
|
|
| 5290 |
|
| 5291 |
+
#### Member functions <a id="pointer.traits.functions">[[pointer.traits.functions]]</a>
|
| 5292 |
|
| 5293 |
``` cpp
|
| 5294 |
static pointer pointer_traits::pointer_to(see below r);
|
| 5295 |
+
static constexpr pointer pointer_traits<T*>::pointer_to(see below r) noexcept;
|
| 5296 |
```
|
| 5297 |
|
| 5298 |
+
*Mandates:* For the first member function, `Ptr::pointer_to(r)` is
|
| 5299 |
+
well-formed.
|
| 5300 |
+
|
| 5301 |
+
*Preconditions:* For the first member function, `Ptr::pointer_to(r)`
|
| 5302 |
+
returns a pointer to `r` through which indirection is valid.
|
| 5303 |
+
|
| 5304 |
+
*Returns:* The first member function returns `Ptr::pointer_to(r)`. The
|
| 5305 |
+
second member function returns `addressof(r)`.
|
| 5306 |
+
|
| 5307 |
*Remarks:* If `element_type` is cv `void`, the type of `r` is
|
| 5308 |
unspecified; otherwise, it is `element_type&`.
|
| 5309 |
|
| 5310 |
+
#### Optional members <a id="pointer.traits.optmem">[[pointer.traits.optmem]]</a>
|
| 5311 |
+
|
| 5312 |
+
Specializations of `pointer_traits` may define the member declared in
|
| 5313 |
+
this subclause to customize the behavior of the standard library.
|
| 5314 |
+
|
| 5315 |
+
``` cpp
|
| 5316 |
+
static element_type* to_address(pointer p) noexcept;
|
| 5317 |
+
```
|
| 5318 |
+
|
| 5319 |
+
*Returns:* A pointer of type `element_type*` that references the same
|
| 5320 |
+
location as the argument `p`.
|
| 5321 |
+
|
| 5322 |
+
[*Note 1*: This function should be the inverse of `pointer_to`. If
|
| 5323 |
+
defined, it customizes the behavior of the non-member function
|
| 5324 |
+
`to_address` [[pointer.conversion]]. — *end note*]
|
| 5325 |
+
|
| 5326 |
+
### Pointer conversion <a id="pointer.conversion">[[pointer.conversion]]</a>
|
| 5327 |
+
|
| 5328 |
+
``` cpp
|
| 5329 |
+
template<class T> constexpr T* to_address(T* p) noexcept;
|
| 5330 |
+
```
|
| 5331 |
+
|
| 5332 |
+
*Mandates:* `T` is not a function type.
|
| 5333 |
+
|
| 5334 |
+
*Returns:* `p`.
|
| 5335 |
+
|
| 5336 |
+
``` cpp
|
| 5337 |
+
template<class Ptr> constexpr auto to_address(const Ptr& p) noexcept;
|
| 5338 |
+
```
|
| 5339 |
+
|
| 5340 |
+
*Returns:* `pointer_traits<Ptr>::to_address(p)` if that expression is
|
| 5341 |
+
well-formed (see [[pointer.traits.optmem]]), otherwise
|
| 5342 |
+
`to_address(p.operator->())`.
|
| 5343 |
|
| 5344 |
### Pointer safety <a id="util.dynamic.safety">[[util.dynamic.safety]]</a>
|
| 5345 |
|
| 5346 |
A complete object is *declared reachable* while the number of calls to
|
| 5347 |
`declare_reachable` with an argument referencing the object exceeds the
|
|
|
|
| 5350 |
|
| 5351 |
``` cpp
|
| 5352 |
void declare_reachable(void* p);
|
| 5353 |
```
|
| 5354 |
|
| 5355 |
+
*Preconditions:* `p` is a safely-derived
|
| 5356 |
+
pointer [[basic.stc.dynamic.safety]] or a null pointer value.
|
| 5357 |
|
| 5358 |
*Effects:* If `p` is not null, the complete object referenced by `p` is
|
| 5359 |
+
subsequently declared reachable [[basic.stc.dynamic.safety]].
|
| 5360 |
|
| 5361 |
*Throws:* May throw `bad_alloc` if the system cannot allocate additional
|
| 5362 |
memory that may be required to track objects declared reachable.
|
| 5363 |
|
| 5364 |
``` cpp
|
| 5365 |
template<class T> T* undeclare_reachable(T* p);
|
| 5366 |
```
|
| 5367 |
|
| 5368 |
+
*Preconditions:* If `p` is not null, the complete object referenced by
|
| 5369 |
+
`p` has been previously declared reachable, and is live [[basic.life]]
|
| 5370 |
+
from the time of the call until the last `undeclare_reachable(p)` call
|
| 5371 |
+
on the object.
|
| 5372 |
|
| 5373 |
+
*Returns:* A safely derived copy of `p` which compares equal to `p`.
|
|
|
|
| 5374 |
|
| 5375 |
*Throws:* Nothing.
|
| 5376 |
|
| 5377 |
[*Note 1*: It is expected that calls to `declare_reachable(p)` will
|
| 5378 |
consume a small amount of memory in addition to that occupied by the
|
|
|
|
| 5382 |
|
| 5383 |
``` cpp
|
| 5384 |
void declare_no_pointers(char* p, size_t n);
|
| 5385 |
```
|
| 5386 |
|
| 5387 |
+
*Preconditions:* No bytes in the specified range are currently
|
| 5388 |
+
registered with `declare_no_pointers()`. If the specified range is in an
|
| 5389 |
+
allocated object, then it is entirely within a single allocated object.
|
| 5390 |
+
The object is live until the corresponding `undeclare_no_pointers()`
|
| 5391 |
call.
|
| 5392 |
|
| 5393 |
[*Note 2*: In a garbage-collecting implementation, the fact that a
|
| 5394 |
region in an object is registered with `declare_no_pointers()` should
|
| 5395 |
not prevent the object from being collected. — *end note*]
|
|
|
|
| 5410 |
|
| 5411 |
``` cpp
|
| 5412 |
void undeclare_no_pointers(char* p, size_t n);
|
| 5413 |
```
|
| 5414 |
|
| 5415 |
+
*Preconditions:* The same range has previously been passed to
|
| 5416 |
`declare_no_pointers()`.
|
| 5417 |
|
| 5418 |
*Effects:* Unregisters a range registered with `declare_no_pointers()`
|
| 5419 |
+
for destruction. It shall be called before the lifetime of the object
|
| 5420 |
ends.
|
| 5421 |
|
| 5422 |
*Throws:* Nothing.
|
| 5423 |
|
| 5424 |
``` cpp
|
| 5425 |
pointer_safety get_pointer_safety() noexcept;
|
| 5426 |
```
|
| 5427 |
|
| 5428 |
*Returns:* `pointer_safety::strict` if the implementation has strict
|
| 5429 |
+
pointer safety [[basic.stc.dynamic.safety]]. It is
|
| 5430 |
*implementation-defined* whether `get_pointer_safety` returns
|
| 5431 |
`pointer_safety::relaxed` or `pointer_safety::preferred` if the
|
| 5432 |
implementation has relaxed pointer safety.[^1]
|
| 5433 |
|
| 5434 |
+
### Pointer alignment <a id="ptr.align">[[ptr.align]]</a>
|
| 5435 |
|
| 5436 |
``` cpp
|
| 5437 |
void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
|
| 5438 |
```
|
| 5439 |
|
| 5440 |
+
*Preconditions:*
|
| 5441 |
+
|
| 5442 |
+
- `alignment` is a power of two
|
| 5443 |
+
- `ptr` represents the address of contiguous storage of at least `space`
|
| 5444 |
+
bytes
|
| 5445 |
+
|
| 5446 |
*Effects:* If it is possible to fit `size` bytes of storage aligned by
|
| 5447 |
`alignment` into the buffer pointed to by `ptr` with length `space`, the
|
| 5448 |
function updates `ptr` to represent the first possible address of such
|
| 5449 |
storage and decreases `space` by the number of bytes used for alignment.
|
| 5450 |
Otherwise, the function does nothing.
|
| 5451 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5452 |
*Returns:* A null pointer if the requested aligned buffer would not fit
|
| 5453 |
into the available space, otherwise the adjusted value of `ptr`.
|
| 5454 |
|
| 5455 |
[*Note 1*: The function updates its `ptr` and `space` arguments so that
|
| 5456 |
it can be called repeatedly with possibly different `alignment` and
|
| 5457 |
`size` arguments for the same buffer. — *end note*]
|
| 5458 |
|
| 5459 |
+
``` cpp
|
| 5460 |
+
template<size_t N, class T>
|
| 5461 |
+
[[nodiscard]] constexpr T* assume_aligned(T* ptr);
|
| 5462 |
+
```
|
| 5463 |
+
|
| 5464 |
+
*Mandates:* `N` is a power of two.
|
| 5465 |
+
|
| 5466 |
+
*Preconditions:* `ptr` points to an object `X` of a type
|
| 5467 |
+
similar [[conv.qual]] to `T`, where `X` has alignment `N`
|
| 5468 |
+
[[basic.align]].
|
| 5469 |
+
|
| 5470 |
+
*Returns:* `ptr`.
|
| 5471 |
+
|
| 5472 |
+
*Throws:* Nothing.
|
| 5473 |
+
|
| 5474 |
+
[*Note 2*: The alignment assumption on an object `X` expressed by a
|
| 5475 |
+
call to `assume_aligned` may result in generation of more efficient
|
| 5476 |
+
code. It is up to the program to ensure that the assumption actually
|
| 5477 |
+
holds. The call does not cause the compiler to verify or enforce this.
|
| 5478 |
+
An implementation might only make the assumption for those operations on
|
| 5479 |
+
`X` that access `X` through the pointer returned by
|
| 5480 |
+
`assume_aligned`. — *end note*]
|
| 5481 |
+
|
| 5482 |
### Allocator argument tag <a id="allocator.tag">[[allocator.tag]]</a>
|
| 5483 |
|
| 5484 |
``` cpp
|
| 5485 |
namespace std {
|
| 5486 |
struct allocator_arg_t { explicit allocator_arg_t() = default; };
|
| 5487 |
inline constexpr allocator_arg_t allocator_arg{};
|
| 5488 |
}
|
| 5489 |
```
|
| 5490 |
|
| 5491 |
+
The `allocator_arg_t` struct is an empty class type used as a unique
|
| 5492 |
type to disambiguate constructor and function overloading. Specifically,
|
| 5493 |
several types (see `tuple` [[tuple]]) have constructors with
|
| 5494 |
`allocator_arg_t` as the first argument, immediately followed by an
|
| 5495 |
+
argument of a type that meets the *Cpp17Allocator* requirements (
|
| 5496 |
+
[[cpp17.allocator]]).
|
| 5497 |
|
| 5498 |
### `uses_allocator` <a id="allocator.uses">[[allocator.uses]]</a>
|
| 5499 |
|
| 5500 |
#### `uses_allocator` trait <a id="allocator.uses.trait">[[allocator.uses.trait]]</a>
|
| 5501 |
|
|
|
|
| 5503 |
template<class T, class Alloc> struct uses_allocator;
|
| 5504 |
```
|
| 5505 |
|
| 5506 |
*Remarks:* Automatically detects whether `T` has a nested
|
| 5507 |
`allocator_type` that is convertible from `Alloc`. Meets the
|
| 5508 |
+
*Cpp17BinaryTypeTrait* requirements [[meta.rqmts]]. The implementation
|
| 5509 |
shall provide a definition that is derived from `true_type` if the
|
| 5510 |
*qualified-id* `T::allocator_type` is valid and denotes a
|
| 5511 |
+
type [[temp.deduct]] and
|
| 5512 |
`is_convertible_v<Alloc, T::allocator_type> != false`, otherwise it
|
| 5513 |
shall be derived from `false_type`. A program may specialize this
|
| 5514 |
+
template to derive from `true_type` for a program-defined type `T` that
|
| 5515 |
does not have a nested `allocator_type` but nonetheless can be
|
| 5516 |
constructed with an allocator where either:
|
| 5517 |
|
| 5518 |
- the first argument of a constructor has type `allocator_arg_t` and the
|
| 5519 |
second argument has type `Alloc` or
|
| 5520 |
- the last argument of a constructor has type `Alloc`.
|
| 5521 |
|
| 5522 |
#### Uses-allocator construction <a id="allocator.uses.construction">[[allocator.uses.construction]]</a>
|
| 5523 |
|
| 5524 |
+
*Uses-allocator construction* with allocator `alloc` and constructor
|
| 5525 |
+
arguments `args...` refers to the construction of an object of type `T`
|
| 5526 |
+
such that `alloc` is passed to the constructor of `T` if `T` uses an
|
| 5527 |
+
allocator type compatible with `alloc`. When applied to the construction
|
| 5528 |
+
of an object of type `T`, it is equivalent to initializing it with the
|
| 5529 |
+
value of the expression `make_obj_using_allocator<T>(alloc, args...)`,
|
| 5530 |
+
described below.
|
| 5531 |
+
|
| 5532 |
+
The following utility functions support three conventions for passing
|
| 5533 |
+
`alloc` to a constructor:
|
| 5534 |
+
|
| 5535 |
+
- If `T` does not use an allocator compatible with `alloc`, then `alloc`
|
| 5536 |
+
is ignored.
|
| 5537 |
+
- Otherwise, if `T` has a constructor invocable as
|
| 5538 |
+
`T(allocator_arg, alloc, args...)` (leading-allocator convention),
|
| 5539 |
+
then uses-allocator construction chooses this constructor form.
|
| 5540 |
+
- Otherwise, if `T` has a constructor invocable as `T(args..., alloc)`
|
| 5541 |
+
(trailing-allocator convention), then uses-allocator construction
|
| 5542 |
+
chooses this constructor form.
|
| 5543 |
+
|
| 5544 |
+
The `uses_allocator_construction_args` function template takes an
|
| 5545 |
+
allocator and argument list and produces (as a tuple) a new argument
|
| 5546 |
+
list matching one of the above conventions. Additionally, overloads are
|
| 5547 |
+
provided that treat specializations of `pair` such that uses-allocator
|
| 5548 |
+
construction is applied individually to the `first` and `second` data
|
| 5549 |
+
members. The `make_obj_using_allocator` and
|
| 5550 |
+
`uninitialized_construct_using_allocator` function templates apply the
|
| 5551 |
+
modified constructor arguments to construct an object of type `T` as a
|
| 5552 |
+
return value or in-place, respectively.
|
| 5553 |
+
|
| 5554 |
+
[*Note 1*: For `uses_allocator_construction_args` and
|
| 5555 |
+
`make_obj_using_allocator`, type `T` is not deduced and must therefore
|
| 5556 |
+
be specified explicitly by the caller. — *end note*]
|
| 5557 |
+
|
| 5558 |
+
``` cpp
|
| 5559 |
+
template<class T, class Alloc, class... Args>
|
| 5560 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
|
| 5561 |
+
Args&&... args) noexcept -> see below;
|
| 5562 |
+
```
|
| 5563 |
+
|
| 5564 |
+
*Constraints:* `T` is not a specialization of `pair`.
|
| 5565 |
+
|
| 5566 |
+
*Returns:* A `tuple` value determined as follows:
|
| 5567 |
+
|
| 5568 |
+
- If `uses_allocator_v<T, Alloc>` is `false` and
|
| 5569 |
+
`is_constructible_v<T, Args...>` is `true`, return
|
| 5570 |
+
`forward_as_tuple(std::forward<Args>(args)...)`.
|
| 5571 |
+
- Otherwise, if `uses_allocator_v<T, Alloc>` is `true` and
|
| 5572 |
+
`is_constructible_v<T, allocator_arg_t, const Alloc&, Args...>` is
|
| 5573 |
+
`true`, return
|
| 5574 |
+
``` cpp
|
| 5575 |
+
tuple<allocator_arg_t, const Alloc&, Args&&...>(
|
| 5576 |
+
allocator_arg, alloc, std::forward<Args>(args)...)
|
| 5577 |
+
```
|
| 5578 |
+
- Otherwise, if `uses_allocator_v<T, Alloc>` is `true` and
|
| 5579 |
+
`is_constructible_v<T, Args..., const Alloc&>` is `true`, return
|
| 5580 |
+
`forward_as_tuple(std::forward<Args>(args)..., alloc)`.
|
| 5581 |
+
- Otherwise, the program is ill-formed.
|
| 5582 |
+
|
| 5583 |
+
[*Note 1*: This definition prevents a silent failure to pass the
|
| 5584 |
+
allocator to a constructor of a type for which
|
| 5585 |
+
`uses_allocator_v<T, Alloc>` is `true`. — *end note*]
|
| 5586 |
+
|
| 5587 |
+
``` cpp
|
| 5588 |
+
template<class T, class Alloc, class Tuple1, class Tuple2>
|
| 5589 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t,
|
| 5590 |
+
Tuple1&& x, Tuple2&& y)
|
| 5591 |
+
noexcept -> see below;
|
| 5592 |
+
```
|
| 5593 |
+
|
| 5594 |
+
*Constraints:* `T` is a specialization of `pair`.
|
| 5595 |
+
|
| 5596 |
+
*Effects:* For `T` specified as `pair<T1, T2>`, equivalent to:
|
| 5597 |
+
|
| 5598 |
+
``` cpp
|
| 5599 |
+
return make_tuple(
|
| 5600 |
+
piecewise_construct,
|
| 5601 |
+
apply([&alloc](auto&&... args1) {
|
| 5602 |
+
return uses_allocator_construction_args<T1>(
|
| 5603 |
+
alloc, std::forward<decltype(args1)>(args1)...);
|
| 5604 |
+
}, std::forward<Tuple1>(x)),
|
| 5605 |
+
apply([&alloc](auto&&... args2) {
|
| 5606 |
+
return uses_allocator_construction_args<T2>(
|
| 5607 |
+
alloc, std::forward<decltype(args2)>(args2)...);
|
| 5608 |
+
}, std::forward<Tuple2>(y)));
|
| 5609 |
+
```
|
| 5610 |
+
|
| 5611 |
+
``` cpp
|
| 5612 |
+
template<class T, class Alloc>
|
| 5613 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept -> see below;
|
| 5614 |
+
```
|
| 5615 |
+
|
| 5616 |
+
*Constraints:* `T` is a specialization of `pair`.
|
| 5617 |
+
|
| 5618 |
+
*Effects:* Equivalent to:
|
| 5619 |
+
|
| 5620 |
+
``` cpp
|
| 5621 |
+
return uses_allocator_construction_args<T>(alloc, piecewise_construct,
|
| 5622 |
+
tuple<>{}, tuple<>{});
|
| 5623 |
+
```
|
| 5624 |
+
|
| 5625 |
+
``` cpp
|
| 5626 |
+
template<class T, class Alloc, class U, class V>
|
| 5627 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
|
| 5628 |
+
U&& u, V&& v) noexcept -> see below;
|
| 5629 |
+
```
|
| 5630 |
+
|
| 5631 |
+
*Constraints:* `T` is a specialization of `pair`.
|
| 5632 |
+
|
| 5633 |
+
*Effects:* Equivalent to:
|
| 5634 |
+
|
| 5635 |
+
``` cpp
|
| 5636 |
+
return uses_allocator_construction_args<T>(alloc, piecewise_construct,
|
| 5637 |
+
forward_as_tuple(std::forward<U>(u)),
|
| 5638 |
+
forward_as_tuple(std::forward<V>(v)));
|
| 5639 |
+
```
|
| 5640 |
+
|
| 5641 |
+
``` cpp
|
| 5642 |
+
template<class T, class Alloc, class U, class V>
|
| 5643 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
|
| 5644 |
+
const pair<U,V>& pr) noexcept -> see below;
|
| 5645 |
+
```
|
| 5646 |
+
|
| 5647 |
+
*Constraints:* `T` is a specialization of `pair`.
|
| 5648 |
+
|
| 5649 |
+
*Effects:* Equivalent to:
|
| 5650 |
+
|
| 5651 |
+
``` cpp
|
| 5652 |
+
return uses_allocator_construction_args<T>(alloc, piecewise_construct,
|
| 5653 |
+
forward_as_tuple(pr.first),
|
| 5654 |
+
forward_as_tuple(pr.second));
|
| 5655 |
+
```
|
| 5656 |
+
|
| 5657 |
+
``` cpp
|
| 5658 |
+
template<class T, class Alloc, class U, class V>
|
| 5659 |
+
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
|
| 5660 |
+
pair<U,V>&& pr) noexcept -> see below;
|
| 5661 |
+
```
|
| 5662 |
+
|
| 5663 |
+
*Constraints:* `T` is a specialization of `pair`.
|
| 5664 |
+
|
| 5665 |
+
*Effects:* Equivalent to:
|
| 5666 |
+
|
| 5667 |
+
``` cpp
|
| 5668 |
+
return uses_allocator_construction_args<T>(alloc, piecewise_construct,
|
| 5669 |
+
forward_as_tuple(std::move(pr).first),
|
| 5670 |
+
forward_as_tuple(std::move(pr).second));
|
| 5671 |
+
```
|
| 5672 |
+
|
| 5673 |
+
``` cpp
|
| 5674 |
+
template<class T, class Alloc, class... Args>
|
| 5675 |
+
constexpr T make_obj_using_allocator(const Alloc& alloc, Args&&... args);
|
| 5676 |
+
```
|
| 5677 |
+
|
| 5678 |
+
*Effects:* Equivalent to:
|
| 5679 |
+
|
| 5680 |
+
``` cpp
|
| 5681 |
+
return make_from_tuple<T>(uses_allocator_construction_args<T>(
|
| 5682 |
+
alloc, std::forward<Args>(args)...));
|
| 5683 |
+
```
|
| 5684 |
+
|
| 5685 |
+
``` cpp
|
| 5686 |
+
template<class T, class Alloc, class... Args>
|
| 5687 |
+
constexpr T* uninitialized_construct_using_allocator(T* p, const Alloc& alloc, Args&&... args);
|
| 5688 |
+
```
|
| 5689 |
+
|
| 5690 |
+
*Effects:* Equivalent to:
|
| 5691 |
+
|
| 5692 |
+
``` cpp
|
| 5693 |
+
return apply([&]<class... U>(U&&... xs) {
|
| 5694 |
+
return construct_at(p, std::forward<U>(xs)...);
|
| 5695 |
+
}, uses_allocator_construction_args<T>(alloc, std::forward<Args>(args)...));
|
| 5696 |
+
```
|
| 5697 |
|
| 5698 |
### Allocator traits <a id="allocator.traits">[[allocator.traits]]</a>
|
| 5699 |
|
| 5700 |
The class template `allocator_traits` supplies a uniform interface to
|
| 5701 |
all allocator types. An allocator cannot be a non-class type, however,
|
|
|
|
| 5725 |
using is_always_equal = see below;
|
| 5726 |
|
| 5727 |
template<class T> using rebind_alloc = see below;
|
| 5728 |
template<class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
|
| 5729 |
|
| 5730 |
+
[[nodiscard]] static constexpr pointer allocate(Alloc& a, size_type n);
|
| 5731 |
+
[[nodiscard]] static constexpr pointer allocate(Alloc& a, size_type n,
|
| 5732 |
+
const_void_pointer hint);
|
| 5733 |
|
| 5734 |
+
static constexpr void deallocate(Alloc& a, pointer p, size_type n);
|
| 5735 |
|
| 5736 |
template<class T, class... Args>
|
| 5737 |
+
static constexpr void construct(Alloc& a, T* p, Args&&... args);
|
| 5738 |
|
| 5739 |
template<class T>
|
| 5740 |
+
static constexpr void destroy(Alloc& a, T* p);
|
| 5741 |
|
| 5742 |
+
static constexpr size_type max_size(const Alloc& a) noexcept;
|
| 5743 |
|
| 5744 |
+
static constexpr Alloc select_on_container_copy_construction(const Alloc& rhs);
|
| 5745 |
};
|
| 5746 |
}
|
| 5747 |
```
|
| 5748 |
|
| 5749 |
+
#### Member types <a id="allocator.traits.types">[[allocator.traits.types]]</a>
|
| 5750 |
|
| 5751 |
``` cpp
|
| 5752 |
using pointer = see below;
|
| 5753 |
```
|
| 5754 |
|
| 5755 |
*Type:* `Alloc::pointer` if the *qualified-id* `Alloc::pointer` is valid
|
| 5756 |
+
and denotes a type [[temp.deduct]]; otherwise, `value_type*`.
|
| 5757 |
|
| 5758 |
``` cpp
|
| 5759 |
using const_pointer = see below;
|
| 5760 |
```
|
| 5761 |
|
| 5762 |
*Type:* `Alloc::const_pointer` if the *qualified-id*
|
| 5763 |
+
`Alloc::const_pointer` is valid and denotes a type [[temp.deduct]];
|
| 5764 |
otherwise, `pointer_traits<pointer>::rebind<const value_type>`.
|
| 5765 |
|
| 5766 |
``` cpp
|
| 5767 |
using void_pointer = see below;
|
| 5768 |
```
|
| 5769 |
|
| 5770 |
*Type:* `Alloc::void_pointer` if the *qualified-id*
|
| 5771 |
+
`Alloc::void_pointer` is valid and denotes a type [[temp.deduct]];
|
| 5772 |
otherwise, `pointer_traits<pointer>::rebind<void>`.
|
| 5773 |
|
| 5774 |
``` cpp
|
| 5775 |
using const_void_pointer = see below;
|
| 5776 |
```
|
| 5777 |
|
| 5778 |
*Type:* `Alloc::const_void_pointer` if the *qualified-id*
|
| 5779 |
+
`Alloc::const_void_pointer` is valid and denotes a type [[temp.deduct]];
|
| 5780 |
+
otherwise, `pointer_traits<pointer>::rebind<const void>`.
|
|
|
|
| 5781 |
|
| 5782 |
``` cpp
|
| 5783 |
using difference_type = see below;
|
| 5784 |
```
|
| 5785 |
|
| 5786 |
*Type:* `Alloc::difference_type` if the *qualified-id*
|
| 5787 |
+
`Alloc::difference_type` is valid and denotes a type [[temp.deduct]];
|
| 5788 |
otherwise, `pointer_traits<pointer>::difference_type`.
|
| 5789 |
|
| 5790 |
``` cpp
|
| 5791 |
using size_type = see below;
|
| 5792 |
```
|
| 5793 |
|
| 5794 |
*Type:* `Alloc::size_type` if the *qualified-id* `Alloc::size_type` is
|
| 5795 |
+
valid and denotes a type [[temp.deduct]]; otherwise,
|
| 5796 |
`make_unsigned_t<difference_type>`.
|
| 5797 |
|
| 5798 |
``` cpp
|
| 5799 |
using propagate_on_container_copy_assignment = see below;
|
| 5800 |
```
|
| 5801 |
|
| 5802 |
*Type:* `Alloc::propagate_on_container_copy_assignment` if the
|
| 5803 |
*qualified-id* `Alloc::propagate_on_container_copy_assignment` is valid
|
| 5804 |
+
and denotes a type [[temp.deduct]]; otherwise `false_type`.
|
| 5805 |
|
| 5806 |
``` cpp
|
| 5807 |
using propagate_on_container_move_assignment = see below;
|
| 5808 |
```
|
| 5809 |
|
| 5810 |
*Type:* `Alloc::propagate_on_container_move_assignment` if the
|
| 5811 |
*qualified-id* `Alloc::propagate_on_container_move_assignment` is valid
|
| 5812 |
+
and denotes a type [[temp.deduct]]; otherwise `false_type`.
|
| 5813 |
|
| 5814 |
``` cpp
|
| 5815 |
using propagate_on_container_swap = see below;
|
| 5816 |
```
|
| 5817 |
|
| 5818 |
*Type:* `Alloc::propagate_on_container_swap` if the *qualified-id*
|
| 5819 |
`Alloc::propagate_on_container_swap` is valid and denotes a
|
| 5820 |
+
type [[temp.deduct]]; otherwise `false_type`.
|
| 5821 |
|
| 5822 |
``` cpp
|
| 5823 |
using is_always_equal = see below;
|
| 5824 |
```
|
| 5825 |
|
| 5826 |
*Type:* `Alloc::is_always_equal` if the *qualified-id*
|
| 5827 |
+
`Alloc::is_always_equal` is valid and denotes a type [[temp.deduct]];
|
| 5828 |
otherwise `is_empty<Alloc>::type`.
|
| 5829 |
|
| 5830 |
``` cpp
|
| 5831 |
template<class T> using rebind_alloc = see below;
|
| 5832 |
```
|
| 5833 |
|
| 5834 |
*Alias template:* `Alloc::rebind<T>::other` if the *qualified-id*
|
| 5835 |
+
`Alloc::rebind<T>::other` is valid and denotes a type [[temp.deduct]];
|
| 5836 |
+
otherwise, `Alloc<T, Args>` if `Alloc` is a class template instantiation
|
| 5837 |
+
of the form `Alloc<U, Args>`, where `Args` is zero or more type
|
| 5838 |
+
arguments; otherwise, the instantiation of `rebind_alloc` is ill-formed.
|
|
|
|
| 5839 |
|
| 5840 |
+
#### Static member functions <a id="allocator.traits.members">[[allocator.traits.members]]</a>
|
| 5841 |
|
| 5842 |
``` cpp
|
| 5843 |
+
[[nodiscard]] static constexpr pointer allocate(Alloc& a, size_type n);
|
| 5844 |
```
|
| 5845 |
|
| 5846 |
*Returns:* `a.allocate(n)`.
|
| 5847 |
|
| 5848 |
``` cpp
|
| 5849 |
+
[[nodiscard]] static constexpr pointer allocate(Alloc& a, size_type n, const_void_pointer hint);
|
| 5850 |
```
|
| 5851 |
|
| 5852 |
*Returns:* `a.allocate(n, hint)` if that expression is well-formed;
|
| 5853 |
otherwise, `a.allocate(n)`.
|
| 5854 |
|
| 5855 |
``` cpp
|
| 5856 |
+
static constexpr void deallocate(Alloc& a, pointer p, size_type n);
|
| 5857 |
```
|
| 5858 |
|
| 5859 |
*Effects:* Calls `a.deallocate(p, n)`.
|
| 5860 |
|
| 5861 |
*Throws:* Nothing.
|
| 5862 |
|
| 5863 |
``` cpp
|
| 5864 |
template<class T, class... Args>
|
| 5865 |
+
static constexpr void construct(Alloc& a, T* p, Args&&... args);
|
| 5866 |
```
|
| 5867 |
|
| 5868 |
*Effects:* Calls `a.construct(p, std::forward<Args>(args)...)` if that
|
| 5869 |
call is well-formed; otherwise, invokes
|
| 5870 |
+
`construct_at(p, std::forward<Args>(args)...)`.
|
| 5871 |
|
| 5872 |
``` cpp
|
| 5873 |
template<class T>
|
| 5874 |
+
static constexpr void destroy(Alloc& a, T* p);
|
| 5875 |
```
|
| 5876 |
|
| 5877 |
*Effects:* Calls `a.destroy(p)` if that call is well-formed; otherwise,
|
| 5878 |
+
invokes `destroy_at(p)`.
|
| 5879 |
|
| 5880 |
``` cpp
|
| 5881 |
+
static constexpr size_type max_size(const Alloc& a) noexcept;
|
| 5882 |
```
|
| 5883 |
|
| 5884 |
*Returns:* `a.max_size()` if that expression is well-formed; otherwise,
|
| 5885 |
`numeric_limits<size_type>::max()/sizeof(value_type)`.
|
| 5886 |
|
| 5887 |
``` cpp
|
| 5888 |
+
static constexpr Alloc select_on_container_copy_construction(const Alloc& rhs);
|
| 5889 |
```
|
| 5890 |
|
| 5891 |
*Returns:* `rhs.select_on_container_copy_construction()` if that
|
| 5892 |
expression is well-formed; otherwise, `rhs`.
|
| 5893 |
|
| 5894 |
### The default allocator <a id="default.allocator">[[default.allocator]]</a>
|
| 5895 |
|
| 5896 |
+
All specializations of the default allocator meet the allocator
|
| 5897 |
+
completeness requirements [[allocator.requirements.completeness]].
|
| 5898 |
|
| 5899 |
``` cpp
|
| 5900 |
namespace std {
|
| 5901 |
template<class T> class allocator {
|
| 5902 |
public:
|
| 5903 |
using value_type = T;
|
| 5904 |
+
using size_type = size_t;
|
| 5905 |
+
using difference_type = ptrdiff_t;
|
| 5906 |
using propagate_on_container_move_assignment = true_type;
|
| 5907 |
using is_always_equal = true_type;
|
| 5908 |
|
| 5909 |
+
constexpr allocator() noexcept;
|
| 5910 |
+
constexpr allocator(const allocator&) noexcept;
|
| 5911 |
+
template<class U> constexpr allocator(const allocator<U>&) noexcept;
|
| 5912 |
+
constexpr ~allocator();
|
| 5913 |
+
constexpr allocator& operator=(const allocator&) = default;
|
| 5914 |
|
| 5915 |
+
[[nodiscard]] constexpr T* allocate(size_t n);
|
| 5916 |
+
constexpr void deallocate(T* p, size_t n);
|
| 5917 |
};
|
| 5918 |
}
|
| 5919 |
```
|
| 5920 |
|
| 5921 |
+
#### Members <a id="allocator.members">[[allocator.members]]</a>
|
| 5922 |
|
| 5923 |
Except for the destructor, member functions of the default allocator
|
| 5924 |
+
shall not introduce data races [[intro.multithread]] as a result of
|
| 5925 |
concurrent calls to those member functions from different threads. Calls
|
| 5926 |
to these functions that allocate or deallocate a particular unit of
|
| 5927 |
storage shall occur in a single total order, and each such deallocation
|
| 5928 |
call shall happen before the next allocation (if any) in this order.
|
| 5929 |
|
| 5930 |
``` cpp
|
| 5931 |
+
[[nodiscard]] constexpr T* allocate(size_t n);
|
| 5932 |
```
|
| 5933 |
|
| 5934 |
+
*Mandates:* `T` is not an incomplete type [[basic.types]].
|
|
|
|
| 5935 |
|
| 5936 |
+
*Returns:* A pointer to the initial element of an array of `n` `T`.
|
|
|
|
|
|
|
| 5937 |
|
| 5938 |
+
*Remarks:* The storage for the array is obtained by calling
|
| 5939 |
+
`::operator new` [[new.delete]], but it is unspecified when or how often
|
| 5940 |
+
this function is called. This function starts the lifetime of the array
|
| 5941 |
+
object, but not that of any of the array elements.
|
| 5942 |
+
|
| 5943 |
+
*Throws:* `bad_array_new_length` if
|
| 5944 |
+
`numeric_limits<size_t>::max() / sizeof(T) < n`, or `bad_alloc` if the
|
| 5945 |
+
storage cannot be obtained.
|
| 5946 |
|
| 5947 |
``` cpp
|
| 5948 |
+
constexpr void deallocate(T* p, size_t n);
|
| 5949 |
```
|
| 5950 |
|
| 5951 |
+
*Preconditions:* `p` is a pointer value obtained from `allocate()`. `n`
|
| 5952 |
+
equals the value passed as the first argument to the invocation of
|
| 5953 |
allocate which returned `p`.
|
| 5954 |
|
| 5955 |
*Effects:* Deallocates the storage referenced by `p` .
|
| 5956 |
|
| 5957 |
+
*Remarks:* Uses `::operator delete` [[new.delete]], but it is
|
| 5958 |
unspecified when this function is called.
|
| 5959 |
|
| 5960 |
+
#### Operators <a id="allocator.globals">[[allocator.globals]]</a>
|
| 5961 |
|
| 5962 |
``` cpp
|
| 5963 |
template<class T, class U>
|
| 5964 |
+
constexpr bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
|
| 5965 |
```
|
| 5966 |
|
| 5967 |
*Returns:* `true`.
|
| 5968 |
|
| 5969 |
+
### `addressof` <a id="specialized.addressof">[[specialized.addressof]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5970 |
|
| 5971 |
``` cpp
|
| 5972 |
template<class T> constexpr T* addressof(T& r) noexcept;
|
| 5973 |
```
|
| 5974 |
|
| 5975 |
*Returns:* The actual address of the object or function referenced by
|
| 5976 |
`r`, even in the presence of an overloaded `operator&`.
|
| 5977 |
|
| 5978 |
*Remarks:* An expression `addressof(E)` is a constant
|
| 5979 |
+
subexpression [[defns.const.subexpr]] if `E` is an lvalue constant
|
| 5980 |
subexpression.
|
| 5981 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5982 |
### C library memory allocation <a id="c.malloc">[[c.malloc]]</a>
|
| 5983 |
|
| 5984 |
+
[*Note 1*: The header `<cstdlib>` declares the functions described in
|
| 5985 |
+
this subclause. — *end note*]
|
| 5986 |
|
| 5987 |
``` cpp
|
| 5988 |
void* aligned_alloc(size_t alignment, size_t size);
|
| 5989 |
void* calloc(size_t nmemb, size_t size);
|
| 5990 |
void* malloc(size_t size);
|
|
|
|
| 5993 |
|
| 5994 |
*Effects:* These functions have the semantics specified in the C
|
| 5995 |
standard library.
|
| 5996 |
|
| 5997 |
*Remarks:* These functions do not attempt to allocate storage by calling
|
| 5998 |
+
`::operator new()` [[new.delete]].
|
| 5999 |
|
| 6000 |
Storage allocated directly with these functions is implicitly declared
|
| 6001 |
reachable (see [[basic.stc.dynamic.safety]]) on allocation, ceases to
|
| 6002 |
be declared reachable on deallocation, and need not cease to be declared
|
| 6003 |
reachable as the result of an `undeclare_reachable()` call.
|
|
|
|
| 6011 |
intentionally be used as a replacement for `declare_reachable()`, and
|
| 6012 |
newly written code is strongly encouraged to treat memory allocated with
|
| 6013 |
these functions as though it were allocated with
|
| 6014 |
`operator new`. — *end note*]
|
| 6015 |
|
| 6016 |
+
These functions implicitly create objects [[intro.object]] in the
|
| 6017 |
+
returned region of storage and return a pointer to a suitable created
|
| 6018 |
+
object. In the case of `calloc` and `realloc`, the objects are created
|
| 6019 |
+
before the storage is zeroed or copied, respectively.
|
| 6020 |
+
|
| 6021 |
``` cpp
|
| 6022 |
void free(void* ptr);
|
| 6023 |
```
|
| 6024 |
|
| 6025 |
*Effects:* This function has the semantics specified in the C standard
|
| 6026 |
library.
|
| 6027 |
|
| 6028 |
*Remarks:* This function does not attempt to deallocate storage by
|
| 6029 |
calling `::operator delete()`.
|
| 6030 |
|
| 6031 |
+
See also: ISO C 7.22.3
|
| 6032 |
|
| 6033 |
## Smart pointers <a id="smartptr">[[smartptr]]</a>
|
| 6034 |
|
| 6035 |
### Class template `unique_ptr` <a id="unique.ptr">[[unique.ptr]]</a>
|
| 6036 |
|
| 6037 |
A *unique pointer* is an object that owns another object and manages
|
| 6038 |
that other object through a pointer. More precisely, a unique pointer is
|
| 6039 |
an object *u* that stores a pointer to a second object *p* and will
|
| 6040 |
dispose of *p* when *u* is itself destroyed (e.g., when leaving block
|
| 6041 |
+
scope [[stmt.dcl]]). In this context, *u* is said to *own* `p`.
|
| 6042 |
|
| 6043 |
The mechanism by which *u* disposes of *p* is known as *p*’s associated
|
| 6044 |
*deleter*, a function object whose correct invocation results in *p*’s
|
| 6045 |
appropriate disposition (typically its deletion).
|
| 6046 |
|
| 6047 |
Let the notation *u.p* denote the pointer stored by *u*, and let *u.d*
|
| 6048 |
denote the associated deleter. Upon request, *u* can *reset* (replace)
|
| 6049 |
+
*u.p* and *u.d* with another pointer and deleter, but properly disposes
|
| 6050 |
+
of its owned object via the associated deleter before such replacement
|
| 6051 |
+
is considered completed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6052 |
|
| 6053 |
Each object of a type `U` instantiated from the `unique_ptr` template
|
| 6054 |
specified in this subclause has the strict ownership semantics,
|
| 6055 |
specified above, of a unique pointer. In partial satisfaction of these
|
| 6056 |
+
semantics, each such `U` is *Cpp17MoveConstructible* and
|
| 6057 |
+
*Cpp17MoveAssignable*, but is not *Cpp17CopyConstructible* nor
|
| 6058 |
+
*Cpp17CopyAssignable*. The template parameter `T` of `unique_ptr` may be
|
| 6059 |
+
an incomplete type.
|
| 6060 |
|
| 6061 |
+
[*Note 1*: The uses of `unique_ptr` include providing exception safety
|
| 6062 |
for dynamically allocated memory, passing ownership of dynamically
|
| 6063 |
allocated memory to a function, and returning dynamically allocated
|
| 6064 |
memory from a function. — *end note*]
|
| 6065 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6066 |
#### Default deleters <a id="unique.ptr.dltr">[[unique.ptr.dltr]]</a>
|
| 6067 |
|
| 6068 |
##### In general <a id="unique.ptr.dltr.general">[[unique.ptr.dltr.general]]</a>
|
| 6069 |
|
| 6070 |
The class template `default_delete` serves as the default deleter
|
|
|
|
| 6087 |
|
| 6088 |
``` cpp
|
| 6089 |
template<class U> default_delete(const default_delete<U>& other) noexcept;
|
| 6090 |
```
|
| 6091 |
|
| 6092 |
+
*Constraints:* `U*` is implicitly convertible to `T*`.
|
| 6093 |
+
|
| 6094 |
*Effects:* Constructs a `default_delete` object from another
|
| 6095 |
`default_delete<U>` object.
|
| 6096 |
|
|
|
|
|
|
|
|
|
|
| 6097 |
``` cpp
|
| 6098 |
void operator()(T* ptr) const;
|
| 6099 |
```
|
| 6100 |
|
| 6101 |
+
*Mandates:* `T` is a complete type.
|
| 6102 |
+
|
| 6103 |
*Effects:* Calls `delete` on `ptr`.
|
| 6104 |
|
|
|
|
|
|
|
| 6105 |
##### `default_delete<T[]>` <a id="unique.ptr.dltr.dflt1">[[unique.ptr.dltr.dflt1]]</a>
|
| 6106 |
|
| 6107 |
``` cpp
|
| 6108 |
namespace std {
|
| 6109 |
template<class T> struct default_delete<T[]> {
|
|
|
|
| 6116 |
|
| 6117 |
``` cpp
|
| 6118 |
template<class U> default_delete(const default_delete<U[]>& other) noexcept;
|
| 6119 |
```
|
| 6120 |
|
| 6121 |
+
*Constraints:* `U(*)[]` is convertible to `T(*)[]`.
|
| 6122 |
+
|
| 6123 |
+
*Effects:* Constructs a `default_delete` object from another
|
| 6124 |
`default_delete<U[]>` object.
|
| 6125 |
|
|
|
|
|
|
|
|
|
|
| 6126 |
``` cpp
|
| 6127 |
template<class U> void operator()(U* ptr) const;
|
| 6128 |
```
|
| 6129 |
|
| 6130 |
+
*Mandates:* `U` is a complete type.
|
| 6131 |
+
|
| 6132 |
+
*Constraints:* `U(*)[]` is convertible to `T(*)[]`.
|
| 6133 |
+
|
| 6134 |
*Effects:* Calls `delete[]` on `ptr`.
|
| 6135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6136 |
#### `unique_ptr` for single objects <a id="unique.ptr.single">[[unique.ptr.single]]</a>
|
| 6137 |
|
| 6138 |
``` cpp
|
| 6139 |
namespace std {
|
| 6140 |
template<class T, class D = default_delete<T>> class unique_ptr {
|
|
|
|
| 6156 |
// [unique.ptr.single.dtor], destructor
|
| 6157 |
~unique_ptr();
|
| 6158 |
|
| 6159 |
// [unique.ptr.single.asgn], assignment
|
| 6160 |
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
| 6161 |
+
template<class U, class E>
|
| 6162 |
+
unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
|
| 6163 |
unique_ptr& operator=(nullptr_t) noexcept;
|
| 6164 |
|
| 6165 |
// [unique.ptr.single.observers], observers
|
| 6166 |
add_lvalue_reference_t<T> operator*() const;
|
| 6167 |
pointer operator->() const noexcept;
|
|
|
|
| 6181 |
};
|
| 6182 |
}
|
| 6183 |
```
|
| 6184 |
|
| 6185 |
The default type for the template parameter `D` is `default_delete`. A
|
| 6186 |
+
client-supplied template argument `D` shall be a function object type
|
| 6187 |
+
[[function.objects]], lvalue reference to function, or lvalue reference
|
| 6188 |
to function object type for which, given a value `d` of type `D` and a
|
| 6189 |
value `ptr` of type `unique_ptr<T, D>::pointer`, the expression `d(ptr)`
|
| 6190 |
is valid and has the effect of disposing of the pointer as appropriate
|
| 6191 |
for that deleter.
|
| 6192 |
|
| 6193 |
+
If the deleter’s type `D` is not a reference type, `D` shall meet the
|
| 6194 |
+
*Cpp17Destructible* requirements ([[cpp17.destructible]]).
|
| 6195 |
|
| 6196 |
If the *qualified-id* `remove_reference_t<D>::pointer` is valid and
|
| 6197 |
+
denotes a type [[temp.deduct]], then `unique_ptr<T,
|
| 6198 |
D>::pointer` shall be a synonym for `remove_reference_t<D>::pointer`.
|
| 6199 |
Otherwise `unique_ptr<T, D>::pointer` shall be a synonym for
|
| 6200 |
`element_type*`. The type `unique_ptr<T,
|
| 6201 |
+
D>::pointer` shall meet the *Cpp17NullablePointer* requirements (
|
| 6202 |
+
[[cpp17.nullablepointer]]).
|
| 6203 |
|
| 6204 |
+
[*Example 1*: Given an allocator type `X` ([[cpp17.allocator]]) and
|
| 6205 |
+
letting `A` be a synonym for `allocator_traits<X>`, the types
|
| 6206 |
`A::pointer`, `A::const_pointer`, `A::void_pointer`, and
|
| 6207 |
`A::const_void_pointer` may be used as
|
| 6208 |
`unique_ptr<T, D>::pointer`. — *end example*]
|
| 6209 |
|
| 6210 |
+
##### Constructors <a id="unique.ptr.single.ctor">[[unique.ptr.single.ctor]]</a>
|
| 6211 |
|
| 6212 |
``` cpp
|
| 6213 |
constexpr unique_ptr() noexcept;
|
| 6214 |
constexpr unique_ptr(nullptr_t) noexcept;
|
| 6215 |
```
|
| 6216 |
|
| 6217 |
+
*Preconditions:* `D` meets the *Cpp17DefaultConstructible* requirements
|
| 6218 |
+
([[cpp17.defaultconstructible]]), and that construction does not throw
|
| 6219 |
+
an exception.
|
| 6220 |
+
|
| 6221 |
+
*Constraints:* `is_pointer_v<deleter_type>` is `false` and
|
| 6222 |
+
`is_default_constructible_v<deleter_type>` is `true`.
|
| 6223 |
|
| 6224 |
*Effects:* Constructs a `unique_ptr` object that owns nothing,
|
| 6225 |
value-initializing the stored pointer and the stored deleter.
|
| 6226 |
|
| 6227 |
+
*Ensures:* `get() == nullptr`. `get_deleter()` returns a reference to
|
| 6228 |
+
the stored deleter.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6229 |
|
| 6230 |
``` cpp
|
| 6231 |
explicit unique_ptr(pointer p) noexcept;
|
| 6232 |
```
|
| 6233 |
|
| 6234 |
+
*Constraints:* `is_pointer_v<deleter_type>` is `false` and
|
| 6235 |
+
`is_default_constructible_v<deleter_type>` is `true`.
|
| 6236 |
+
|
| 6237 |
+
*Mandates:* This constructor is not selected by class template argument
|
| 6238 |
+
deduction [[over.match.class.deduct]].
|
| 6239 |
+
|
| 6240 |
+
*Preconditions:* `D` meets the *Cpp17DefaultConstructible* requirements
|
| 6241 |
+
([[cpp17.defaultconstructible]]), and that construction does not throw
|
| 6242 |
+
an exception.
|
| 6243 |
|
| 6244 |
*Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
|
| 6245 |
stored pointer with `p` and value-initializing the stored deleter.
|
| 6246 |
|
| 6247 |
+
*Ensures:* `get() == p`. `get_deleter()` returns a reference to the
|
| 6248 |
+
stored deleter.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6249 |
|
| 6250 |
``` cpp
|
| 6251 |
+
unique_ptr(pointer p, const D& d) noexcept;
|
| 6252 |
+
unique_ptr(pointer p, remove_reference_t<D>&& d) noexcept;
|
| 6253 |
```
|
| 6254 |
|
| 6255 |
+
*Constraints:* `is_constructible_v<D, decltype(d)>` is `true`.
|
| 6256 |
|
| 6257 |
+
*Mandates:* These constructors are not selected by class template
|
| 6258 |
+
argument deduction [[over.match.class.deduct]].
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6259 |
|
| 6260 |
+
*Preconditions:* For the first constructor, if `D` is not a reference
|
| 6261 |
+
type, `D` meets the *Cpp17CopyConstructible* requirements and such
|
| 6262 |
+
construction does not exit via an exception. For the second constructor,
|
| 6263 |
+
if `D` is not a reference type, `D` meets the *Cpp17MoveConstructible*
|
| 6264 |
+
requirements and such construction does not exit via an exception.
|
| 6265 |
|
| 6266 |
*Effects:* Constructs a `unique_ptr` object which owns `p`, initializing
|
| 6267 |
the stored pointer with `p` and initializing the deleter from
|
| 6268 |
`std::forward<decltype(d)>(d)`.
|
| 6269 |
|
| 6270 |
+
*Ensures:* `get() == p`. `get_deleter()` returns a reference to the
|
| 6271 |
+
stored deleter. If `D` is a reference type then `get_deleter()` returns
|
| 6272 |
+
a reference to the lvalue `d`.
|
| 6273 |
|
| 6274 |
+
*Remarks:* If `D` is a reference type, the second constructor is defined
|
| 6275 |
+
as deleted.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6276 |
|
| 6277 |
[*Example 1*:
|
| 6278 |
|
| 6279 |
``` cpp
|
| 6280 |
D d;
|
| 6281 |
+
unique_ptr<int, D> p1(new int, D()); // D must be Cpp17MoveConstructible
|
| 6282 |
+
unique_ptr<int, D> p2(new int, d); // D must be Cpp17CopyConstructible
|
| 6283 |
unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d
|
| 6284 |
unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined
|
| 6285 |
// with reference deleter type
|
| 6286 |
```
|
| 6287 |
|
|
|
|
| 6289 |
|
| 6290 |
``` cpp
|
| 6291 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 6292 |
```
|
| 6293 |
|
| 6294 |
+
*Constraints:* `is_move_constructible_v<D>` is `true`.
|
|
|
|
|
|
|
|
|
|
| 6295 |
|
| 6296 |
+
*Preconditions:* If `D` is not a reference type, `D` meets the
|
| 6297 |
+
*Cpp17MoveConstructible* requirements ([[cpp17.moveconstructible]]).
|
| 6298 |
+
Construction of the deleter from an rvalue of type `D` does not throw an
|
| 6299 |
+
exception.
|
| 6300 |
|
| 6301 |
+
*Effects:* Constructs a `unique_ptr` from `u`. If `D` is a reference
|
| 6302 |
+
type, this deleter is copy constructed from `u`’s deleter; otherwise,
|
| 6303 |
+
this deleter is move constructed from `u`’s deleter.
|
| 6304 |
+
|
| 6305 |
+
[*Note 1*: The construction of the deleter can be implemented with
|
| 6306 |
`std::forward<D>`. — *end note*]
|
| 6307 |
|
| 6308 |
+
*Ensures:* `get()` yields the value `u.get()` yielded before the
|
| 6309 |
+
construction. `u.get() == nullptr`. `get_deleter()` returns a reference
|
| 6310 |
+
to the stored deleter that was constructed from `u.get_deleter()`. If
|
| 6311 |
+
`D` is a reference type then `get_deleter()` and `u.get_deleter()` both
|
| 6312 |
+
reference the same lvalue deleter.
|
| 6313 |
|
| 6314 |
``` cpp
|
| 6315 |
template<class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
| 6316 |
```
|
| 6317 |
|
| 6318 |
+
*Constraints:*
|
| 6319 |
+
|
| 6320 |
+
- `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
|
| 6321 |
+
- `U` is not an array type, and
|
| 6322 |
+
- either `D` is a reference type and `E` is the same type as `D`, or `D`
|
| 6323 |
+
is not a reference type and `E` is implicitly convertible to `D`.
|
| 6324 |
+
|
| 6325 |
+
*Preconditions:* If `E` is not a reference type, construction of the
|
| 6326 |
+
deleter from an rvalue of type `E` is well-formed and does not throw an
|
| 6327 |
exception. Otherwise, `E` is a reference type and construction of the
|
| 6328 |
+
deleter from an lvalue of type `E` is well-formed and does not throw an
|
| 6329 |
+
exception.
|
| 6330 |
|
| 6331 |
+
*Effects:* Constructs a `unique_ptr` from `u`. If `E` is a reference
|
| 6332 |
+
type, this deleter is copy constructed from `u`’s deleter; otherwise,
|
| 6333 |
+
this deleter is move constructed from `u`’s deleter.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6334 |
|
| 6335 |
[*Note 2*: The deleter constructor can be implemented with
|
| 6336 |
`std::forward<E>`. — *end note*]
|
| 6337 |
|
| 6338 |
+
*Ensures:* `get()` yields the value `u.get()` yielded before the
|
| 6339 |
+
construction. `u.get() == nullptr`. `get_deleter()` returns a reference
|
| 6340 |
+
to the stored deleter that was constructed from `u.get_deleter()`.
|
| 6341 |
|
| 6342 |
+
##### Destructor <a id="unique.ptr.single.dtor">[[unique.ptr.single.dtor]]</a>
|
| 6343 |
|
| 6344 |
``` cpp
|
| 6345 |
~unique_ptr();
|
| 6346 |
```
|
| 6347 |
|
| 6348 |
+
*Preconditions:* The expression `get_deleter()(get())` is well-formed,
|
| 6349 |
+
has well-defined behavior, and does not throw exceptions.
|
| 6350 |
|
| 6351 |
[*Note 3*: The use of `default_delete` requires `T` to be a complete
|
| 6352 |
type. — *end note*]
|
| 6353 |
|
| 6354 |
*Effects:* If `get() == nullptr` there are no effects. Otherwise
|
| 6355 |
`get_deleter()(get())`.
|
| 6356 |
|
| 6357 |
+
##### Assignment <a id="unique.ptr.single.asgn">[[unique.ptr.single.asgn]]</a>
|
| 6358 |
|
| 6359 |
``` cpp
|
| 6360 |
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
| 6361 |
```
|
| 6362 |
|
| 6363 |
+
*Constraints:* `is_move_assignable_v<D>` is `true`.
|
| 6364 |
+
|
| 6365 |
+
*Preconditions:* If `D` is not a reference type, `D` meets the
|
| 6366 |
+
*Cpp17MoveAssignable* requirements ([[cpp17.moveassignable]]) and
|
| 6367 |
+
assignment of the deleter from an rvalue of type `D` does not throw an
|
| 6368 |
exception. Otherwise, `D` is a reference type; `remove_reference_t<D>`
|
| 6369 |
+
meets the *Cpp17CopyAssignable* requirements and assignment of the
|
| 6370 |
+
deleter from an lvalue of type `D` does not throw an exception.
|
| 6371 |
|
| 6372 |
+
*Effects:* Calls `reset(u.release())` followed by
|
|
|
|
| 6373 |
`get_deleter() = std::forward<D>(u.get_deleter())`.
|
| 6374 |
|
| 6375 |
*Returns:* `*this`.
|
| 6376 |
|
| 6377 |
+
*Ensures:* `u.get() == nullptr`.
|
| 6378 |
+
|
| 6379 |
``` cpp
|
| 6380 |
template<class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
|
| 6381 |
```
|
| 6382 |
|
| 6383 |
+
*Constraints:*
|
| 6384 |
+
|
| 6385 |
+
- `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
|
| 6386 |
+
and
|
| 6387 |
+
- `U` is not an array type, and
|
| 6388 |
+
- `is_assignable_v<D&, E&&>` is `true`.
|
| 6389 |
+
|
| 6390 |
+
*Preconditions:* If `E` is not a reference type, assignment of the
|
| 6391 |
+
deleter from an rvalue of type `E` is well-formed and does not throw an
|
| 6392 |
exception. Otherwise, `E` is a reference type and assignment of the
|
| 6393 |
+
deleter from an lvalue of type `E` is well-formed and does not throw an
|
| 6394 |
+
exception.
|
| 6395 |
|
| 6396 |
+
*Effects:* Calls `reset(u.release())` followed by
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6397 |
`get_deleter() = std::forward<E>(u.get_deleter())`.
|
| 6398 |
|
| 6399 |
*Returns:* `*this`.
|
| 6400 |
|
| 6401 |
+
*Ensures:* `u.get() == nullptr`.
|
| 6402 |
+
|
| 6403 |
``` cpp
|
| 6404 |
unique_ptr& operator=(nullptr_t) noexcept;
|
| 6405 |
```
|
| 6406 |
|
| 6407 |
*Effects:* As if by `reset()`.
|
| 6408 |
|
| 6409 |
+
*Ensures:* `get() == nullptr`.
|
| 6410 |
|
| 6411 |
*Returns:* `*this`.
|
| 6412 |
|
| 6413 |
+
##### Observers <a id="unique.ptr.single.observers">[[unique.ptr.single.observers]]</a>
|
| 6414 |
|
| 6415 |
``` cpp
|
| 6416 |
add_lvalue_reference_t<T> operator*() const;
|
| 6417 |
```
|
| 6418 |
|
| 6419 |
+
*Preconditions:* `get() != nullptr`.
|
| 6420 |
|
| 6421 |
*Returns:* `*get()`.
|
| 6422 |
|
| 6423 |
``` cpp
|
| 6424 |
pointer operator->() const noexcept;
|
| 6425 |
```
|
| 6426 |
|
| 6427 |
+
*Preconditions:* `get() != nullptr`.
|
| 6428 |
|
| 6429 |
*Returns:* `get()`.
|
| 6430 |
|
| 6431 |
[*Note 4*: The use of this function typically requires that `T` be a
|
| 6432 |
complete type. — *end note*]
|
|
|
|
| 6448 |
explicit operator bool() const noexcept;
|
| 6449 |
```
|
| 6450 |
|
| 6451 |
*Returns:* `get() != nullptr`.
|
| 6452 |
|
| 6453 |
+
##### Modifiers <a id="unique.ptr.single.modifiers">[[unique.ptr.single.modifiers]]</a>
|
| 6454 |
|
| 6455 |
``` cpp
|
| 6456 |
pointer release() noexcept;
|
| 6457 |
```
|
| 6458 |
|
| 6459 |
+
*Ensures:* `get() == nullptr`.
|
| 6460 |
|
| 6461 |
*Returns:* The value `get()` had at the start of the call to `release`.
|
| 6462 |
|
| 6463 |
``` cpp
|
| 6464 |
void reset(pointer p = pointer()) noexcept;
|
| 6465 |
```
|
| 6466 |
|
| 6467 |
+
*Preconditions:* The expression `get_deleter()(get())` is well-formed,
|
| 6468 |
+
has well-defined behavior, and does not throw exceptions.
|
| 6469 |
|
| 6470 |
*Effects:* Assigns `p` to the stored pointer, and then if and only if
|
| 6471 |
the old value of the stored pointer, `old_p`, was not equal to
|
| 6472 |
`nullptr`, calls `get_deleter()(old_p)`.
|
| 6473 |
|
| 6474 |
[*Note 5*: The order of these operations is significant because the
|
| 6475 |
call to `get_deleter()` may destroy `*this`. — *end note*]
|
| 6476 |
|
| 6477 |
+
*Ensures:* `get() == p`.
|
| 6478 |
|
| 6479 |
[*Note 6*: The postcondition does not hold if the call to
|
| 6480 |
`get_deleter()` destroys `*this` since `this->get()` is no longer a
|
| 6481 |
valid expression. — *end note*]
|
| 6482 |
|
| 6483 |
``` cpp
|
| 6484 |
void swap(unique_ptr& u) noexcept;
|
| 6485 |
```
|
| 6486 |
|
| 6487 |
+
*Preconditions:* `get_deleter()` is swappable [[swappable.requirements]]
|
| 6488 |
+
and does not throw an exception under `swap`.
|
|
|
|
| 6489 |
|
| 6490 |
*Effects:* Invokes `swap` on the stored pointers and on the stored
|
| 6491 |
deleters of `*this` and `u`.
|
| 6492 |
|
| 6493 |
#### `unique_ptr` for array objects with a runtime length <a id="unique.ptr.runtime">[[unique.ptr.runtime]]</a>
|
|
|
|
| 6555 |
Descriptions are provided below only for members that differ from the
|
| 6556 |
primary template.
|
| 6557 |
|
| 6558 |
The template argument `T` shall be a complete type.
|
| 6559 |
|
| 6560 |
+
##### Constructors <a id="unique.ptr.runtime.ctor">[[unique.ptr.runtime.ctor]]</a>
|
| 6561 |
|
| 6562 |
``` cpp
|
| 6563 |
template<class U> explicit unique_ptr(U p) noexcept;
|
| 6564 |
```
|
| 6565 |
|
| 6566 |
This constructor behaves the same as the constructor in the primary
|
| 6567 |
+
template that takes a single parameter of type `pointer`.
|
| 6568 |
+
|
| 6569 |
+
*Constraints:*
|
| 6570 |
|
| 6571 |
- `U` is the same type as `pointer`, or
|
| 6572 |
- `pointer` is the same type as `element_type*`, `U` is a pointer type
|
| 6573 |
`V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
|
| 6574 |
|
|
|
|
| 6576 |
template<class U> unique_ptr(U p, see below d) noexcept;
|
| 6577 |
template<class U> unique_ptr(U p, see below d) noexcept;
|
| 6578 |
```
|
| 6579 |
|
| 6580 |
These constructors behave the same as the constructors in the primary
|
| 6581 |
+
template that take a parameter of type `pointer` and a second parameter.
|
| 6582 |
+
|
| 6583 |
+
*Constraints:*
|
| 6584 |
|
| 6585 |
- `U` is the same type as `pointer`,
|
| 6586 |
- `U` is `nullptr_t`, or
|
| 6587 |
- `pointer` is the same type as `element_type*`, `U` is a pointer type
|
| 6588 |
`V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
|
| 6589 |
|
| 6590 |
``` cpp
|
| 6591 |
+
template<class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
|
|
|
| 6592 |
```
|
| 6593 |
|
| 6594 |
+
This constructor behaves the same as in the primary template.
|
| 6595 |
+
|
| 6596 |
+
*Constraints:* Where `UP` is `unique_ptr<U, E>`:
|
| 6597 |
|
| 6598 |
- `U` is an array type, and
|
| 6599 |
- `pointer` is the same type as `element_type*`, and
|
| 6600 |
- `UP::pointer` is the same type as `UP::element_type*`, and
|
| 6601 |
- `UP::element_type(*)[]` is convertible to `element_type(*)[]`, and
|
| 6602 |
- either `D` is a reference type and `E` is the same type as `D`, or `D`
|
| 6603 |
is not a reference type and `E` is implicitly convertible to `D`.
|
| 6604 |
|
| 6605 |
+
[*Note 1*: This replaces the *Constraints:* specification of the
|
| 6606 |
+
primary template. — *end note*]
|
| 6607 |
|
| 6608 |
+
##### Assignment <a id="unique.ptr.runtime.asgn">[[unique.ptr.runtime.asgn]]</a>
|
| 6609 |
|
| 6610 |
``` cpp
|
| 6611 |
+
template<class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u)noexcept;
|
|
|
|
| 6612 |
```
|
| 6613 |
|
| 6614 |
+
This operator behaves the same as in the primary template.
|
| 6615 |
+
|
| 6616 |
+
*Constraints:* Where `UP` is `unique_ptr<U, E>`:
|
| 6617 |
|
| 6618 |
- `U` is an array type, and
|
| 6619 |
- `pointer` is the same type as `element_type*`, and
|
| 6620 |
- `UP::pointer` is the same type as `UP::element_type*`, and
|
| 6621 |
- `UP::element_type(*)[]` is convertible to `element_type(*)[]`, and
|
| 6622 |
- `is_assignable_v<D&, E&&>` is `true`.
|
| 6623 |
|
| 6624 |
+
[*Note 2*: This replaces the *Constraints:* specification of the
|
| 6625 |
+
primary template. — *end note*]
|
| 6626 |
|
| 6627 |
+
##### Observers <a id="unique.ptr.runtime.observers">[[unique.ptr.runtime.observers]]</a>
|
| 6628 |
|
| 6629 |
``` cpp
|
| 6630 |
T& operator[](size_t i) const;
|
| 6631 |
```
|
| 6632 |
|
| 6633 |
+
*Preconditions:* `i` < the number of elements in the array to which the
|
| 6634 |
stored pointer points.
|
| 6635 |
|
| 6636 |
*Returns:* `get()[i]`.
|
| 6637 |
|
| 6638 |
+
##### Modifiers <a id="unique.ptr.runtime.modifiers">[[unique.ptr.runtime.modifiers]]</a>
|
| 6639 |
|
| 6640 |
``` cpp
|
| 6641 |
void reset(nullptr_t p = nullptr) noexcept;
|
| 6642 |
```
|
| 6643 |
|
|
|
|
| 6646 |
``` cpp
|
| 6647 |
template<class U> void reset(U p) noexcept;
|
| 6648 |
```
|
| 6649 |
|
| 6650 |
This function behaves the same as the `reset` member of the primary
|
| 6651 |
+
template.
|
| 6652 |
+
|
| 6653 |
+
*Constraints:*
|
| 6654 |
|
| 6655 |
- `U` is the same type as `pointer`, or
|
| 6656 |
- `pointer` is the same type as `element_type*`, `U` is a pointer type
|
| 6657 |
`V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
|
| 6658 |
|
| 6659 |
+
#### Creation <a id="unique.ptr.create">[[unique.ptr.create]]</a>
|
| 6660 |
|
| 6661 |
``` cpp
|
| 6662 |
template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
|
| 6663 |
```
|
| 6664 |
|
| 6665 |
+
*Constraints:* `T` is not an array type.
|
|
|
|
| 6666 |
|
| 6667 |
*Returns:* `unique_ptr<T>(new T(std::forward<Args>(args)...))`.
|
| 6668 |
|
| 6669 |
``` cpp
|
| 6670 |
template<class T> unique_ptr<T> make_unique(size_t n);
|
| 6671 |
```
|
| 6672 |
|
| 6673 |
+
*Constraints:* `T` is an array of unknown bound.
|
|
|
|
| 6674 |
|
| 6675 |
*Returns:* `unique_ptr<T>(new remove_extent_t<T>[n]())`.
|
| 6676 |
|
| 6677 |
``` cpp
|
| 6678 |
template<class T, class... Args> unspecified make_unique(Args&&...) = delete;
|
| 6679 |
```
|
| 6680 |
|
| 6681 |
+
*Constraints:* `T` is an array of known bound.
|
|
|
|
| 6682 |
|
| 6683 |
+
``` cpp
|
| 6684 |
+
template<class T> unique_ptr<T> make_unique_for_overwrite();
|
| 6685 |
+
```
|
| 6686 |
+
|
| 6687 |
+
*Constraints:* `T` is not an array type.
|
| 6688 |
+
|
| 6689 |
+
*Returns:* `unique_ptr<T>(new T)`.
|
| 6690 |
+
|
| 6691 |
+
``` cpp
|
| 6692 |
+
template<class T> unique_ptr<T> make_unique_for_overwrite(size_t n);
|
| 6693 |
+
```
|
| 6694 |
+
|
| 6695 |
+
*Constraints:* `T` is an array of unknown bound.
|
| 6696 |
+
|
| 6697 |
+
*Returns:* `unique_ptr<T>(new remove_extent_t<T>[n])`.
|
| 6698 |
+
|
| 6699 |
+
``` cpp
|
| 6700 |
+
template<class T, class... Args> unspecified make_unique_for_overwrite(Args&&...) = delete;
|
| 6701 |
+
```
|
| 6702 |
+
|
| 6703 |
+
*Constraints:* `T` is an array of known bound.
|
| 6704 |
+
|
| 6705 |
+
#### Specialized algorithms <a id="unique.ptr.special">[[unique.ptr.special]]</a>
|
| 6706 |
|
| 6707 |
``` cpp
|
| 6708 |
template<class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
|
| 6709 |
```
|
| 6710 |
|
| 6711 |
+
*Constraints:* `is_swappable_v<D>` is `true`.
|
|
|
|
| 6712 |
|
| 6713 |
*Effects:* Calls `x.swap(y)`.
|
| 6714 |
|
| 6715 |
``` cpp
|
| 6716 |
template<class T1, class D1, class T2, class D2>
|
| 6717 |
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6718 |
```
|
| 6719 |
|
| 6720 |
*Returns:* `x.get() == y.get()`.
|
| 6721 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6722 |
``` cpp
|
| 6723 |
template<class T1, class D1, class T2, class D2>
|
| 6724 |
bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6725 |
```
|
| 6726 |
|
| 6727 |
+
Let `CT` denote
|
| 6728 |
|
| 6729 |
``` cpp
|
| 6730 |
common_type_t<typename unique_ptr<T1, D1>::pointer,
|
| 6731 |
typename unique_ptr<T2, D2>::pointer>
|
| 6732 |
```
|
| 6733 |
|
| 6734 |
+
*Mandates:*
|
|
|
|
|
|
|
| 6735 |
|
| 6736 |
+
- `unique_ptr<T1, D1>::pointer` is implicitly convertible to `CT` and
|
| 6737 |
+
- `unique_ptr<T2, D2>::pointer` is implicitly convertible to `CT`.
|
| 6738 |
|
| 6739 |
+
*Preconditions:* The specialization `less<CT>` is a function object
|
| 6740 |
+
type [[function.objects]] that induces a strict weak
|
| 6741 |
+
ordering [[alg.sorting]] on the pointer values.
|
| 6742 |
|
| 6743 |
+
*Returns:* `less<CT>()(x.get(), y.get())`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6744 |
|
| 6745 |
``` cpp
|
| 6746 |
template<class T1, class D1, class T2, class D2>
|
| 6747 |
bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6748 |
```
|
| 6749 |
|
| 6750 |
*Returns:* `y < x`.
|
| 6751 |
|
| 6752 |
+
``` cpp
|
| 6753 |
+
template<class T1, class D1, class T2, class D2>
|
| 6754 |
+
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6755 |
+
```
|
| 6756 |
+
|
| 6757 |
+
*Returns:* `!(y < x)`.
|
| 6758 |
+
|
| 6759 |
``` cpp
|
| 6760 |
template<class T1, class D1, class T2, class D2>
|
| 6761 |
bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6762 |
```
|
| 6763 |
|
| 6764 |
*Returns:* `!(x < y)`.
|
| 6765 |
|
| 6766 |
+
``` cpp
|
| 6767 |
+
template<class T1, class D1, class T2, class D2>
|
| 6768 |
+
requires three_way_comparable_with<typename unique_ptr<T1, D1>::pointer,
|
| 6769 |
+
typename unique_ptr<T2, D2>::pointer>
|
| 6770 |
+
compare_three_way_result_t<typename unique_ptr<T1, D1>::pointer,
|
| 6771 |
+
typename unique_ptr<T2, D2>::pointer>
|
| 6772 |
+
operator<=>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
| 6773 |
+
```
|
| 6774 |
+
|
| 6775 |
+
*Returns:* `compare_three_way()(x.get(), y.get())`.
|
| 6776 |
+
|
| 6777 |
``` cpp
|
| 6778 |
template<class T, class D>
|
| 6779 |
bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
|
|
|
|
|
|
|
| 6780 |
```
|
| 6781 |
|
| 6782 |
*Returns:* `!x`.
|
| 6783 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6784 |
``` cpp
|
| 6785 |
template<class T, class D>
|
| 6786 |
bool operator<(const unique_ptr<T, D>& x, nullptr_t);
|
| 6787 |
template<class T, class D>
|
| 6788 |
bool operator<(nullptr_t, const unique_ptr<T, D>& x);
|
| 6789 |
```
|
| 6790 |
|
| 6791 |
+
*Preconditions:* The specialization `less<unique_ptr<T, D>::pointer>` is
|
| 6792 |
+
a function object type [[function.objects]] that induces a strict weak
|
| 6793 |
+
ordering [[alg.sorting]] on the pointer values.
|
| 6794 |
|
| 6795 |
*Returns:* The first function template returns
|
| 6796 |
+
|
| 6797 |
+
``` cpp
|
| 6798 |
+
less<unique_ptr<T, D>::pointer>()(x.get(), nullptr)
|
| 6799 |
+
```
|
| 6800 |
+
|
| 6801 |
+
The second function template returns
|
| 6802 |
+
|
| 6803 |
+
``` cpp
|
| 6804 |
+
less<unique_ptr<T, D>::pointer>()(nullptr, x.get())
|
| 6805 |
+
```
|
| 6806 |
|
| 6807 |
``` cpp
|
| 6808 |
template<class T, class D>
|
| 6809 |
bool operator>(const unique_ptr<T, D>& x, nullptr_t);
|
| 6810 |
template<class T, class D>
|
|
|
|
| 6832 |
```
|
| 6833 |
|
| 6834 |
*Returns:* The first function template returns `!(x < nullptr)`. The
|
| 6835 |
second function template returns `!(nullptr < x)`.
|
| 6836 |
|
| 6837 |
+
``` cpp
|
| 6838 |
+
template<class T, class D>
|
| 6839 |
+
requires three_way_comparable_with<typename unique_ptr<T, D>::pointer, nullptr_t>
|
| 6840 |
+
compare_three_way_result_t<typename unique_ptr<T, D>::pointer, nullptr_t>
|
| 6841 |
+
operator<=>(const unique_ptr<T, D>& x, nullptr_t);
|
| 6842 |
+
```
|
| 6843 |
|
| 6844 |
+
*Returns:* `compare_three_way()(x.get(), nullptr)`.
|
| 6845 |
+
|
| 6846 |
+
#### I/O <a id="unique.ptr.io">[[unique.ptr.io]]</a>
|
| 6847 |
+
|
| 6848 |
+
``` cpp
|
| 6849 |
+
template<class E, class T, class Y, class D>
|
| 6850 |
+
basic_ostream<E, T>& operator<<(basic_ostream<E, T>& os, const unique_ptr<Y, D>& p);
|
| 6851 |
+
```
|
| 6852 |
+
|
| 6853 |
+
*Constraints:* `os << p.get()` is a valid expression.
|
| 6854 |
+
|
| 6855 |
+
*Effects:* Equivalent to: `os << p.get();`
|
| 6856 |
+
|
| 6857 |
+
*Returns:* `os`.
|
| 6858 |
+
|
| 6859 |
+
### Class `bad_weak_ptr` <a id="util.smartptr.weak.bad">[[util.smartptr.weak.bad]]</a>
|
| 6860 |
|
| 6861 |
``` cpp
|
| 6862 |
namespace std {
|
| 6863 |
class bad_weak_ptr : public exception {
|
| 6864 |
public:
|
| 6865 |
+
// see [exception] for the specification of the special member functions
|
| 6866 |
+
const char* what() const noexcept override;
|
| 6867 |
};
|
| 6868 |
}
|
| 6869 |
```
|
| 6870 |
|
| 6871 |
An exception of type `bad_weak_ptr` is thrown by the `shared_ptr`
|
| 6872 |
constructor taking a `weak_ptr`.
|
| 6873 |
|
| 6874 |
``` cpp
|
| 6875 |
+
const char* what() const noexcept override;
|
| 6876 |
```
|
| 6877 |
|
| 6878 |
+
*Returns:* An *implementation-defined* NTBS.
|
| 6879 |
|
| 6880 |
+
### Class template `shared_ptr` <a id="util.smartptr.shared">[[util.smartptr.shared]]</a>
|
| 6881 |
|
| 6882 |
The `shared_ptr` class template stores a pointer, usually obtained via
|
| 6883 |
`new`. `shared_ptr` implements semantics of shared ownership; the last
|
| 6884 |
remaining owner of the pointer is responsible for destroying the object,
|
| 6885 |
or otherwise releasing the resources associated with the stored pointer.
|
|
|
|
| 6892 |
using element_type = remove_extent_t<T>;
|
| 6893 |
using weak_type = weak_ptr<T>;
|
| 6894 |
|
| 6895 |
// [util.smartptr.shared.const], constructors
|
| 6896 |
constexpr shared_ptr() noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6897 |
constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() { }
|
| 6898 |
+
template<class Y>
|
| 6899 |
+
explicit shared_ptr(Y* p);
|
| 6900 |
+
template<class Y, class D>
|
| 6901 |
+
shared_ptr(Y* p, D d);
|
| 6902 |
+
template<class Y, class D, class A>
|
| 6903 |
+
shared_ptr(Y* p, D d, A a);
|
| 6904 |
+
template<class D>
|
| 6905 |
+
shared_ptr(nullptr_t p, D d);
|
| 6906 |
+
template<class D, class A>
|
| 6907 |
+
shared_ptr(nullptr_t p, D d, A a);
|
| 6908 |
+
template<class Y>
|
| 6909 |
+
shared_ptr(const shared_ptr<Y>& r, element_type* p) noexcept;
|
| 6910 |
+
template<class Y>
|
| 6911 |
+
shared_ptr(shared_ptr<Y>&& r, element_type* p) noexcept;
|
| 6912 |
+
shared_ptr(const shared_ptr& r) noexcept;
|
| 6913 |
+
template<class Y>
|
| 6914 |
+
shared_ptr(const shared_ptr<Y>& r) noexcept;
|
| 6915 |
+
shared_ptr(shared_ptr&& r) noexcept;
|
| 6916 |
+
template<class Y>
|
| 6917 |
+
shared_ptr(shared_ptr<Y>&& r) noexcept;
|
| 6918 |
+
template<class Y>
|
| 6919 |
+
explicit shared_ptr(const weak_ptr<Y>& r);
|
| 6920 |
+
template<class Y, class D>
|
| 6921 |
+
shared_ptr(unique_ptr<Y, D>&& r);
|
| 6922 |
|
| 6923 |
// [util.smartptr.shared.dest], destructor
|
| 6924 |
~shared_ptr();
|
| 6925 |
|
| 6926 |
// [util.smartptr.shared.assign], assignment
|
| 6927 |
shared_ptr& operator=(const shared_ptr& r) noexcept;
|
| 6928 |
+
template<class Y>
|
| 6929 |
+
shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 6930 |
shared_ptr& operator=(shared_ptr&& r) noexcept;
|
| 6931 |
+
template<class Y>
|
| 6932 |
+
shared_ptr& operator=(shared_ptr<Y>&& r) noexcept;
|
| 6933 |
+
template<class Y, class D>
|
| 6934 |
+
shared_ptr& operator=(unique_ptr<Y, D>&& r);
|
| 6935 |
|
| 6936 |
// [util.smartptr.shared.mod], modifiers
|
| 6937 |
void swap(shared_ptr& r) noexcept;
|
| 6938 |
void reset() noexcept;
|
| 6939 |
+
template<class Y>
|
| 6940 |
+
void reset(Y* p);
|
| 6941 |
+
template<class Y, class D>
|
| 6942 |
+
void reset(Y* p, D d);
|
| 6943 |
+
template<class Y, class D, class A>
|
| 6944 |
+
void reset(Y* p, D d, A a);
|
| 6945 |
|
| 6946 |
// [util.smartptr.shared.obs], observers
|
| 6947 |
element_type* get() const noexcept;
|
| 6948 |
T& operator*() const noexcept;
|
| 6949 |
T* operator->() const noexcept;
|
| 6950 |
element_type& operator[](ptrdiff_t i) const;
|
| 6951 |
long use_count() const noexcept;
|
| 6952 |
explicit operator bool() const noexcept;
|
| 6953 |
+
template<class U>
|
| 6954 |
+
bool owner_before(const shared_ptr<U>& b) const noexcept;
|
| 6955 |
+
template<class U>
|
| 6956 |
+
bool owner_before(const weak_ptr<U>& b) const noexcept;
|
| 6957 |
};
|
| 6958 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6959 |
template<class T>
|
| 6960 |
+
shared_ptr(weak_ptr<T>) -> shared_ptr<T>;
|
| 6961 |
+
template<class T, class D>
|
| 6962 |
+
shared_ptr(unique_ptr<T, D>) -> shared_ptr<T>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6963 |
}
|
| 6964 |
```
|
| 6965 |
|
| 6966 |
+
Specializations of `shared_ptr` shall be *Cpp17CopyConstructible*,
|
| 6967 |
+
*Cpp17CopyAssignable*, and *Cpp17LessThanComparable*, allowing their use
|
| 6968 |
+
in standard containers. Specializations of `shared_ptr` shall be
|
| 6969 |
contextually convertible to `bool`, allowing their use in boolean
|
| 6970 |
+
expressions and declarations in conditions.
|
| 6971 |
+
|
| 6972 |
+
The template parameter `T` of `shared_ptr` may be an incomplete type.
|
| 6973 |
+
|
| 6974 |
+
[*Note 1*: `T` may be a function type. — *end note*]
|
| 6975 |
|
| 6976 |
[*Example 1*:
|
| 6977 |
|
| 6978 |
``` cpp
|
| 6979 |
if (shared_ptr<X> px = dynamic_pointer_cast<X>(py)) {
|
|
|
|
| 6987 |
functions shall access and modify only the `shared_ptr` and `weak_ptr`
|
| 6988 |
objects themselves and not objects they refer to. Changes in
|
| 6989 |
`use_count()` do not reflect modifications that can introduce data
|
| 6990 |
races.
|
| 6991 |
|
| 6992 |
+
For the purposes of subclause [[smartptr]], a pointer type `Y*` is said
|
| 6993 |
+
to be *compatible with* a pointer type `T*` when either `Y*` is
|
| 6994 |
convertible to `T*` or `Y` is `U[N]` and `T` is cv `U[]`.
|
| 6995 |
|
| 6996 |
+
#### Constructors <a id="util.smartptr.shared.const">[[util.smartptr.shared.const]]</a>
|
| 6997 |
|
| 6998 |
In the constructor definitions below, enables `shared_from_this` with
|
| 6999 |
`p`, for a pointer `p` of type `Y*`, means that if `Y` has an
|
| 7000 |
unambiguous and accessible base class that is a specialization of
|
| 7001 |
+
`enable_shared_from_this` [[util.smartptr.enab]], then `remove_cv_t<Y>*`
|
| 7002 |
+
shall be implicitly convertible to `T*` and the constructor evaluates
|
| 7003 |
+
the statement:
|
| 7004 |
|
| 7005 |
``` cpp
|
| 7006 |
if (p != nullptr && p->weak_this.expired())
|
| 7007 |
p->weak_this = shared_ptr<remove_cv_t<Y>>(*this, const_cast<remove_cv_t<Y>*>(p));
|
| 7008 |
```
|
| 7009 |
|
| 7010 |
The assignment to the `weak_this` member is not atomic and conflicts
|
| 7011 |
+
with any potentially concurrent access to the same object
|
| 7012 |
+
[[intro.multithread]].
|
| 7013 |
|
| 7014 |
``` cpp
|
| 7015 |
constexpr shared_ptr() noexcept;
|
| 7016 |
```
|
| 7017 |
|
| 7018 |
+
*Ensures:* `use_count() == 0 && get() == nullptr`.
|
|
|
|
|
|
|
| 7019 |
|
| 7020 |
``` cpp
|
| 7021 |
template<class Y> explicit shared_ptr(Y* p);
|
| 7022 |
```
|
| 7023 |
|
| 7024 |
+
*Mandates:* `Y` is a complete type.
|
| 7025 |
+
|
| 7026 |
+
*Constraints:* When `T` is an array type, the expression `delete[] p` is
|
| 7027 |
+
well-formed and either `T` is `U[N]` and `Y(*)[N]` is convertible to
|
| 7028 |
+
`T*`, or `T` is `U[]` and `Y(*)[]` is convertible to `T*`. When `T` is
|
| 7029 |
+
not an array type, the expression `delete p` is well-formed and `Y*` is
|
| 7030 |
+
convertible to `T*`.
|
| 7031 |
+
|
| 7032 |
+
*Preconditions:* The expression `delete[] p`, when `T` is an array type,
|
| 7033 |
+
or `delete p`, when `T` is not an array type, has well-defined behavior,
|
| 7034 |
+
and does not throw exceptions.
|
| 7035 |
|
| 7036 |
*Effects:* When `T` is not an array type, constructs a `shared_ptr`
|
| 7037 |
object that owns the pointer `p`. Otherwise, constructs a `shared_ptr`
|
| 7038 |
that owns `p` and a deleter of an unspecified type that calls
|
| 7039 |
`delete[] p`. When `T` is not an array type, enables `shared_from_this`
|
| 7040 |
with `p`. If an exception is thrown, `delete p` is called when `T` is
|
| 7041 |
not an array type, `delete[] p` otherwise.
|
| 7042 |
|
| 7043 |
+
*Ensures:* `use_count() == 1 && get() == p`.
|
| 7044 |
|
| 7045 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 7046 |
resource other than memory could not be obtained.
|
| 7047 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7048 |
``` cpp
|
| 7049 |
template<class Y, class D> shared_ptr(Y* p, D d);
|
| 7050 |
template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
|
| 7051 |
template<class D> shared_ptr(nullptr_t p, D d);
|
| 7052 |
template<class D, class A> shared_ptr(nullptr_t p, D d, A a);
|
| 7053 |
```
|
| 7054 |
|
| 7055 |
+
*Constraints:* `is_move_constructible_v<D>` is `true`, and `d(p)` is a
|
| 7056 |
+
well-formed expression. For the first two overloads:
|
| 7057 |
+
|
| 7058 |
+
- If `T` is an array type, then either `T` is `U[N]` and `Y(*)[N]` is
|
| 7059 |
+
convertible to `T*`, or `T` is `U[]` and `Y(*)[]` is convertible to
|
| 7060 |
+
`T*`.
|
| 7061 |
+
- If `T` is not an array type, then `Y*` is convertible to `T*`.
|
| 7062 |
+
|
| 7063 |
+
*Preconditions:* Construction of `d` and a deleter of type `D`
|
| 7064 |
+
initialized with `std::move(d)` do not throw exceptions. The expression
|
| 7065 |
+
`d(p)` has well-defined behavior and does not throw exceptions. `A`
|
| 7066 |
+
meets the *Cpp17Allocator* requirements ([[cpp17.allocator]]).
|
| 7067 |
|
| 7068 |
*Effects:* Constructs a `shared_ptr` object that owns the object `p` and
|
| 7069 |
the deleter `d`. When `T` is not an array type, the first and second
|
| 7070 |
constructors enable `shared_from_this` with `p`. The second and fourth
|
| 7071 |
constructors shall use a copy of `a` to allocate memory for internal
|
| 7072 |
use. If an exception is thrown, `d(p)` is called.
|
| 7073 |
|
| 7074 |
+
*Ensures:* `use_count() == 1 && get() == p`.
|
| 7075 |
|
| 7076 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 7077 |
resource other than memory could not be obtained.
|
| 7078 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7079 |
``` cpp
|
| 7080 |
template<class Y> shared_ptr(const shared_ptr<Y>& r, element_type* p) noexcept;
|
| 7081 |
+
template<class Y> shared_ptr(shared_ptr<Y>&& r, element_type* p) noexcept;
|
| 7082 |
```
|
| 7083 |
|
| 7084 |
*Effects:* Constructs a `shared_ptr` instance that stores `p` and shares
|
| 7085 |
+
ownership with the initial value of `r`.
|
| 7086 |
|
| 7087 |
+
*Ensures:* `get() == p`. For the second overload, `r` is empty and
|
| 7088 |
+
`r.get() == nullptr`.
|
| 7089 |
|
| 7090 |
[*Note 1*: To avoid the possibility of a dangling pointer, the user of
|
| 7091 |
+
this constructor should ensure that `p` remains valid at least until the
|
| 7092 |
ownership group of `r` is destroyed. — *end note*]
|
| 7093 |
|
| 7094 |
[*Note 2*: This constructor allows creation of an empty `shared_ptr`
|
| 7095 |
instance with a non-null stored pointer. — *end note*]
|
| 7096 |
|
| 7097 |
``` cpp
|
| 7098 |
shared_ptr(const shared_ptr& r) noexcept;
|
| 7099 |
template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
|
| 7100 |
```
|
| 7101 |
|
| 7102 |
+
*Constraints:* For the second constructor, `Y*` is compatible with `T*`.
|
|
|
|
| 7103 |
|
| 7104 |
*Effects:* If `r` is empty, constructs an empty `shared_ptr` object;
|
| 7105 |
otherwise, constructs a `shared_ptr` object that shares ownership with
|
| 7106 |
`r`.
|
| 7107 |
|
| 7108 |
+
*Ensures:* `get() == r.get() && use_count() == r.use_count()`.
|
| 7109 |
|
| 7110 |
``` cpp
|
| 7111 |
shared_ptr(shared_ptr&& r) noexcept;
|
| 7112 |
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
|
| 7113 |
```
|
| 7114 |
|
| 7115 |
+
*Constraints:* For the second constructor, `Y*` is compatible with `T*`.
|
|
|
|
| 7116 |
|
| 7117 |
*Effects:* Move constructs a `shared_ptr` instance from `r`.
|
| 7118 |
|
| 7119 |
+
*Ensures:* `*this` shall contain the old value of `r`. `r` shall be
|
| 7120 |
+
empty. `r.get() == nullptr`.
|
| 7121 |
|
| 7122 |
``` cpp
|
| 7123 |
template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
|
| 7124 |
```
|
| 7125 |
|
| 7126 |
+
*Constraints:* `Y*` is compatible with `T*`.
|
| 7127 |
+
|
| 7128 |
*Effects:* Constructs a `shared_ptr` object that shares ownership with
|
| 7129 |
`r` and stores a copy of the pointer stored in `r`. If an exception is
|
| 7130 |
thrown, the constructor has no effect.
|
| 7131 |
|
| 7132 |
+
*Ensures:* `use_count() == r.use_count()`.
|
| 7133 |
|
| 7134 |
*Throws:* `bad_weak_ptr` when `r.expired()`.
|
| 7135 |
|
|
|
|
|
|
|
|
|
|
| 7136 |
``` cpp
|
| 7137 |
template<class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
|
| 7138 |
```
|
| 7139 |
|
| 7140 |
+
*Constraints:* `Y*` is compatible with `T*` and
|
| 7141 |
+
`unique_ptr<Y, D>::pointer` is convertible to `element_type*`.
|
|
|
|
| 7142 |
|
| 7143 |
*Effects:* If `r.get() == nullptr`, equivalent to `shared_ptr()`.
|
| 7144 |
Otherwise, if `D` is not a reference type, equivalent to
|
| 7145 |
`shared_ptr(r.release(), r.get_deleter())`. Otherwise, equivalent to
|
| 7146 |
`shared_ptr(r.release(), ref(r.get_deleter()))`. If an exception is
|
| 7147 |
thrown, the constructor has no effect.
|
| 7148 |
|
| 7149 |
+
#### Destructor <a id="util.smartptr.shared.dest">[[util.smartptr.shared.dest]]</a>
|
| 7150 |
|
| 7151 |
``` cpp
|
| 7152 |
~shared_ptr();
|
| 7153 |
```
|
| 7154 |
|
|
|
|
| 7164 |
instances that share ownership with `*this` by one, after `*this` has
|
| 7165 |
been destroyed all `shared_ptr` instances that shared ownership with
|
| 7166 |
`*this` will report a `use_count()` that is one less than its previous
|
| 7167 |
value. — *end note*]
|
| 7168 |
|
| 7169 |
+
#### Assignment <a id="util.smartptr.shared.assign">[[util.smartptr.shared.assign]]</a>
|
| 7170 |
|
| 7171 |
``` cpp
|
| 7172 |
shared_ptr& operator=(const shared_ptr& r) noexcept;
|
| 7173 |
template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 7174 |
```
|
| 7175 |
|
| 7176 |
*Effects:* Equivalent to `shared_ptr(r).swap(*this)`.
|
| 7177 |
|
| 7178 |
*Returns:* `*this`.
|
| 7179 |
|
| 7180 |
+
[*Note 1*:
|
| 7181 |
|
| 7182 |
The use count updates caused by the temporary object construction and
|
| 7183 |
destruction are not observable side effects, so the implementation may
|
| 7184 |
meet the effects (and the implied guarantees) via different means,
|
| 7185 |
without creating a temporary. In particular, in the example:
|
|
|
|
| 7210 |
|
| 7211 |
*Effects:* Equivalent to `shared_ptr(std::move(r)).swap(*this)`.
|
| 7212 |
|
| 7213 |
*Returns:* `*this`.
|
| 7214 |
|
| 7215 |
+
#### Modifiers <a id="util.smartptr.shared.mod">[[util.smartptr.shared.mod]]</a>
|
| 7216 |
|
| 7217 |
``` cpp
|
| 7218 |
void swap(shared_ptr& r) noexcept;
|
| 7219 |
```
|
| 7220 |
|
|
|
|
| 7242 |
template<class Y, class D, class A> void reset(Y* p, D d, A a);
|
| 7243 |
```
|
| 7244 |
|
| 7245 |
*Effects:* Equivalent to `shared_ptr(p, d, a).swap(*this)`.
|
| 7246 |
|
| 7247 |
+
#### Observers <a id="util.smartptr.shared.obs">[[util.smartptr.shared.obs]]</a>
|
| 7248 |
|
| 7249 |
``` cpp
|
| 7250 |
element_type* get() const noexcept;
|
| 7251 |
```
|
| 7252 |
|
|
|
|
| 7254 |
|
| 7255 |
``` cpp
|
| 7256 |
T& operator*() const noexcept;
|
| 7257 |
```
|
| 7258 |
|
| 7259 |
+
*Preconditions:* `get() != 0`.
|
| 7260 |
|
| 7261 |
*Returns:* `*get()`.
|
| 7262 |
|
| 7263 |
*Remarks:* When `T` is an array type or cv `void`, it is unspecified
|
| 7264 |
whether this member function is declared. If it is declared, it is
|
| 7265 |
unspecified what its return type is, except that the declaration
|
| 7266 |
+
(although not necessarily the definition) of the function shall be
|
| 7267 |
+
well-formed.
|
| 7268 |
|
| 7269 |
``` cpp
|
| 7270 |
T* operator->() const noexcept;
|
| 7271 |
```
|
| 7272 |
|
| 7273 |
+
*Preconditions:* `get() != 0`.
|
| 7274 |
|
| 7275 |
*Returns:* `get()`.
|
| 7276 |
|
| 7277 |
*Remarks:* When `T` is an array type, it is unspecified whether this
|
| 7278 |
member function is declared. If it is declared, it is unspecified what
|
| 7279 |
its return type is, except that the declaration (although not
|
| 7280 |
+
necessarily the definition) of the function shall be well-formed.
|
| 7281 |
|
| 7282 |
``` cpp
|
| 7283 |
element_type& operator[](ptrdiff_t i) const;
|
| 7284 |
```
|
| 7285 |
|
| 7286 |
+
*Preconditions:* `get() != 0 && i >= 0`. If `T` is `U[N]`, `i < N`.
|
| 7287 |
|
| 7288 |
*Returns:* `get()[i]`.
|
| 7289 |
|
| 7290 |
*Remarks:* When `T` is not an array type, it is unspecified whether this
|
| 7291 |
member function is declared. If it is declared, it is unspecified what
|
| 7292 |
its return type is, except that the declaration (although not
|
| 7293 |
+
necessarily the definition) of the function shall be well-formed.
|
| 7294 |
|
| 7295 |
*Throws:* Nothing.
|
| 7296 |
|
| 7297 |
``` cpp
|
| 7298 |
long use_count() const noexcept;
|
|
|
|
| 7301 |
*Returns:* The number of `shared_ptr` objects, `*this` included, that
|
| 7302 |
share ownership with `*this`, or `0` when `*this` is empty.
|
| 7303 |
|
| 7304 |
*Synchronization:* None.
|
| 7305 |
|
| 7306 |
+
[*Note 1*: `get() == nullptr` does not imply a specific return value of
|
| 7307 |
`use_count()`. — *end note*]
|
| 7308 |
|
| 7309 |
+
[*Note 2*: `weak_ptr<T>::lock()` can affect the return value of
|
| 7310 |
`use_count()`. — *end note*]
|
| 7311 |
|
| 7312 |
+
[*Note 3*: When multiple threads can affect the return value of
|
| 7313 |
`use_count()`, the result should be treated as approximate. In
|
| 7314 |
particular, `use_count() == 1` does not imply that accesses through a
|
| 7315 |
previously destroyed `shared_ptr` have in any sense
|
| 7316 |
completed. — *end note*]
|
| 7317 |
|
|
|
|
| 7333 |
- under the equivalence relation defined by `owner_before`,
|
| 7334 |
`!a.owner_before(b) && !b.owner_before(a)`, two `shared_ptr` or
|
| 7335 |
`weak_ptr` instances are equivalent if and only if they share
|
| 7336 |
ownership or are both empty.
|
| 7337 |
|
| 7338 |
+
#### Creation <a id="util.smartptr.shared.create">[[util.smartptr.shared.create]]</a>
|
| 7339 |
+
|
| 7340 |
+
The common requirements that apply to all `make_shared`,
|
| 7341 |
+
`allocate_shared`, `make_shared_for_overwrite`, and
|
| 7342 |
+
`allocate_shared_for_overwrite` overloads, unless specified otherwise,
|
| 7343 |
+
are described below.
|
| 7344 |
|
| 7345 |
``` cpp
|
| 7346 |
+
template<class T, ...>
|
| 7347 |
+
shared_ptr<T> make_shared(args);
|
| 7348 |
+
template<class T, class A, ...>
|
| 7349 |
+
shared_ptr<T> allocate_shared(const A& a, args);
|
| 7350 |
+
template<class T, ...>
|
| 7351 |
+
shared_ptr<T> make_shared_for_overwrite(args);
|
| 7352 |
+
template<class T, class A, ...>
|
| 7353 |
+
shared_ptr<T> allocate_shared_for_overwrite(const A& a, args);
|
| 7354 |
```
|
| 7355 |
|
| 7356 |
+
*Preconditions:* `A` meets the *Cpp17Allocator* requirements
|
| 7357 |
+
([[cpp17.allocator]]).
|
|
|
|
|
|
|
|
|
|
| 7358 |
|
| 7359 |
+
*Effects:* Allocates memory for an object of type `T` (or `U[N]` when
|
| 7360 |
+
`T` is `U[]`, where `N` is determined from *args* as specified by the
|
| 7361 |
+
concrete overload). The object is initialized from *args* as specified
|
| 7362 |
+
by the concrete overload. The `allocate_shared` and
|
| 7363 |
+
`allocate_shared_for_overwrite` templates use a copy of `a` (rebound for
|
| 7364 |
+
an unspecified `value_type`) to allocate memory. If an exception is
|
| 7365 |
+
thrown, the functions have no effect.
|
| 7366 |
|
| 7367 |
*Returns:* A `shared_ptr` instance that stores and owns the address of
|
| 7368 |
+
the newly constructed object.
|
| 7369 |
|
| 7370 |
+
*Ensures:* `r.get() != 0 && r.use_count() == 1`, where `r` is the return
|
| 7371 |
+
value.
|
| 7372 |
|
| 7373 |
+
*Throws:* `bad_alloc`, or an exception thrown from `allocate` or from
|
| 7374 |
+
the initialization of the object.
|
| 7375 |
|
| 7376 |
+
*Remarks:*
|
|
|
|
|
|
|
|
|
|
| 7377 |
|
| 7378 |
+
- Implementations should perform no more than one memory allocation.
|
| 7379 |
+
\[*Note 1*: This provides efficiency equivalent to an intrusive smart
|
| 7380 |
pointer. — *end note*]
|
| 7381 |
+
- When an object of an array type `U` is specified to have an initial
|
| 7382 |
+
value of `u` (of the same type), this shall be interpreted to mean
|
| 7383 |
+
that each array element of the object has as its initial value the
|
| 7384 |
+
corresponding element from `u`.
|
| 7385 |
+
- When an object of an array type is specified to have a default initial
|
| 7386 |
+
value, this shall be interpreted to mean that each array element of
|
| 7387 |
+
the object has a default initial value.
|
| 7388 |
+
- When a (sub)object of a non-array type `U` is specified to have an
|
| 7389 |
+
initial value of `v`, or `U(l...)`, where `l...` is a list of
|
| 7390 |
+
constructor arguments, `make_shared` shall initialize this (sub)object
|
| 7391 |
+
via the expression `::new(pv) U(v)` or `::new(pv) U(l...)`
|
| 7392 |
+
respectively, where `pv` has type `void*` and points to storage
|
| 7393 |
+
suitable to hold an object of type `U`.
|
| 7394 |
+
- When a (sub)object of a non-array type `U` is specified to have an
|
| 7395 |
+
initial value of `v`, or `U(l...)`, where `l...` is a list of
|
| 7396 |
+
constructor arguments, `allocate_shared` shall initialize this
|
| 7397 |
+
(sub)object via the expression
|
| 7398 |
+
- `allocator_traits<A2>::construct(a2, pv, v)` or
|
| 7399 |
+
- `allocator_traits<A2>::construct(a2, pv, l...)`
|
| 7400 |
|
| 7401 |
+
respectively, where `pv` points to storage suitable to hold an object
|
| 7402 |
+
of type `U` and `a2` of type `A2` is a rebound copy of the allocator
|
| 7403 |
+
`a` passed to `allocate_shared` such that its `value_type` is
|
| 7404 |
+
`remove_cv_t<U>`.
|
| 7405 |
+
- When a (sub)object of non-array type `U` is specified to have a
|
| 7406 |
+
default initial value, `make_shared` shall initialize this (sub)object
|
| 7407 |
+
via the expression `::new(pv) U()`, where `pv` has type `void*` and
|
| 7408 |
+
points to storage suitable to hold an object of type `U`.
|
| 7409 |
+
- When a (sub)object of non-array type `U` is specified to have a
|
| 7410 |
+
default initial value, `allocate_shared` shall initialize this
|
| 7411 |
+
(sub)object via the expression
|
| 7412 |
+
`allocator_traits<A2>::construct(a2, pv)`, where `pv` points to
|
| 7413 |
+
storage suitable to hold an object of type `U` and `a2` of type `A2`
|
| 7414 |
+
is a rebound copy of the allocator `a` passed to `allocate_shared`
|
| 7415 |
+
such that its `value_type` is `remove_cv_t<U>`.
|
| 7416 |
+
- When a (sub)object of non-array type `U` is initialized by
|
| 7417 |
+
`make_shared_for_overwrite` or `allocate_shared_for_overwrite`, it is
|
| 7418 |
+
initialized via the expression `::new(pv) U`, where `pv` has type
|
| 7419 |
+
`void*` and points to storage suitable to hold an object of type `U`.
|
| 7420 |
+
- Array elements are initialized in ascending order of their addresses.
|
| 7421 |
+
- When the lifetime of the object managed by the return value ends, or
|
| 7422 |
+
when the initialization of an array element throws an exception, the
|
| 7423 |
+
initialized elements are destroyed in the reverse order of their
|
| 7424 |
+
original construction.
|
| 7425 |
+
- When a (sub)object of non-array type `U` that was initialized by
|
| 7426 |
+
`make_shared` is to be destroyed, it is destroyed via the expression
|
| 7427 |
+
`pv->~U()` where `pv` points to that object of type `U`.
|
| 7428 |
+
- When a (sub)object of non-array type `U` that was initialized by
|
| 7429 |
+
`allocate_shared` is to be destroyed, it is destroyed via the
|
| 7430 |
+
expression `allocator_traits<A2>::destroy(a2, pv)` where `pv` points
|
| 7431 |
+
to that object of type `remove_cv_t<U>` and `a2` of type `A2` is a
|
| 7432 |
+
rebound copy of the allocator `a` passed to `allocate_shared` such
|
| 7433 |
+
that its `value_type` is `remove_cv_t<U>`.
|
| 7434 |
+
|
| 7435 |
+
[*Note 1*: These functions will typically allocate more memory than
|
| 7436 |
+
`sizeof(T)` to allow for internal bookkeeping structures such as
|
| 7437 |
reference counts. — *end note*]
|
| 7438 |
|
| 7439 |
+
``` cpp
|
| 7440 |
+
template<class T, class... Args>
|
| 7441 |
+
shared_ptr<T> make_shared(Args&&... args); // T is not array
|
| 7442 |
+
template<class T, class A, class... Args>
|
| 7443 |
+
shared_ptr<T> allocate_shared(const A& a, Args&&... args); // T is not array
|
| 7444 |
+
```
|
| 7445 |
+
|
| 7446 |
+
*Constraints:* `T` is not an array type.
|
| 7447 |
+
|
| 7448 |
+
*Returns:* A `shared_ptr` to an object of type `T` with an initial value
|
| 7449 |
+
`T(forward<Args>(args)...)`.
|
| 7450 |
+
|
| 7451 |
+
*Remarks:* The `shared_ptr` constructors called by these functions
|
| 7452 |
+
enable `shared_from_this` with the address of the newly constructed
|
| 7453 |
+
object of type `T`.
|
| 7454 |
+
|
| 7455 |
+
[*Example 1*:
|
| 7456 |
+
|
| 7457 |
+
``` cpp
|
| 7458 |
+
shared_ptr<int> p = make_shared<int>(); // shared_ptr to int()
|
| 7459 |
+
shared_ptr<vector<int>> q = make_shared<vector<int>>(16, 1);
|
| 7460 |
+
// shared_ptr to vector of 16 elements with value 1
|
| 7461 |
+
```
|
| 7462 |
+
|
| 7463 |
+
— *end example*]
|
| 7464 |
+
|
| 7465 |
+
``` cpp
|
| 7466 |
+
template<class T> shared_ptr<T>
|
| 7467 |
+
make_shared(size_t N); // T is U[]
|
| 7468 |
+
template<class T, class A>
|
| 7469 |
+
shared_ptr<T> allocate_shared(const A& a, size_t N); // T is U[]
|
| 7470 |
+
```
|
| 7471 |
+
|
| 7472 |
+
*Constraints:* `T` is of the form `U[]`.
|
| 7473 |
+
|
| 7474 |
+
*Returns:* A `shared_ptr` to an object of type `U[N]` with a default
|
| 7475 |
+
initial value, where `U` is `remove_extent_t<T>`.
|
| 7476 |
+
|
| 7477 |
+
[*Example 2*:
|
| 7478 |
+
|
| 7479 |
+
``` cpp
|
| 7480 |
+
shared_ptr<double[]> p = make_shared<double[]>(1024);
|
| 7481 |
+
// shared_ptr to a value-initialized double[1024]
|
| 7482 |
+
shared_ptr<double[][2][2]> q = make_shared<double[][2][2]>(6);
|
| 7483 |
+
// shared_ptr to a value-initialized double[6][2][2]
|
| 7484 |
+
```
|
| 7485 |
+
|
| 7486 |
+
— *end example*]
|
| 7487 |
+
|
| 7488 |
+
``` cpp
|
| 7489 |
+
template<class T>
|
| 7490 |
+
shared_ptr<T> make_shared(); // T is U[N]
|
| 7491 |
+
template<class T, class A>
|
| 7492 |
+
shared_ptr<T> allocate_shared(const A& a); // T is U[N]
|
| 7493 |
+
```
|
| 7494 |
+
|
| 7495 |
+
*Constraints:* `T` is of the form `U[N]`.
|
| 7496 |
+
|
| 7497 |
+
*Returns:* A `shared_ptr` to an object of type `T` with a default
|
| 7498 |
+
initial value.
|
| 7499 |
+
|
| 7500 |
+
[*Example 3*:
|
| 7501 |
+
|
| 7502 |
+
``` cpp
|
| 7503 |
+
shared_ptr<double[1024]> p = make_shared<double[1024]>();
|
| 7504 |
+
// shared_ptr to a value-initialized double[1024]
|
| 7505 |
+
shared_ptr<double[6][2][2]> q = make_shared<double[6][2][2]>();
|
| 7506 |
+
// shared_ptr to a value-initialized double[6][2][2]
|
| 7507 |
+
```
|
| 7508 |
+
|
| 7509 |
+
— *end example*]
|
| 7510 |
+
|
| 7511 |
+
``` cpp
|
| 7512 |
+
template<class T>
|
| 7513 |
+
shared_ptr<T> make_shared(size_t N,
|
| 7514 |
+
const remove_extent_t<T>& u); // T is U[]
|
| 7515 |
+
template<class T, class A>
|
| 7516 |
+
shared_ptr<T> allocate_shared(const A& a, size_t N,
|
| 7517 |
+
const remove_extent_t<T>& u); // T is U[]
|
| 7518 |
+
```
|
| 7519 |
+
|
| 7520 |
+
*Constraints:* `T` is of the form `U[]`.
|
| 7521 |
+
|
| 7522 |
+
*Returns:* A `shared_ptr` to an object of type `U[N]`, where `U` is
|
| 7523 |
+
`remove_extent_t<T>` and each array element has an initial value of `u`.
|
| 7524 |
+
|
| 7525 |
+
[*Example 4*:
|
| 7526 |
+
|
| 7527 |
+
``` cpp
|
| 7528 |
+
shared_ptr<double[]> p = make_shared<double[]>(1024, 1.0);
|
| 7529 |
+
// shared_ptr to a double[1024], where each element is 1.0
|
| 7530 |
+
shared_ptr<double[][2]> q = make_shared<double[][2]>(6, {1.0, 0.0});
|
| 7531 |
+
// shared_ptr to a double[6][2], where each double[2] element is {1.0, 0.0}
|
| 7532 |
+
shared_ptr<vector<int>[]> r = make_shared<vector<int>[]>(4, {1, 2});
|
| 7533 |
+
// shared_ptr to a vector<int>[4], where each vector has contents {1, 2}
|
| 7534 |
+
```
|
| 7535 |
+
|
| 7536 |
+
— *end example*]
|
| 7537 |
+
|
| 7538 |
+
``` cpp
|
| 7539 |
+
template<class T>
|
| 7540 |
+
shared_ptr<T> make_shared(const remove_extent_t<T>& u); // T is U[N]
|
| 7541 |
+
template<class T, class A>
|
| 7542 |
+
shared_ptr<T> allocate_shared(const A& a,
|
| 7543 |
+
const remove_extent_t<T>& u); // T is U[N]
|
| 7544 |
+
```
|
| 7545 |
+
|
| 7546 |
+
*Constraints:* `T` is of the form `U[N]`.
|
| 7547 |
+
|
| 7548 |
+
*Returns:* A `shared_ptr` to an object of type `T`, where each array
|
| 7549 |
+
element of type `remove_extent_t<T>` has an initial value of `u`.
|
| 7550 |
+
|
| 7551 |
+
[*Example 5*:
|
| 7552 |
+
|
| 7553 |
+
``` cpp
|
| 7554 |
+
shared_ptr<double[1024]> p = make_shared<double[1024]>(1.0);
|
| 7555 |
+
// shared_ptr to a double[1024], where each element is 1.0
|
| 7556 |
+
shared_ptr<double[6][2]> q = make_shared<double[6][2]>({1.0, 0.0});
|
| 7557 |
+
// shared_ptr to a double[6][2], where each double[2] element is {1.0, 0.0}
|
| 7558 |
+
shared_ptr<vector<int>[4]> r = make_shared<vector<int>[4]>({1, 2});
|
| 7559 |
+
// shared_ptr to a vector<int>[4], where each vector has contents {1, 2}
|
| 7560 |
+
```
|
| 7561 |
+
|
| 7562 |
+
— *end example*]
|
| 7563 |
+
|
| 7564 |
+
``` cpp
|
| 7565 |
+
template<class T>
|
| 7566 |
+
shared_ptr<T> make_shared_for_overwrite();
|
| 7567 |
+
template<class T, class A>
|
| 7568 |
+
shared_ptr<T> allocate_shared_for_overwrite(const A& a);
|
| 7569 |
+
```
|
| 7570 |
+
|
| 7571 |
+
*Constraints:* `T` is not an array of unknown bound.
|
| 7572 |
+
|
| 7573 |
+
*Returns:* A `shared_ptr` to an object of type `T`.
|
| 7574 |
+
|
| 7575 |
+
[*Example 6*:
|
| 7576 |
+
|
| 7577 |
+
``` cpp
|
| 7578 |
+
struct X { double data[1024]; };
|
| 7579 |
+
shared_ptr<X> p = make_shared_for_overwrite<X>();
|
| 7580 |
+
// shared_ptr to a default-initialized X, where each element in X::data has an indeterminate value
|
| 7581 |
+
|
| 7582 |
+
shared_ptr<double[1024]> q = make_shared_for_overwrite<double[1024]>();
|
| 7583 |
+
// shared_ptr to a default-initialized double[1024], where each element has an indeterminate value
|
| 7584 |
+
```
|
| 7585 |
+
|
| 7586 |
+
— *end example*]
|
| 7587 |
+
|
| 7588 |
+
``` cpp
|
| 7589 |
+
template<class T>
|
| 7590 |
+
shared_ptr<T> make_shared_for_overwrite(size_t N);
|
| 7591 |
+
template<class T, class A>
|
| 7592 |
+
shared_ptr<T> allocate_shared_for_overwrite(const A& a, size_t N);
|
| 7593 |
+
```
|
| 7594 |
+
|
| 7595 |
+
*Constraints:* `T` is an array of unknown bound.
|
| 7596 |
+
|
| 7597 |
+
*Returns:* A `shared_ptr` to an object of type `U[N]`, where `U` is
|
| 7598 |
+
`remove_extent_t<T>`.
|
| 7599 |
+
|
| 7600 |
+
[*Example 7*:
|
| 7601 |
+
|
| 7602 |
+
``` cpp
|
| 7603 |
+
shared_ptr<double[]> p = make_shared_for_overwrite<double[]>(1024);
|
| 7604 |
+
// shared_ptr to a default-initialized double[1024], where each element has an indeterminate value
|
| 7605 |
+
```
|
| 7606 |
+
|
| 7607 |
+
— *end example*]
|
| 7608 |
+
|
| 7609 |
+
#### Comparison <a id="util.smartptr.shared.cmp">[[util.smartptr.shared.cmp]]</a>
|
| 7610 |
|
| 7611 |
``` cpp
|
| 7612 |
template<class T, class U>
|
| 7613 |
bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
| 7614 |
```
|
| 7615 |
|
| 7616 |
*Returns:* `a.get() == b.get()`.
|
| 7617 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7618 |
``` cpp
|
| 7619 |
template<class T>
|
| 7620 |
bool operator==(const shared_ptr<T>& a, nullptr_t) noexcept;
|
|
|
|
|
|
|
| 7621 |
```
|
| 7622 |
|
| 7623 |
*Returns:* `!a`.
|
| 7624 |
|
| 7625 |
``` cpp
|
| 7626 |
+
template<class T, class U>
|
| 7627 |
+
strong_ordering operator<=>(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7628 |
```
|
| 7629 |
|
| 7630 |
+
*Returns:* `compare_three_way()(a.get(), b.get())`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7631 |
|
| 7632 |
+
[*Note 1*: Defining a comparison function allows `shared_ptr` objects
|
| 7633 |
+
to be used as keys in associative containers. — *end note*]
|
| 7634 |
|
| 7635 |
``` cpp
|
| 7636 |
template<class T>
|
| 7637 |
+
strong_ordering operator<=>(const shared_ptr<T>& a, nullptr_t) noexcept;
|
|
|
|
|
|
|
| 7638 |
```
|
| 7639 |
|
| 7640 |
+
*Returns:* `compare_three_way()(a.get(), nullptr)`.
|
|
|
|
| 7641 |
|
| 7642 |
+
#### Specialized algorithms <a id="util.smartptr.shared.spec">[[util.smartptr.shared.spec]]</a>
|
| 7643 |
|
| 7644 |
``` cpp
|
| 7645 |
template<class T>
|
| 7646 |
void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
|
| 7647 |
```
|
| 7648 |
|
| 7649 |
*Effects:* Equivalent to `a.swap(b)`.
|
| 7650 |
|
| 7651 |
+
#### Casts <a id="util.smartptr.shared.cast">[[util.smartptr.shared.cast]]</a>
|
| 7652 |
|
| 7653 |
``` cpp
|
| 7654 |
template<class T, class U>
|
| 7655 |
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7656 |
+
template<class T, class U>
|
| 7657 |
+
shared_ptr<T> static_pointer_cast(shared_ptr<U>&& r) noexcept;
|
| 7658 |
```
|
| 7659 |
|
| 7660 |
+
*Mandates:* The expression `static_cast<T*>((U*)nullptr)` is
|
| 7661 |
+
well-formed.
|
| 7662 |
|
| 7663 |
*Returns:*
|
| 7664 |
|
| 7665 |
``` cpp
|
| 7666 |
+
shared_ptr<T>(R, static_cast<typename shared_ptr<T>::element_type*>(r.get()))
|
| 7667 |
```
|
| 7668 |
|
| 7669 |
+
where *`R`* is `r` for the first overload, and `std::move(r)` for the
|
| 7670 |
+
second.
|
| 7671 |
+
|
| 7672 |
+
[*Note 1*: The seemingly equivalent expression
|
| 7673 |
`shared_ptr<T>(static_cast<T*>(r.get()))` will eventually result in
|
| 7674 |
undefined behavior, attempting to delete the same object
|
| 7675 |
twice. — *end note*]
|
| 7676 |
|
| 7677 |
``` cpp
|
| 7678 |
template<class T, class U>
|
| 7679 |
shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7680 |
+
template<class T, class U>
|
| 7681 |
+
shared_ptr<T> dynamic_pointer_cast(shared_ptr<U>&& r) noexcept;
|
| 7682 |
```
|
| 7683 |
|
| 7684 |
+
*Mandates:* The expression `dynamic_cast<T*>((U*)nullptr)` is
|
| 7685 |
+
well-formed. The expression
|
| 7686 |
+
`dynamic_cast<typename shared_ptr<T>::element_type*>(r.get())` is well
|
| 7687 |
+
formed.
|
| 7688 |
+
|
| 7689 |
+
*Preconditions:* The expression
|
| 7690 |
+
`dynamic_cast<typename shared_ptr<T>::element_type*>(r.get())` has
|
| 7691 |
+
well-defined behavior.
|
| 7692 |
|
| 7693 |
*Returns:*
|
| 7694 |
|
| 7695 |
- When `dynamic_cast<typename shared_ptr<T>::element_type*>(r.get())`
|
| 7696 |
+
returns a non-null value `p`, `shared_ptr<T>(`*`R`*`, p)`, where *`R`*
|
| 7697 |
+
is `r` for the first overload, and `std::move(r)` for the second.
|
| 7698 |
- Otherwise, `shared_ptr<T>()`.
|
| 7699 |
|
| 7700 |
+
[*Note 2*: The seemingly equivalent expression
|
| 7701 |
`shared_ptr<T>(dynamic_cast<T*>(r.get()))` will eventually result in
|
| 7702 |
undefined behavior, attempting to delete the same object
|
| 7703 |
twice. — *end note*]
|
| 7704 |
|
| 7705 |
``` cpp
|
| 7706 |
template<class T, class U>
|
| 7707 |
shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7708 |
+
template<class T, class U>
|
| 7709 |
+
shared_ptr<T> const_pointer_cast(shared_ptr<U>&& r) noexcept;
|
| 7710 |
```
|
| 7711 |
|
| 7712 |
+
*Mandates:* The expression `const_cast<T*>((U*)nullptr)` is well-formed.
|
| 7713 |
|
| 7714 |
*Returns:*
|
| 7715 |
|
| 7716 |
``` cpp
|
| 7717 |
+
shared_ptr<T>(R, const_cast<typename shared_ptr<T>::element_type*>(r.get()))
|
| 7718 |
```
|
| 7719 |
|
| 7720 |
+
where *`R`* is `r` for the first overload, and `std::move(r)` for the
|
| 7721 |
+
second.
|
| 7722 |
+
|
| 7723 |
+
[*Note 3*: The seemingly equivalent expression
|
| 7724 |
`shared_ptr<T>(const_cast<T*>(r.get()))` will eventually result in
|
| 7725 |
undefined behavior, attempting to delete the same object
|
| 7726 |
twice. — *end note*]
|
| 7727 |
|
| 7728 |
``` cpp
|
| 7729 |
template<class T, class U>
|
| 7730 |
shared_ptr<T> reinterpret_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 7731 |
+
template<class T, class U>
|
| 7732 |
+
shared_ptr<T> reinterpret_pointer_cast(shared_ptr<U>&& r) noexcept;
|
| 7733 |
```
|
| 7734 |
|
| 7735 |
+
*Mandates:* The expression `reinterpret_cast<T*>((U*)nullptr)` is
|
| 7736 |
+
well-formed.
|
| 7737 |
|
| 7738 |
*Returns:*
|
| 7739 |
|
| 7740 |
``` cpp
|
| 7741 |
+
shared_ptr<T>(R, reinterpret_cast<typename shared_ptr<T>::element_type*>(r.get()))
|
| 7742 |
```
|
| 7743 |
|
| 7744 |
+
where *`R`* is `r` for the first overload, and `std::move(r)` for the
|
| 7745 |
+
second.
|
| 7746 |
+
|
| 7747 |
+
[*Note 4*: The seemingly equivalent expression
|
| 7748 |
`shared_ptr<T>(reinterpret_cast<T*>(r.get()))` will eventually result in
|
| 7749 |
undefined behavior, attempting to delete the same object
|
| 7750 |
twice. — *end note*]
|
| 7751 |
|
| 7752 |
+
#### `get_deleter` <a id="util.smartptr.getdeleter">[[util.smartptr.getdeleter]]</a>
|
| 7753 |
|
| 7754 |
``` cpp
|
| 7755 |
template<class D, class T>
|
| 7756 |
D* get_deleter(const shared_ptr<T>& p) noexcept;
|
| 7757 |
```
|
|
|
|
| 7759 |
*Returns:* If `p` owns a deleter `d` of type cv-unqualified `D`, returns
|
| 7760 |
`addressof(d)`; otherwise returns `nullptr`. The returned pointer
|
| 7761 |
remains valid as long as there exists a `shared_ptr` instance that owns
|
| 7762 |
`d`.
|
| 7763 |
|
| 7764 |
+
[*Note 1*: It is unspecified whether the pointer remains valid longer
|
| 7765 |
than that. This can happen if the implementation doesn’t destroy the
|
| 7766 |
deleter until all `weak_ptr` instances that share ownership with `p`
|
| 7767 |
have been destroyed. — *end note*]
|
| 7768 |
|
| 7769 |
+
#### I/O <a id="util.smartptr.shared.io">[[util.smartptr.shared.io]]</a>
|
| 7770 |
|
| 7771 |
``` cpp
|
| 7772 |
template<class E, class T, class Y>
|
| 7773 |
basic_ostream<E, T>& operator<<(basic_ostream<E, T>& os, const shared_ptr<Y>& p);
|
| 7774 |
```
|
| 7775 |
|
| 7776 |
*Effects:* As if by: `os << p.get();`
|
| 7777 |
|
| 7778 |
*Returns:* `os`.
|
| 7779 |
|
| 7780 |
+
### Class template `weak_ptr` <a id="util.smartptr.weak">[[util.smartptr.weak]]</a>
|
| 7781 |
|
| 7782 |
The `weak_ptr` class template stores a weak reference to an object that
|
| 7783 |
is already managed by a `shared_ptr`. To access the object, a `weak_ptr`
|
| 7784 |
can be converted to a `shared_ptr` using the member function `lock`.
|
| 7785 |
|
| 7786 |
``` cpp
|
| 7787 |
namespace std {
|
| 7788 |
template<class T> class weak_ptr {
|
| 7789 |
public:
|
| 7790 |
+
using element_type = remove_extent_t<T>;
|
| 7791 |
|
| 7792 |
// [util.smartptr.weak.const], constructors
|
| 7793 |
constexpr weak_ptr() noexcept;
|
| 7794 |
+
template<class Y>
|
| 7795 |
+
weak_ptr(const shared_ptr<Y>& r) noexcept;
|
| 7796 |
weak_ptr(const weak_ptr& r) noexcept;
|
| 7797 |
+
template<class Y>
|
| 7798 |
+
weak_ptr(const weak_ptr<Y>& r) noexcept;
|
| 7799 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 7800 |
+
template<class Y>
|
| 7801 |
+
weak_ptr(weak_ptr<Y>&& r) noexcept;
|
| 7802 |
|
| 7803 |
// [util.smartptr.weak.dest], destructor
|
| 7804 |
~weak_ptr();
|
| 7805 |
|
| 7806 |
// [util.smartptr.weak.assign], assignment
|
| 7807 |
weak_ptr& operator=(const weak_ptr& r) noexcept;
|
| 7808 |
+
template<class Y>
|
| 7809 |
+
weak_ptr& operator=(const weak_ptr<Y>& r) noexcept;
|
| 7810 |
+
template<class Y>
|
| 7811 |
+
weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 7812 |
weak_ptr& operator=(weak_ptr&& r) noexcept;
|
| 7813 |
+
template<class Y>
|
| 7814 |
+
weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
|
| 7815 |
|
| 7816 |
// [util.smartptr.weak.mod], modifiers
|
| 7817 |
void swap(weak_ptr& r) noexcept;
|
| 7818 |
void reset() noexcept;
|
| 7819 |
|
| 7820 |
// [util.smartptr.weak.obs], observers
|
| 7821 |
long use_count() const noexcept;
|
| 7822 |
bool expired() const noexcept;
|
| 7823 |
shared_ptr<T> lock() const noexcept;
|
| 7824 |
+
template<class U>
|
| 7825 |
+
bool owner_before(const shared_ptr<U>& b) const noexcept;
|
| 7826 |
+
template<class U>
|
| 7827 |
+
bool owner_before(const weak_ptr<U>& b) const noexcept;
|
| 7828 |
};
|
| 7829 |
|
| 7830 |
+
template<class T>
|
| 7831 |
+
weak_ptr(shared_ptr<T>) -> weak_ptr<T>;
|
| 7832 |
|
| 7833 |
// [util.smartptr.weak.spec], specialized algorithms
|
| 7834 |
+
template<class T>
|
| 7835 |
+
void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
| 7836 |
}
|
| 7837 |
```
|
| 7838 |
|
| 7839 |
+
Specializations of `weak_ptr` shall be *Cpp17CopyConstructible* and
|
| 7840 |
+
*Cpp17CopyAssignable*, allowing their use in standard containers. The
|
| 7841 |
template parameter `T` of `weak_ptr` may be an incomplete type.
|
| 7842 |
|
| 7843 |
+
#### Constructors <a id="util.smartptr.weak.const">[[util.smartptr.weak.const]]</a>
|
| 7844 |
|
| 7845 |
``` cpp
|
| 7846 |
constexpr weak_ptr() noexcept;
|
| 7847 |
```
|
| 7848 |
|
| 7849 |
*Effects:* Constructs an empty `weak_ptr` object.
|
| 7850 |
|
| 7851 |
+
*Ensures:* `use_count() == 0`.
|
| 7852 |
|
| 7853 |
``` cpp
|
| 7854 |
weak_ptr(const weak_ptr& r) noexcept;
|
| 7855 |
template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
|
| 7856 |
template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
|
| 7857 |
```
|
| 7858 |
|
| 7859 |
+
*Constraints:* For the second and third constructors, `Y*` is compatible
|
| 7860 |
+
with `T*`.
|
| 7861 |
|
| 7862 |
*Effects:* If `r` is empty, constructs an empty `weak_ptr` object;
|
| 7863 |
otherwise, constructs a `weak_ptr` object that shares ownership with `r`
|
| 7864 |
and stores a copy of the pointer stored in `r`.
|
| 7865 |
|
| 7866 |
+
*Ensures:* `use_count() == r.use_count()`.
|
| 7867 |
|
| 7868 |
``` cpp
|
| 7869 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 7870 |
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
|
| 7871 |
```
|
| 7872 |
|
| 7873 |
+
*Constraints:* For the second constructor, `Y*` is compatible with `T*`.
|
|
|
|
| 7874 |
|
| 7875 |
*Effects:* Move constructs a `weak_ptr` instance from `r`.
|
| 7876 |
|
| 7877 |
+
*Ensures:* `*this` shall contain the old value of `r`. `r` shall be
|
| 7878 |
+
empty. `r.use_count() == 0`.
|
| 7879 |
|
| 7880 |
+
#### Destructor <a id="util.smartptr.weak.dest">[[util.smartptr.weak.dest]]</a>
|
| 7881 |
|
| 7882 |
``` cpp
|
| 7883 |
~weak_ptr();
|
| 7884 |
```
|
| 7885 |
|
| 7886 |
*Effects:* Destroys this `weak_ptr` object but has no effect on the
|
| 7887 |
object its stored pointer points to.
|
| 7888 |
|
| 7889 |
+
#### Assignment <a id="util.smartptr.weak.assign">[[util.smartptr.weak.assign]]</a>
|
| 7890 |
|
| 7891 |
``` cpp
|
| 7892 |
weak_ptr& operator=(const weak_ptr& r) noexcept;
|
| 7893 |
template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r) noexcept;
|
| 7894 |
template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 7895 |
```
|
| 7896 |
|
| 7897 |
*Effects:* Equivalent to `weak_ptr(r).swap(*this)`.
|
| 7898 |
|
| 7899 |
*Remarks:* The implementation may meet the effects (and the implied
|
| 7900 |
+
guarantees) via different means, without creating a temporary object.
|
| 7901 |
|
| 7902 |
*Returns:* `*this`.
|
| 7903 |
|
| 7904 |
``` cpp
|
| 7905 |
weak_ptr& operator=(weak_ptr&& r) noexcept;
|
|
|
|
| 7908 |
|
| 7909 |
*Effects:* Equivalent to `weak_ptr(std::move(r)).swap(*this)`.
|
| 7910 |
|
| 7911 |
*Returns:* `*this`.
|
| 7912 |
|
| 7913 |
+
#### Modifiers <a id="util.smartptr.weak.mod">[[util.smartptr.weak.mod]]</a>
|
| 7914 |
|
| 7915 |
``` cpp
|
| 7916 |
void swap(weak_ptr& r) noexcept;
|
| 7917 |
```
|
| 7918 |
|
|
|
|
| 7922 |
void reset() noexcept;
|
| 7923 |
```
|
| 7924 |
|
| 7925 |
*Effects:* Equivalent to `weak_ptr().swap(*this)`.
|
| 7926 |
|
| 7927 |
+
#### Observers <a id="util.smartptr.weak.obs">[[util.smartptr.weak.obs]]</a>
|
| 7928 |
|
| 7929 |
``` cpp
|
| 7930 |
long use_count() const noexcept;
|
| 7931 |
```
|
| 7932 |
|
|
|
|
| 7945 |
|
| 7946 |
*Returns:* `expired() ? shared_ptr<T>() : shared_ptr<T>(*this)`,
|
| 7947 |
executed atomically.
|
| 7948 |
|
| 7949 |
``` cpp
|
| 7950 |
+
template<class U> bool owner_before(const shared_ptr<U>& b) const noexcept;
|
| 7951 |
+
template<class U> bool owner_before(const weak_ptr<U>& b) const noexcept;
|
| 7952 |
```
|
| 7953 |
|
| 7954 |
*Returns:* An unspecified value such that
|
| 7955 |
|
| 7956 |
- `x.owner_before(y)` defines a strict weak ordering as defined
|
|
|
|
| 7958 |
- under the equivalence relation defined by `owner_before`,
|
| 7959 |
`!a.owner_before(b) && !b.owner_before(a)`, two `shared_ptr` or
|
| 7960 |
`weak_ptr` instances are equivalent if and only if they share
|
| 7961 |
ownership or are both empty.
|
| 7962 |
|
| 7963 |
+
#### Specialized algorithms <a id="util.smartptr.weak.spec">[[util.smartptr.weak.spec]]</a>
|
| 7964 |
|
| 7965 |
``` cpp
|
| 7966 |
template<class T>
|
| 7967 |
void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
| 7968 |
```
|
| 7969 |
|
| 7970 |
*Effects:* Equivalent to `a.swap(b)`.
|
| 7971 |
|
| 7972 |
+
### Class template `owner_less` <a id="util.smartptr.ownerless">[[util.smartptr.ownerless]]</a>
|
| 7973 |
|
| 7974 |
The class template `owner_less` allows ownership-based mixed comparisons
|
| 7975 |
of shared and weak pointers.
|
| 7976 |
|
| 7977 |
``` cpp
|
|
|
|
| 8003 |
using is_transparent = unspecified;
|
| 8004 |
};
|
| 8005 |
}
|
| 8006 |
```
|
| 8007 |
|
| 8008 |
+
`operator()(x, y)` returns `x.owner_before(y)`.
|
| 8009 |
|
| 8010 |
[*Note 1*:
|
| 8011 |
|
| 8012 |
Note that
|
| 8013 |
|
|
|
|
| 8018 |
`weak_ptr` instances are equivalent if and only if they share
|
| 8019 |
ownership or are both empty.
|
| 8020 |
|
| 8021 |
— *end note*]
|
| 8022 |
|
| 8023 |
+
### Class template `enable_shared_from_this` <a id="util.smartptr.enab">[[util.smartptr.enab]]</a>
|
| 8024 |
|
| 8025 |
A class `T` can inherit from `enable_shared_from_this<T>` to inherit the
|
| 8026 |
`shared_from_this` member functions that obtain a `shared_ptr` instance
|
| 8027 |
pointing to `*this`.
|
| 8028 |
|
|
|
|
| 8047 |
protected:
|
| 8048 |
constexpr enable_shared_from_this() noexcept;
|
| 8049 |
enable_shared_from_this(const enable_shared_from_this&) noexcept;
|
| 8050 |
enable_shared_from_this& operator=(const enable_shared_from_this&) noexcept;
|
| 8051 |
~enable_shared_from_this();
|
| 8052 |
+
|
| 8053 |
public:
|
| 8054 |
shared_ptr<T> shared_from_this();
|
| 8055 |
shared_ptr<T const> shared_from_this() const;
|
| 8056 |
weak_ptr<T> weak_from_this() noexcept;
|
| 8057 |
weak_ptr<T const> weak_from_this() const noexcept;
|
| 8058 |
+
|
| 8059 |
private:
|
| 8060 |
mutable weak_ptr<T> weak_this; // exposition only
|
| 8061 |
};
|
| 8062 |
}
|
| 8063 |
```
|
|
|
|
| 8092 |
weak_ptr<T const> weak_from_this() const noexcept;
|
| 8093 |
```
|
| 8094 |
|
| 8095 |
*Returns:* `weak_this`.
|
| 8096 |
|
| 8097 |
+
### Smart pointer hash support <a id="util.smartptr.hash">[[util.smartptr.hash]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8098 |
|
| 8099 |
``` cpp
|
| 8100 |
template<class T, class D> struct hash<unique_ptr<T, D>>;
|
| 8101 |
```
|
| 8102 |
|
| 8103 |
Letting `UP` be `unique_ptr<T,D>`, the specialization `hash<UP>` is
|
| 8104 |
+
enabled [[unord.hash]] if and only if `hash<typename UP::pointer>` is
|
| 8105 |
enabled. When enabled, for an object `p` of type `UP`, `hash<UP>()(p)`
|
| 8106 |
+
evaluates to the same value as `hash<typename UP::pointer>()(p.get())`.
|
| 8107 |
+
The member functions are not guaranteed to be `noexcept`.
|
|
|
|
| 8108 |
|
| 8109 |
``` cpp
|
| 8110 |
template<class T> struct hash<shared_ptr<T>>;
|
| 8111 |
```
|
| 8112 |
|
| 8113 |
For an object `p` of type `shared_ptr<T>`, `hash<shared_ptr<T>>()(p)`
|
| 8114 |
+
evaluates to the same value as
|
| 8115 |
`hash<typename shared_ptr<T>::element_type*>()(p.get())`.
|
| 8116 |
|
| 8117 |
## Memory resources <a id="mem.res">[[mem.res]]</a>
|
| 8118 |
|
| 8119 |
### Header `<memory_resource>` synopsis <a id="mem.res.syn">[[mem.res.syn]]</a>
|
|
|
|
| 8122 |
namespace std::pmr {
|
| 8123 |
// [mem.res.class], class memory_resource
|
| 8124 |
class memory_resource;
|
| 8125 |
|
| 8126 |
bool operator==(const memory_resource& a, const memory_resource& b) noexcept;
|
|
|
|
| 8127 |
|
| 8128 |
// [mem.poly.allocator.class], class template polymorphic_allocator
|
| 8129 |
template<class Tp> class polymorphic_allocator;
|
| 8130 |
|
| 8131 |
template<class T1, class T2>
|
| 8132 |
bool operator==(const polymorphic_allocator<T1>& a,
|
| 8133 |
const polymorphic_allocator<T2>& b) noexcept;
|
|
|
|
|
|
|
|
|
|
| 8134 |
|
| 8135 |
// [mem.res.global], global memory resources
|
| 8136 |
memory_resource* new_delete_resource() noexcept;
|
| 8137 |
memory_resource* null_memory_resource() noexcept;
|
| 8138 |
memory_resource* set_default_resource(memory_resource* r) noexcept;
|
|
|
|
| 8150 |
|
| 8151 |
The `memory_resource` class is an abstract interface to an unbounded set
|
| 8152 |
of classes encapsulating memory resources.
|
| 8153 |
|
| 8154 |
``` cpp
|
| 8155 |
+
namespace std::pmr {
|
| 8156 |
class memory_resource {
|
| 8157 |
static constexpr size_t max_align = alignof(max_align_t); // exposition only
|
| 8158 |
|
| 8159 |
public:
|
| 8160 |
+
memory_resource() = default;
|
| 8161 |
+
memory_resource(const memory_resource&) = default;
|
| 8162 |
virtual ~memory_resource();
|
| 8163 |
|
| 8164 |
+
memory_resource& operator=(const memory_resource&) = default;
|
| 8165 |
+
|
| 8166 |
+
[[nodiscard]] void* allocate(size_t bytes, size_t alignment = max_align);
|
| 8167 |
void deallocate(void* p, size_t bytes, size_t alignment = max_align);
|
| 8168 |
|
| 8169 |
bool is_equal(const memory_resource& other) const noexcept;
|
| 8170 |
|
| 8171 |
private:
|
| 8172 |
virtual void* do_allocate(size_t bytes, size_t alignment) = 0;
|
| 8173 |
virtual void do_deallocate(void* p, size_t bytes, size_t alignment) = 0;
|
| 8174 |
|
| 8175 |
virtual bool do_is_equal(const memory_resource& other) const noexcept = 0;
|
| 8176 |
};
|
| 8177 |
+
}
|
| 8178 |
```
|
| 8179 |
|
| 8180 |
+
#### Public member functions <a id="mem.res.public">[[mem.res.public]]</a>
|
| 8181 |
|
| 8182 |
``` cpp
|
| 8183 |
~memory_resource();
|
| 8184 |
```
|
| 8185 |
|
| 8186 |
*Effects:* Destroys this `memory_resource`.
|
| 8187 |
|
| 8188 |
``` cpp
|
| 8189 |
+
[[nodiscard]] void* allocate(size_t bytes, size_t alignment = max_align);
|
| 8190 |
```
|
| 8191 |
|
| 8192 |
*Effects:* Equivalent to: `return do_allocate(bytes, alignment);`
|
| 8193 |
|
| 8194 |
``` cpp
|
| 8195 |
void deallocate(void* p, size_t bytes, size_t alignment = max_align);
|
| 8196 |
```
|
| 8197 |
|
| 8198 |
+
*Effects:* Equivalent to `do_deallocate(p, bytes, alignment)`.
|
| 8199 |
|
| 8200 |
``` cpp
|
| 8201 |
bool is_equal(const memory_resource& other) const noexcept;
|
| 8202 |
```
|
| 8203 |
|
| 8204 |
*Effects:* Equivalent to: `return do_is_equal(other);`
|
| 8205 |
|
| 8206 |
+
#### Private virtual member functions <a id="mem.res.private">[[mem.res.private]]</a>
|
| 8207 |
|
| 8208 |
``` cpp
|
| 8209 |
virtual void* do_allocate(size_t bytes, size_t alignment) = 0;
|
| 8210 |
```
|
| 8211 |
|
| 8212 |
+
*Preconditions:* `alignment` is a power of two.
|
| 8213 |
|
| 8214 |
*Returns:* A derived class shall implement this function to return a
|
| 8215 |
+
pointer to allocated storage [[basic.stc.dynamic.allocation]] with a
|
| 8216 |
+
size of at least `bytes`, aligned to the specified `alignment`.
|
|
|
|
|
|
|
| 8217 |
|
| 8218 |
*Throws:* A derived class implementation shall throw an appropriate
|
| 8219 |
exception if it is unable to allocate memory with the requested size and
|
| 8220 |
alignment.
|
| 8221 |
|
| 8222 |
``` cpp
|
| 8223 |
virtual void do_deallocate(void* p, size_t bytes, size_t alignment) = 0;
|
| 8224 |
```
|
| 8225 |
|
| 8226 |
+
*Preconditions:* `p` was returned from a prior call to
|
| 8227 |
`allocate(bytes, alignment)` on a memory resource equal to `*this`, and
|
| 8228 |
+
the storage at `p` has not yet been deallocated.
|
| 8229 |
|
| 8230 |
*Effects:* A derived class shall implement this function to dispose of
|
| 8231 |
allocated storage.
|
| 8232 |
|
| 8233 |
*Throws:* Nothing.
|
|
|
|
| 8239 |
*Returns:* A derived class shall implement this function to return
|
| 8240 |
`true` if memory allocated from `this` can be deallocated from `other`
|
| 8241 |
and vice-versa, otherwise `false`.
|
| 8242 |
|
| 8243 |
[*Note 1*: The most-derived type of `other` might not match the type of
|
| 8244 |
+
`this`. For a derived class `D`, an implementation of this function
|
| 8245 |
+
could immediately return `false` if
|
| 8246 |
`dynamic_cast<const D*>(&other) == nullptr`. — *end note*]
|
| 8247 |
|
| 8248 |
+
#### Equality <a id="mem.res.eq">[[mem.res.eq]]</a>
|
| 8249 |
|
| 8250 |
``` cpp
|
| 8251 |
bool operator==(const memory_resource& a, const memory_resource& b) noexcept;
|
| 8252 |
```
|
| 8253 |
|
| 8254 |
*Returns:* `&a == &b || a.is_equal(b)`.
|
| 8255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8256 |
### Class template `polymorphic_allocator` <a id="mem.poly.allocator.class">[[mem.poly.allocator.class]]</a>
|
| 8257 |
|
| 8258 |
+
A specialization of class template `pmr::polymorphic_allocator` meets
|
| 8259 |
+
the *Cpp17Allocator* requirements ([[cpp17.allocator]]). Constructed
|
| 8260 |
+
with different memory resources, different instances of the same
|
| 8261 |
+
specialization of `pmr::polymorphic_allocator` can exhibit entirely
|
| 8262 |
different allocation behavior. This runtime polymorphism allows objects
|
| 8263 |
that use `polymorphic_allocator` to behave as if they used different
|
| 8264 |
allocator types at run time even though they use the same static
|
| 8265 |
allocator type.
|
| 8266 |
|
| 8267 |
+
All specializations of class template `pmr::polymorphic_allocator` meet
|
| 8268 |
+
the allocator completeness requirements
|
| 8269 |
+
[[allocator.requirements.completeness]].
|
| 8270 |
+
|
| 8271 |
``` cpp
|
| 8272 |
+
namespace std::pmr {
|
| 8273 |
+
template<class Tp = byte> class polymorphic_allocator {
|
| 8274 |
memory_resource* memory_rsrc; // exposition only
|
| 8275 |
|
| 8276 |
public:
|
| 8277 |
using value_type = Tp;
|
| 8278 |
|
|
|
|
| 8283 |
polymorphic_allocator(const polymorphic_allocator& other) = default;
|
| 8284 |
|
| 8285 |
template<class U>
|
| 8286 |
polymorphic_allocator(const polymorphic_allocator<U>& other) noexcept;
|
| 8287 |
|
| 8288 |
+
polymorphic_allocator& operator=(const polymorphic_allocator&) = delete;
|
|
|
|
| 8289 |
|
| 8290 |
// [mem.poly.allocator.mem], member functions
|
| 8291 |
+
[[nodiscard]] Tp* allocate(size_t n);
|
| 8292 |
void deallocate(Tp* p, size_t n);
|
| 8293 |
|
| 8294 |
+
[[nodiscard]] void* allocate_bytes(size_t nbytes, size_t alignment = alignof(max_align_t));
|
| 8295 |
+
void deallocate_bytes(void* p, size_t nbytes, size_t alignment = alignof(max_align_t));
|
| 8296 |
+
template<class T> [[nodiscard]] T* allocate_object(size_t n = 1);
|
| 8297 |
+
template<class T> void deallocate_object(T* p, size_t n = 1);
|
| 8298 |
+
template<class T, class... CtorArgs> [[nodiscard]] T* new_object(CtorArgs&&... ctor_args);
|
| 8299 |
+
template<class T> void delete_object(T* p);
|
| 8300 |
+
|
| 8301 |
template<class T, class... Args>
|
| 8302 |
void construct(T* p, Args&&... args);
|
| 8303 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8304 |
template<class T>
|
| 8305 |
void destroy(T* p);
|
| 8306 |
|
| 8307 |
polymorphic_allocator select_on_container_copy_construction() const;
|
| 8308 |
|
| 8309 |
memory_resource* resource() const;
|
| 8310 |
};
|
| 8311 |
+
}
|
| 8312 |
```
|
| 8313 |
|
| 8314 |
+
#### Constructors <a id="mem.poly.allocator.ctor">[[mem.poly.allocator.ctor]]</a>
|
| 8315 |
|
| 8316 |
``` cpp
|
| 8317 |
polymorphic_allocator() noexcept;
|
| 8318 |
```
|
| 8319 |
|
|
|
|
| 8321 |
|
| 8322 |
``` cpp
|
| 8323 |
polymorphic_allocator(memory_resource* r);
|
| 8324 |
```
|
| 8325 |
|
| 8326 |
+
*Preconditions:* `r` is non-null.
|
| 8327 |
|
| 8328 |
*Effects:* Sets `memory_rsrc` to `r`.
|
| 8329 |
|
| 8330 |
*Throws:* Nothing.
|
| 8331 |
|
| 8332 |
[*Note 1*: This constructor provides an implicit conversion from
|
| 8333 |
`memory_resource*`. — *end note*]
|
| 8334 |
|
| 8335 |
``` cpp
|
| 8336 |
+
template<class U> polymorphic_allocator(const polymorphic_allocator<U>& other) noexcept;
|
|
|
|
| 8337 |
```
|
| 8338 |
|
| 8339 |
*Effects:* Sets `memory_rsrc` to `other.resource()`.
|
| 8340 |
|
| 8341 |
+
#### Member functions <a id="mem.poly.allocator.mem">[[mem.poly.allocator.mem]]</a>
|
| 8342 |
|
| 8343 |
``` cpp
|
| 8344 |
+
[[nodiscard]] Tp* allocate(size_t n);
|
| 8345 |
```
|
| 8346 |
|
| 8347 |
+
*Effects:* If `numeric_limits<size_t>::max() / sizeof(Tp) < n`, throws
|
| 8348 |
+
`bad_array_new_length`. Otherwise equivalent to:
|
| 8349 |
|
| 8350 |
``` cpp
|
| 8351 |
return static_cast<Tp*>(memory_rsrc->allocate(n * sizeof(Tp), alignof(Tp)));
|
| 8352 |
```
|
| 8353 |
|
| 8354 |
``` cpp
|
| 8355 |
void deallocate(Tp* p, size_t n);
|
| 8356 |
```
|
| 8357 |
|
| 8358 |
+
*Preconditions:* `p` was allocated from a memory resource `x`, equal to
|
| 8359 |
`*memory_rsrc`, using `x.allocate(n * sizeof(Tp), alignof(Tp))`.
|
| 8360 |
|
| 8361 |
*Effects:* Equivalent to
|
| 8362 |
`memory_rsrc->deallocate(p, n * sizeof(Tp), alignof(Tp))`.
|
| 8363 |
|
| 8364 |
*Throws:* Nothing.
|
| 8365 |
|
| 8366 |
+
``` cpp
|
| 8367 |
+
[[nodiscard]] void* allocate_bytes(size_t nbytes, size_t alignment = alignof(max_align_t));
|
| 8368 |
+
```
|
| 8369 |
+
|
| 8370 |
+
*Effects:* Equivalent to:
|
| 8371 |
+
`return memory_rsrc->allocate(nbytes, alignment);`
|
| 8372 |
+
|
| 8373 |
+
[*Note 1*: The return type is `void*` (rather than, e.g., `byte*`) to
|
| 8374 |
+
support conversion to an arbitrary pointer type `U*` by
|
| 8375 |
+
`static_cast<U*>`, thus facilitating construction of a `U` object in the
|
| 8376 |
+
allocated memory. — *end note*]
|
| 8377 |
+
|
| 8378 |
+
``` cpp
|
| 8379 |
+
void deallocate_bytes(void* p, size_t nbytes, size_t alignment = alignof(max_align_t));
|
| 8380 |
+
```
|
| 8381 |
+
|
| 8382 |
+
*Effects:* Equivalent to
|
| 8383 |
+
`memory_rsrc->deallocate(p, nbytes, alignment)`.
|
| 8384 |
+
|
| 8385 |
+
``` cpp
|
| 8386 |
+
template<class T>
|
| 8387 |
+
[[nodiscard]] T* allocate_object(size_t n = 1);
|
| 8388 |
+
```
|
| 8389 |
+
|
| 8390 |
+
*Effects:* Allocates memory suitable for holding an array of `n` objects
|
| 8391 |
+
of type `T`, as follows:
|
| 8392 |
+
|
| 8393 |
+
- if `numeric_limits<size_t>::max() / sizeof(T) < n`, throws
|
| 8394 |
+
`bad_array_new_length`,
|
| 8395 |
+
- otherwise equivalent to:
|
| 8396 |
+
``` cpp
|
| 8397 |
+
return static_cast<T*>(allocate_bytes(n*sizeof(T), alignof(T)));
|
| 8398 |
+
```
|
| 8399 |
+
|
| 8400 |
+
[*Note 2*: `T` is not deduced and must therefore be provided as a
|
| 8401 |
+
template argument. — *end note*]
|
| 8402 |
+
|
| 8403 |
+
``` cpp
|
| 8404 |
+
template<class T>
|
| 8405 |
+
void deallocate_object(T* p, size_t n = 1);
|
| 8406 |
+
```
|
| 8407 |
+
|
| 8408 |
+
*Effects:* Equivalent to `deallocate_bytes(p, n*sizeof(T), alignof(T))`.
|
| 8409 |
+
|
| 8410 |
+
``` cpp
|
| 8411 |
+
template<class T, class CtorArgs...>
|
| 8412 |
+
[[nodiscard]] T* new_object(CtorArgs&&... ctor_args);
|
| 8413 |
+
```
|
| 8414 |
+
|
| 8415 |
+
*Effects:* Allocates and constructs an object of type `T`, as follows.
|
| 8416 |
+
Equivalent to:
|
| 8417 |
+
|
| 8418 |
+
``` cpp
|
| 8419 |
+
T* p = allocate_object<T>();
|
| 8420 |
+
try {
|
| 8421 |
+
construct(p, std::forward<CtorArgs>(ctor_args)...);
|
| 8422 |
+
} catch (...) {
|
| 8423 |
+
deallocate_object(p);
|
| 8424 |
+
throw;
|
| 8425 |
+
}
|
| 8426 |
+
return p;
|
| 8427 |
+
```
|
| 8428 |
+
|
| 8429 |
+
[*Note 3*: `T` is not deduced and must therefore be provided as a
|
| 8430 |
+
template argument. — *end note*]
|
| 8431 |
+
|
| 8432 |
+
``` cpp
|
| 8433 |
+
template<class T>
|
| 8434 |
+
void delete_object(T* p);
|
| 8435 |
+
```
|
| 8436 |
+
|
| 8437 |
+
*Effects:* Equivalent to:
|
| 8438 |
+
|
| 8439 |
+
``` cpp
|
| 8440 |
+
destroy(p);
|
| 8441 |
+
deallocate_object(p);
|
| 8442 |
+
```
|
| 8443 |
+
|
| 8444 |
``` cpp
|
| 8445 |
template<class T, class... Args>
|
| 8446 |
void construct(T* p, Args&&... args);
|
| 8447 |
```
|
| 8448 |
|
| 8449 |
+
*Mandates:* Uses-allocator construction of `T` with allocator `*this`
|
| 8450 |
+
(see [[allocator.uses.construction]]) and constructor arguments
|
| 8451 |
+
`std::forward<Args>(args)...` is well-formed.
|
|
|
|
|
|
|
|
|
|
| 8452 |
|
| 8453 |
*Effects:* Construct a `T` object in the storage whose address is
|
| 8454 |
+
represented by `p` by uses-allocator construction with allocator `*this`
|
| 8455 |
+
and constructor arguments `std::forward<Args>(args)...`.
|
| 8456 |
|
| 8457 |
*Throws:* Nothing unless the constructor for `T` throws.
|
| 8458 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8459 |
``` cpp
|
| 8460 |
template<class T>
|
| 8461 |
void destroy(T* p);
|
| 8462 |
```
|
| 8463 |
|
|
|
|
| 8475 |
memory_resource* resource() const;
|
| 8476 |
```
|
| 8477 |
|
| 8478 |
*Returns:* `memory_rsrc`.
|
| 8479 |
|
| 8480 |
+
#### Equality <a id="mem.poly.allocator.eq">[[mem.poly.allocator.eq]]</a>
|
| 8481 |
|
| 8482 |
``` cpp
|
| 8483 |
template<class T1, class T2>
|
| 8484 |
bool operator==(const polymorphic_allocator<T1>& a,
|
| 8485 |
const polymorphic_allocator<T2>& b) noexcept;
|
| 8486 |
```
|
| 8487 |
|
| 8488 |
*Returns:* `*a.resource() == *b.resource()`.
|
| 8489 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8490 |
### Access to program-wide `memory_resource` objects <a id="mem.res.global">[[mem.res.global]]</a>
|
| 8491 |
|
| 8492 |
``` cpp
|
| 8493 |
memory_resource* new_delete_resource() noexcept;
|
| 8494 |
```
|
|
|
|
| 8520 |
|
| 8521 |
*Effects:* If `r` is non-null, sets the value of the default memory
|
| 8522 |
resource pointer to `r`, otherwise sets the default memory resource
|
| 8523 |
pointer to `new_delete_resource()`.
|
| 8524 |
|
|
|
|
|
|
|
| 8525 |
*Returns:* The previous value of the default memory resource pointer.
|
| 8526 |
|
| 8527 |
*Remarks:* Calling the `set_default_resource` and `get_default_resource`
|
| 8528 |
functions shall not incur a data race. A call to the
|
| 8529 |
`set_default_resource` function shall synchronize with subsequent calls
|
|
|
|
| 8569 |
reduce synchronization costs. An `unsynchronized_pool_resource` class
|
| 8570 |
may not be accessed from multiple threads simultaneously and thus avoids
|
| 8571 |
the cost of synchronization entirely in single-threaded applications.
|
| 8572 |
|
| 8573 |
``` cpp
|
| 8574 |
+
namespace std::pmr {
|
| 8575 |
struct pool_options {
|
| 8576 |
size_t max_blocks_per_chunk = 0;
|
| 8577 |
size_t largest_required_pool_block = 0;
|
| 8578 |
};
|
| 8579 |
|
| 8580 |
class synchronized_pool_resource : public memory_resource {
|
| 8581 |
public:
|
| 8582 |
+
synchronized_pool_resource(const pool_options& opts, memory_resource* upstream);
|
|
|
|
| 8583 |
|
| 8584 |
synchronized_pool_resource()
|
| 8585 |
: synchronized_pool_resource(pool_options(), get_default_resource()) {}
|
| 8586 |
explicit synchronized_pool_resource(memory_resource* upstream)
|
| 8587 |
: synchronized_pool_resource(pool_options(), upstream) {}
|
|
|
|
| 8589 |
: synchronized_pool_resource(opts, get_default_resource()) {}
|
| 8590 |
|
| 8591 |
synchronized_pool_resource(const synchronized_pool_resource&) = delete;
|
| 8592 |
virtual ~synchronized_pool_resource();
|
| 8593 |
|
| 8594 |
+
synchronized_pool_resource& operator=(const synchronized_pool_resource&) = delete;
|
|
|
|
| 8595 |
|
| 8596 |
void release();
|
| 8597 |
memory_resource* upstream_resource() const;
|
| 8598 |
pool_options options() const;
|
| 8599 |
|
|
|
|
| 8604 |
bool do_is_equal(const memory_resource& other) const noexcept override;
|
| 8605 |
};
|
| 8606 |
|
| 8607 |
class unsynchronized_pool_resource : public memory_resource {
|
| 8608 |
public:
|
| 8609 |
+
unsynchronized_pool_resource(const pool_options& opts, memory_resource* upstream);
|
|
|
|
| 8610 |
|
| 8611 |
unsynchronized_pool_resource()
|
| 8612 |
: unsynchronized_pool_resource(pool_options(), get_default_resource()) {}
|
| 8613 |
explicit unsynchronized_pool_resource(memory_resource* upstream)
|
| 8614 |
: unsynchronized_pool_resource(pool_options(), upstream) {}
|
|
|
|
| 8616 |
: unsynchronized_pool_resource(opts, get_default_resource()) {}
|
| 8617 |
|
| 8618 |
unsynchronized_pool_resource(const unsynchronized_pool_resource&) = delete;
|
| 8619 |
virtual ~unsynchronized_pool_resource();
|
| 8620 |
|
| 8621 |
+
unsynchronized_pool_resource& operator=(const unsynchronized_pool_resource&) = delete;
|
|
|
|
| 8622 |
|
| 8623 |
void release();
|
| 8624 |
memory_resource* upstream_resource() const;
|
| 8625 |
pool_options options() const;
|
| 8626 |
|
|
|
|
| 8628 |
void* do_allocate(size_t bytes, size_t alignment) override;
|
| 8629 |
void do_deallocate(void* p, size_t bytes, size_t alignment) override;
|
| 8630 |
|
| 8631 |
bool do_is_equal(const memory_resource& other) const noexcept override;
|
| 8632 |
};
|
| 8633 |
+
}
|
| 8634 |
```
|
| 8635 |
|
| 8636 |
#### `pool_options` data members <a id="mem.res.pool.options">[[mem.res.pool.options]]</a>
|
| 8637 |
|
| 8638 |
The members of `pool_options` comprise a set of constructor options for
|
|
|
|
| 8642 |
``` cpp
|
| 8643 |
size_t max_blocks_per_chunk;
|
| 8644 |
```
|
| 8645 |
|
| 8646 |
The maximum number of blocks that will be allocated at once from the
|
| 8647 |
+
upstream memory resource [[mem.res.monotonic.buffer]] to replenish a
|
| 8648 |
pool. If the value of `max_blocks_per_chunk` is zero or is greater than
|
| 8649 |
an *implementation-defined* limit, that limit is used instead. The
|
| 8650 |
implementation may choose to use a smaller value than is specified in
|
| 8651 |
this field and may use different values for different pools.
|
| 8652 |
|
|
|
|
| 8660 |
If `largest_required_pool_block` is zero or is greater than an
|
| 8661 |
*implementation-defined* limit, that limit is used instead. The
|
| 8662 |
implementation may choose a pass-through threshold larger than specified
|
| 8663 |
in this field.
|
| 8664 |
|
| 8665 |
+
#### Constructors and destructors <a id="mem.res.pool.ctor">[[mem.res.pool.ctor]]</a>
|
| 8666 |
|
| 8667 |
``` cpp
|
| 8668 |
synchronized_pool_resource(const pool_options& opts, memory_resource* upstream);
|
| 8669 |
unsynchronized_pool_resource(const pool_options& opts, memory_resource* upstream);
|
| 8670 |
```
|
| 8671 |
|
| 8672 |
+
*Preconditions:* `upstream` is the address of a valid memory resource.
|
| 8673 |
|
| 8674 |
*Effects:* Constructs a pool resource object that will obtain memory
|
| 8675 |
from `upstream` whenever the pool resource is unable to satisfy a memory
|
| 8676 |
request from its own internal data structures. The resulting object will
|
| 8677 |
hold a copy of `upstream`, but will not own the resource to which
|
|
|
|
| 8693 |
virtual ~unsynchronized_pool_resource();
|
| 8694 |
```
|
| 8695 |
|
| 8696 |
*Effects:* Calls `release()`.
|
| 8697 |
|
| 8698 |
+
#### Members <a id="mem.res.pool.mem">[[mem.res.pool.mem]]</a>
|
| 8699 |
|
| 8700 |
``` cpp
|
| 8701 |
void release();
|
| 8702 |
```
|
| 8703 |
|
|
|
|
| 8727 |
|
| 8728 |
``` cpp
|
| 8729 |
void* do_allocate(size_t bytes, size_t alignment) override;
|
| 8730 |
```
|
| 8731 |
|
| 8732 |
+
*Returns:* A pointer to allocated
|
| 8733 |
+
storage [[basic.stc.dynamic.allocation]] with a size of at least
|
| 8734 |
+
`bytes`. The size and alignment of the allocated memory shall meet the
|
| 8735 |
+
requirements for a class derived from `memory_resource`
|
| 8736 |
+
[[mem.res.class]].
|
| 8737 |
|
| 8738 |
*Effects:* If the pool selected for a block of size `bytes` is unable to
|
| 8739 |
satisfy the memory request from its own internal data structures, it
|
| 8740 |
will call `upstream_resource()->allocate()` to obtain more memory. If
|
| 8741 |
`bytes` is larger than that which the largest pool can handle, then
|
|
|
|
| 8752 |
`upstream_resource()->deallocate()`.
|
| 8753 |
|
| 8754 |
*Throws:* Nothing.
|
| 8755 |
|
| 8756 |
``` cpp
|
| 8757 |
+
bool do_is_equal(const memory_resource& other) const noexcept override;
|
|
|
|
| 8758 |
```
|
| 8759 |
|
| 8760 |
+
*Returns:* `this == &other`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8761 |
|
| 8762 |
### Class `monotonic_buffer_resource` <a id="mem.res.monotonic.buffer">[[mem.res.monotonic.buffer]]</a>
|
| 8763 |
|
| 8764 |
A `monotonic_buffer_resource` is a special-purpose memory resource
|
| 8765 |
intended for very fast memory allocations in situations where memory is
|
|
|
|
| 8779 |
with one another.
|
| 8780 |
- It frees the allocated memory on destruction, even if `deallocate` has
|
| 8781 |
not been called for some of the allocated blocks.
|
| 8782 |
|
| 8783 |
``` cpp
|
| 8784 |
+
namespace std::pmr {
|
| 8785 |
class monotonic_buffer_resource : public memory_resource {
|
| 8786 |
memory_resource* upstream_rsrc; // exposition only
|
| 8787 |
void* current_buffer; // exposition only
|
| 8788 |
size_t next_buffer_size; // exposition only
|
| 8789 |
|
| 8790 |
public:
|
| 8791 |
explicit monotonic_buffer_resource(memory_resource* upstream);
|
| 8792 |
monotonic_buffer_resource(size_t initial_size, memory_resource* upstream);
|
| 8793 |
+
monotonic_buffer_resource(void* buffer, size_t buffer_size, memory_resource* upstream);
|
|
|
|
| 8794 |
|
| 8795 |
monotonic_buffer_resource()
|
| 8796 |
: monotonic_buffer_resource(get_default_resource()) {}
|
| 8797 |
explicit monotonic_buffer_resource(size_t initial_size)
|
| 8798 |
: monotonic_buffer_resource(initial_size, get_default_resource()) {}
|
|
|
|
| 8801 |
|
| 8802 |
monotonic_buffer_resource(const monotonic_buffer_resource&) = delete;
|
| 8803 |
|
| 8804 |
virtual ~monotonic_buffer_resource();
|
| 8805 |
|
| 8806 |
+
monotonic_buffer_resource& operator=(const monotonic_buffer_resource&) = delete;
|
|
|
|
| 8807 |
|
| 8808 |
void release();
|
| 8809 |
memory_resource* upstream_resource() const;
|
| 8810 |
|
| 8811 |
protected:
|
| 8812 |
void* do_allocate(size_t bytes, size_t alignment) override;
|
| 8813 |
void do_deallocate(void* p, size_t bytes, size_t alignment) override;
|
| 8814 |
|
| 8815 |
bool do_is_equal(const memory_resource& other) const noexcept override;
|
| 8816 |
};
|
| 8817 |
+
}
|
| 8818 |
```
|
| 8819 |
|
| 8820 |
+
#### Constructors and destructor <a id="mem.res.monotonic.buffer.ctor">[[mem.res.monotonic.buffer.ctor]]</a>
|
| 8821 |
|
| 8822 |
``` cpp
|
| 8823 |
explicit monotonic_buffer_resource(memory_resource* upstream);
|
| 8824 |
monotonic_buffer_resource(size_t initial_size, memory_resource* upstream);
|
| 8825 |
```
|
| 8826 |
|
| 8827 |
+
*Preconditions:* `upstream` is the address of a valid memory resource.
|
| 8828 |
+
`initial_size`, if specified, is greater than zero.
|
| 8829 |
|
| 8830 |
*Effects:* Sets `upstream_rsrc` to `upstream` and `current_buffer` to
|
| 8831 |
`nullptr`. If `initial_size` is specified, sets `next_buffer_size` to at
|
| 8832 |
least `initial_size`; otherwise sets `next_buffer_size` to an
|
| 8833 |
*implementation-defined* size.
|
| 8834 |
|
| 8835 |
``` cpp
|
| 8836 |
monotonic_buffer_resource(void* buffer, size_t buffer_size, memory_resource* upstream);
|
| 8837 |
```
|
| 8838 |
|
| 8839 |
+
*Preconditions:* `upstream` is the address of a valid memory resource.
|
| 8840 |
+
`buffer_size` is no larger than the number of bytes in `buffer`.
|
| 8841 |
|
| 8842 |
*Effects:* Sets `upstream_rsrc` to `upstream`, `current_buffer` to
|
| 8843 |
`buffer`, and `next_buffer_size` to `buffer_size` (but not less than 1),
|
| 8844 |
then increases `next_buffer_size` by an *implementation-defined* growth
|
| 8845 |
factor (which need not be integral).
|
|
|
|
| 8848 |
~monotonic_buffer_resource();
|
| 8849 |
```
|
| 8850 |
|
| 8851 |
*Effects:* Calls `release()`.
|
| 8852 |
|
| 8853 |
+
#### Members <a id="mem.res.monotonic.buffer.mem">[[mem.res.monotonic.buffer.mem]]</a>
|
| 8854 |
|
| 8855 |
``` cpp
|
| 8856 |
void release();
|
| 8857 |
```
|
| 8858 |
|
|
|
|
| 8871 |
|
| 8872 |
``` cpp
|
| 8873 |
void* do_allocate(size_t bytes, size_t alignment) override;
|
| 8874 |
```
|
| 8875 |
|
| 8876 |
+
*Returns:* A pointer to allocated
|
| 8877 |
+
storage [[basic.stc.dynamic.allocation]] with a size of at least
|
| 8878 |
+
`bytes`. The size and alignment of the allocated memory shall meet the
|
| 8879 |
+
requirements for a class derived from `memory_resource`
|
| 8880 |
+
[[mem.res.class]].
|
| 8881 |
|
| 8882 |
*Effects:* If the unused space in `current_buffer` can fit a block with
|
| 8883 |
the specified `bytes` and `alignment`, then allocate the return block
|
| 8884 |
from `current_buffer`; otherwise set `current_buffer` to
|
| 8885 |
`upstream_rsrc->allocate(n, m)`, where `n` is not less than
|
|
|
|
| 8903 |
|
| 8904 |
``` cpp
|
| 8905 |
bool do_is_equal(const memory_resource& other) const noexcept override;
|
| 8906 |
```
|
| 8907 |
|
| 8908 |
+
*Returns:* `this == &other`.
|
|
|
|
| 8909 |
|
| 8910 |
## Class template `scoped_allocator_adaptor` <a id="allocator.adaptor">[[allocator.adaptor]]</a>
|
| 8911 |
|
| 8912 |
### Header `<scoped_allocator>` synopsis <a id="allocator.adaptor.syn">[[allocator.adaptor.syn]]</a>
|
| 8913 |
|
| 8914 |
``` cpp
|
| 8915 |
+
namespace std {
|
| 8916 |
+
// class template scoped allocator adaptor
|
| 8917 |
template<class OuterAlloc, class... InnerAlloc>
|
| 8918 |
class scoped_allocator_adaptor;
|
| 8919 |
+
|
| 8920 |
+
// [scoped.adaptor.operators], scoped allocator operators
|
| 8921 |
template<class OuterA1, class OuterA2, class... InnerAllocs>
|
| 8922 |
bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 8923 |
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
| 8924 |
+
}
|
|
|
|
|
|
|
| 8925 |
```
|
| 8926 |
|
| 8927 |
The class template `scoped_allocator_adaptor` is an allocator template
|
| 8928 |
+
that specifies an allocator resource (the outer allocator) to be used by
|
| 8929 |
+
a container (as any other allocator does) and also specifies an inner
|
| 8930 |
allocator resource to be passed to the constructor of every element
|
| 8931 |
within the container. This adaptor is instantiated with one outer and
|
| 8932 |
zero or more inner allocator types. If instantiated with only one
|
| 8933 |
allocator type, the inner allocator becomes the
|
| 8934 |
`scoped_allocator_adaptor` itself, thus using the same allocator
|
|
|
|
| 8952 |
template<class OuterAlloc, class... InnerAllocs>
|
| 8953 |
class scoped_allocator_adaptor : public OuterAlloc {
|
| 8954 |
private:
|
| 8955 |
using OuterTraits = allocator_traits<OuterAlloc>; // exposition only
|
| 8956 |
scoped_allocator_adaptor<InnerAllocs...> inner; // exposition only
|
| 8957 |
+
|
| 8958 |
public:
|
| 8959 |
using outer_allocator_type = OuterAlloc;
|
| 8960 |
using inner_allocator_type = see below;
|
| 8961 |
|
| 8962 |
using value_type = typename OuterTraits::value_type;
|
|
|
|
| 8970 |
using propagate_on_container_copy_assignment = see below;
|
| 8971 |
using propagate_on_container_move_assignment = see below;
|
| 8972 |
using propagate_on_container_swap = see below;
|
| 8973 |
using is_always_equal = see below;
|
| 8974 |
|
| 8975 |
+
template<class Tp> struct rebind {
|
|
|
|
| 8976 |
using other = scoped_allocator_adaptor<
|
| 8977 |
OuterTraits::template rebind_alloc<Tp>, InnerAllocs...>;
|
| 8978 |
};
|
| 8979 |
|
| 8980 |
scoped_allocator_adaptor();
|
|
|
|
| 9000 |
inner_allocator_type& inner_allocator() noexcept;
|
| 9001 |
const inner_allocator_type& inner_allocator() const noexcept;
|
| 9002 |
outer_allocator_type& outer_allocator() noexcept;
|
| 9003 |
const outer_allocator_type& outer_allocator() const noexcept;
|
| 9004 |
|
| 9005 |
+
[[nodiscard]] pointer allocate(size_type n);
|
| 9006 |
+
[[nodiscard]] pointer allocate(size_type n, const_void_pointer hint);
|
| 9007 |
void deallocate(pointer p, size_type n);
|
| 9008 |
size_type max_size() const;
|
| 9009 |
|
| 9010 |
template<class T, class... Args>
|
| 9011 |
void construct(T* p, Args&&... args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9012 |
|
| 9013 |
template<class T>
|
| 9014 |
void destroy(T* p);
|
| 9015 |
|
| 9016 |
scoped_allocator_adaptor select_on_container_copy_construction() const;
|
| 9017 |
};
|
| 9018 |
|
| 9019 |
template<class OuterAlloc, class... InnerAllocs>
|
| 9020 |
scoped_allocator_adaptor(OuterAlloc, InnerAllocs...)
|
| 9021 |
-> scoped_allocator_adaptor<OuterAlloc, InnerAllocs...>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9022 |
}
|
| 9023 |
```
|
| 9024 |
|
| 9025 |
+
### Member types <a id="allocator.adaptor.types">[[allocator.adaptor.types]]</a>
|
| 9026 |
|
| 9027 |
``` cpp
|
| 9028 |
using inner_allocator_type = see below;
|
| 9029 |
```
|
| 9030 |
|
|
|
|
| 9065 |
|
| 9066 |
*Type:* `true_type` if `allocator_traits<A>::is_always_equal::value` is
|
| 9067 |
`true` for every `A` in the set of `OuterAlloc` and `InnerAllocs...`;
|
| 9068 |
otherwise, `false_type`.
|
| 9069 |
|
| 9070 |
+
### Constructors <a id="allocator.adaptor.cnstr">[[allocator.adaptor.cnstr]]</a>
|
| 9071 |
|
| 9072 |
``` cpp
|
| 9073 |
scoped_allocator_adaptor();
|
| 9074 |
```
|
| 9075 |
|
| 9076 |
*Effects:* Value-initializes the `OuterAlloc` base class and the `inner`
|
| 9077 |
allocator object.
|
| 9078 |
|
| 9079 |
``` cpp
|
| 9080 |
template<class OuterA2>
|
| 9081 |
+
scoped_allocator_adaptor(OuterA2&& outerAlloc, const InnerAllocs&... innerAllocs) noexcept;
|
|
|
|
| 9082 |
```
|
| 9083 |
|
| 9084 |
+
*Constraints:* `is_constructible_v<OuterAlloc, OuterA2>` is `true`.
|
| 9085 |
+
|
| 9086 |
*Effects:* Initializes the `OuterAlloc` base class with
|
| 9087 |
`std::forward<OuterA2>(outerAlloc)` and `inner` with `innerAllocs...`
|
| 9088 |
(hence recursively initializing each allocator within the adaptor with
|
| 9089 |
the corresponding allocator from the argument list).
|
| 9090 |
|
|
|
|
|
|
|
|
|
|
| 9091 |
``` cpp
|
| 9092 |
scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
|
| 9093 |
```
|
| 9094 |
|
| 9095 |
*Effects:* Initializes each allocator within the adaptor with the
|
|
|
|
| 9102 |
*Effects:* Move constructs each allocator within the adaptor with the
|
| 9103 |
corresponding allocator from `other`.
|
| 9104 |
|
| 9105 |
``` cpp
|
| 9106 |
template<class OuterA2>
|
| 9107 |
+
scoped_allocator_adaptor(
|
| 9108 |
+
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept;
|
| 9109 |
```
|
| 9110 |
|
| 9111 |
+
*Constraints:* `is_constructible_v<OuterAlloc, const OuterA2&>` is
|
| 9112 |
+
`true`.
|
| 9113 |
+
|
| 9114 |
*Effects:* Initializes each allocator within the adaptor with the
|
| 9115 |
corresponding allocator from `other`.
|
| 9116 |
|
|
|
|
|
|
|
|
|
|
| 9117 |
``` cpp
|
| 9118 |
template<class OuterA2>
|
| 9119 |
+
scoped_allocator_adaptor(scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
|
|
|
|
| 9120 |
```
|
| 9121 |
|
| 9122 |
+
*Constraints:* `is_constructible_v<OuterAlloc, OuterA2>` is `true`.
|
| 9123 |
+
|
| 9124 |
*Effects:* Initializes each allocator within the adaptor with the
|
| 9125 |
corresponding allocator rvalue from `other`.
|
| 9126 |
|
| 9127 |
+
### Members <a id="allocator.adaptor.members">[[allocator.adaptor.members]]</a>
|
|
|
|
| 9128 |
|
| 9129 |
+
In the `construct` member functions, `OUTERMOST(x)` is
|
| 9130 |
+
`OUTERMOST(x.outer_allocator())` if the expression `x.outer_allocator()`
|
| 9131 |
+
is valid [[temp.deduct]] and `x` otherwise; `OUTERMOST_ALLOC_TRAITS(x)`
|
| 9132 |
+
is `allocator_traits<remove_reference_t<decltype(OUTERMOST(x))>>`.
|
|
|
|
|
|
|
| 9133 |
|
| 9134 |
[*Note 1*: `OUTERMOST(x)` and `OUTERMOST_ALLOC_TRAITS(x)` are recursive
|
| 9135 |
operations. It is incumbent upon the definition of `outer_allocator()`
|
| 9136 |
to ensure that the recursion terminates. It will terminate for all
|
| 9137 |
instantiations of `scoped_allocator_adaptor`. — *end note*]
|
|
|
|
| 9155 |
```
|
| 9156 |
|
| 9157 |
*Returns:* `static_cast<const OuterAlloc&>(*this)`.
|
| 9158 |
|
| 9159 |
``` cpp
|
| 9160 |
+
[[nodiscard]] pointer allocate(size_type n);
|
| 9161 |
```
|
| 9162 |
|
| 9163 |
*Returns:*
|
| 9164 |
`allocator_traits<OuterAlloc>::allocate(outer_allocator(), n)`.
|
| 9165 |
|
| 9166 |
``` cpp
|
| 9167 |
+
[[nodiscard]] pointer allocate(size_type n, const_void_pointer hint);
|
| 9168 |
```
|
| 9169 |
|
| 9170 |
*Returns:*
|
| 9171 |
`allocator_traits<OuterAlloc>::allocate(outer_allocator(), n, hint)`.
|
| 9172 |
|
|
|
|
| 9186 |
``` cpp
|
| 9187 |
template<class T, class... Args>
|
| 9188 |
void construct(T* p, Args&&... args);
|
| 9189 |
```
|
| 9190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9191 |
*Effects:* Equivalent to:
|
| 9192 |
|
| 9193 |
``` cpp
|
| 9194 |
+
apply([p, this](auto&&... newargs) {
|
| 9195 |
+
OUTERMOST_ALLOC_TRAITS(*this)::construct(
|
| 9196 |
+
OUTERMOST(*this), p,
|
| 9197 |
+
std::forward<decltype(newargs)>(newargs)...);
|
| 9198 |
+
},
|
| 9199 |
+
uses_allocator_construction_args<T>(inner_allocator(),
|
| 9200 |
+
std::forward<Args>(args)...));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9201 |
```
|
| 9202 |
|
| 9203 |
``` cpp
|
| 9204 |
template<class T>
|
| 9205 |
void destroy(T* p);
|
|
|
|
| 9215 |
*Returns:* A new `scoped_allocator_adaptor` object where each allocator
|
| 9216 |
`A` in the adaptor is initialized from the result of calling
|
| 9217 |
`allocator_traits<A>::select_on_container_copy_construction()` on the
|
| 9218 |
corresponding allocator in `*this`.
|
| 9219 |
|
| 9220 |
+
### Operators <a id="scoped.adaptor.operators">[[scoped.adaptor.operators]]</a>
|
| 9221 |
|
| 9222 |
``` cpp
|
| 9223 |
template<class OuterA1, class OuterA2, class... InnerAllocs>
|
| 9224 |
bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
| 9225 |
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
|
|
|
| 9235 |
|
| 9236 |
``` cpp
|
| 9237 |
a.outer_allocator() == b.outer_allocator() && a.inner_allocator() == b.inner_allocator()
|
| 9238 |
```
|
| 9239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9240 |
## Function objects <a id="function.objects">[[function.objects]]</a>
|
| 9241 |
|
| 9242 |
+
A *function object type* is an object type [[basic.types]] that can be
|
| 9243 |
+
the type of the *postfix-expression* in a function call ([[expr.call]],
|
| 9244 |
+
[[over.match.call]]).[^2] A *function object* is an object of a function
|
| 9245 |
+
object type. In the places where one would expect to pass a pointer to a
|
| 9246 |
+
function to an algorithmic template [[algorithms]], the interface is
|
| 9247 |
+
specified to accept a function object. This not only makes algorithmic
|
| 9248 |
+
templates work with pointers to functions, but also enables them to work
|
| 9249 |
+
with arbitrary function objects.
|
|
|
|
| 9250 |
|
| 9251 |
### Header `<functional>` synopsis <a id="functional.syn">[[functional.syn]]</a>
|
| 9252 |
|
| 9253 |
``` cpp
|
| 9254 |
namespace std {
|
| 9255 |
// [func.invoke], invoke
|
| 9256 |
template<class F, class... Args>
|
| 9257 |
+
constexpr invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
|
| 9258 |
noexcept(is_nothrow_invocable_v<F, Args...>);
|
| 9259 |
|
| 9260 |
// [refwrap], reference_wrapper
|
| 9261 |
template<class T> class reference_wrapper;
|
| 9262 |
|
| 9263 |
+
template<class T> constexpr reference_wrapper<T> ref(T&) noexcept;
|
| 9264 |
+
template<class T> constexpr reference_wrapper<const T> cref(const T&) noexcept;
|
| 9265 |
template<class T> void ref(const T&&) = delete;
|
| 9266 |
template<class T> void cref(const T&&) = delete;
|
| 9267 |
|
| 9268 |
+
template<class T> constexpr reference_wrapper<T> ref(reference_wrapper<T>) noexcept;
|
| 9269 |
+
template<class T> constexpr reference_wrapper<const T> cref(reference_wrapper<T>) noexcept;
|
| 9270 |
|
| 9271 |
// [arithmetic.operations], arithmetic operations
|
| 9272 |
template<class T = void> struct plus;
|
| 9273 |
template<class T = void> struct minus;
|
| 9274 |
template<class T = void> struct multiplies;
|
|
|
|
| 9294 |
template<> struct greater<void>;
|
| 9295 |
template<> struct less<void>;
|
| 9296 |
template<> struct greater_equal<void>;
|
| 9297 |
template<> struct less_equal<void>;
|
| 9298 |
|
| 9299 |
+
// [comparisons.three.way], class compare_three_way
|
| 9300 |
+
struct compare_three_way;
|
| 9301 |
+
|
| 9302 |
// [logical.operations], logical operations
|
| 9303 |
template<class T = void> struct logical_and;
|
| 9304 |
template<class T = void> struct logical_or;
|
| 9305 |
template<class T = void> struct logical_not;
|
| 9306 |
template<> struct logical_and<void>;
|
|
|
|
| 9315 |
template<> struct bit_and<void>;
|
| 9316 |
template<> struct bit_or<void>;
|
| 9317 |
template<> struct bit_xor<void>;
|
| 9318 |
template<> struct bit_not<void>;
|
| 9319 |
|
| 9320 |
+
// [func.identity], identity
|
| 9321 |
+
struct identity;
|
| 9322 |
+
|
| 9323 |
+
// [func.not.fn], function template not_fn
|
| 9324 |
+
template<class F> constexpr unspecified not_fn(F&& f);
|
| 9325 |
+
|
| 9326 |
+
// [func.bind.front], function template bind_front
|
| 9327 |
+
template<class F, class... Args> constexpr unspecified bind_front(F&&, Args&&...);
|
| 9328 |
|
| 9329 |
// [func.bind], bind
|
| 9330 |
template<class T> struct is_bind_expression;
|
| 9331 |
+
template<class T>
|
| 9332 |
+
inline constexpr bool is_bind_expression_v = is_bind_expression<T>::value;
|
| 9333 |
template<class T> struct is_placeholder;
|
| 9334 |
+
template<class T>
|
| 9335 |
+
inline constexpr int is_placeholder_v = is_placeholder<T>::value;
|
| 9336 |
|
| 9337 |
template<class F, class... BoundArgs>
|
| 9338 |
+
constexpr unspecified bind(F&&, BoundArgs&&...);
|
| 9339 |
template<class R, class F, class... BoundArgs>
|
| 9340 |
+
constexpr unspecified bind(F&&, BoundArgs&&...);
|
| 9341 |
|
| 9342 |
namespace placeholders {
|
| 9343 |
// M is the implementation-defined number of placeholders
|
| 9344 |
see belownc _1;
|
| 9345 |
see belownc _2;
|
|
|
|
| 9349 |
see belownc _M;
|
| 9350 |
}
|
| 9351 |
|
| 9352 |
// [func.memfn], member function adaptors
|
| 9353 |
template<class R, class T>
|
| 9354 |
+
constexpr unspecified mem_fn(R T::*) noexcept;
|
| 9355 |
|
| 9356 |
// [func.wrap], polymorphic function wrappers
|
| 9357 |
class bad_function_call;
|
| 9358 |
|
| 9359 |
template<class> class function; // not defined
|
|
|
|
| 9362 |
template<class R, class... ArgTypes>
|
| 9363 |
void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
|
| 9364 |
|
| 9365 |
template<class R, class... ArgTypes>
|
| 9366 |
bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9367 |
|
| 9368 |
// [func.search], searchers
|
| 9369 |
template<class ForwardIterator, class BinaryPredicate = equal_to<>>
|
| 9370 |
class default_searcher;
|
| 9371 |
|
|
|
|
| 9377 |
template<class RandomAccessIterator,
|
| 9378 |
class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
|
| 9379 |
class BinaryPredicate = equal_to<>>
|
| 9380 |
class boyer_moore_horspool_searcher;
|
| 9381 |
|
| 9382 |
+
// [unord.hash], class template hash
|
| 9383 |
template<class T>
|
| 9384 |
struct hash;
|
| 9385 |
|
| 9386 |
+
namespace ranges {
|
| 9387 |
+
// [range.cmp], concept-constrained comparisons
|
| 9388 |
+
struct equal_to;
|
| 9389 |
+
struct not_equal_to;
|
| 9390 |
+
struct greater;
|
| 9391 |
+
struct less;
|
| 9392 |
+
struct greater_equal;
|
| 9393 |
+
struct less_equal;
|
| 9394 |
+
}
|
| 9395 |
}
|
| 9396 |
```
|
| 9397 |
|
| 9398 |
[*Example 1*:
|
| 9399 |
|
|
|
|
| 9421 |
The following definitions apply to this Clause:
|
| 9422 |
|
| 9423 |
A *call signature* is the name of a return type followed by a
|
| 9424 |
parenthesized comma-separated list of zero or more argument types.
|
| 9425 |
|
| 9426 |
+
A *callable type* is a function object type [[function.objects]] or a
|
| 9427 |
pointer to member.
|
| 9428 |
|
| 9429 |
A *callable object* is an object of a callable type.
|
| 9430 |
|
| 9431 |
A *call wrapper type* is a type that holds a callable object and
|
|
|
|
| 9433 |
|
| 9434 |
A *call wrapper* is an object of a call wrapper type.
|
| 9435 |
|
| 9436 |
A *target object* is the callable object held by a call wrapper.
|
| 9437 |
|
| 9438 |
+
A call wrapper type may additionally hold a sequence of objects and
|
| 9439 |
+
references that may be passed as arguments to the target object. These
|
| 9440 |
+
entities are collectively referred to as *bound argument entities*.
|
| 9441 |
+
|
| 9442 |
+
The target object and bound argument entities of the call wrapper are
|
| 9443 |
+
collectively referred to as *state entities*.
|
| 9444 |
+
|
| 9445 |
### Requirements <a id="func.require">[[func.require]]</a>
|
| 9446 |
|
| 9447 |
+
Define `INVOKE(f, t₁, t₂, …, t_N)` as follows:
|
| 9448 |
|
| 9449 |
+
- `(t₁.*f)(t₂, …, t_N)` when `f` is a pointer to a member function of a
|
| 9450 |
+
class `T` and `is_base_of_v<T, remove_reference_t<decltype(t₁)>>` is
|
| 9451 |
+
`true`;
|
| 9452 |
+
- `(t₁.get().*f)(t₂, …, t_N)` when `f` is a pointer to a member function
|
| 9453 |
+
of a class `T` and `remove_cvref_t<decltype(t₁)>` is a specialization
|
| 9454 |
+
of `reference_wrapper`;
|
| 9455 |
+
- `((*t₁).*f)(t₂, …, t_N)` when `f` is a pointer to a member function of
|
| 9456 |
+
a class `T` and `t₁` does not satisfy the previous two items;
|
| 9457 |
+
- `t₁.*f` when `N == 1` and `f` is a pointer to data member of a class
|
| 9458 |
+
`T` and `is_base_of_v<T, remove_reference_t<decltype(t₁)>>` is `true`;
|
| 9459 |
+
- `t₁.get().*f` when `N == 1` and `f` is a pointer to data member of a
|
| 9460 |
+
class `T` and `remove_cvref_t<decltype(t₁)>` is a specialization of
|
| 9461 |
`reference_wrapper`;
|
| 9462 |
+
- `(*t₁).*f` when `N == 1` and `f` is a pointer to data member of a
|
| 9463 |
+
class `T` and `t₁` does not satisfy the previous two items;
|
| 9464 |
+
- `f(t₁, t₂, …, t_N)` in all other cases.
|
| 9465 |
|
| 9466 |
+
Define `INVOKE<R>(f, t₁, t₂, …, t_N)` as
|
| 9467 |
+
`static_cast<void>(INVOKE(f, t₁, t₂, …, t_N))` if `R` is cv `void`,
|
| 9468 |
+
otherwise `INVOKE(f, t₁, t₂, …, t_N)` implicitly converted to `R`.
|
| 9469 |
|
| 9470 |
+
Every call wrapper [[func.def]] meets the *Cpp17MoveConstructible* and
|
| 9471 |
+
*Cpp17Destructible* requirements. An *argument forwarding call wrapper*
|
| 9472 |
+
is a call wrapper that can be called with an arbitrary argument list and
|
| 9473 |
+
delivers the arguments to the wrapped callable object as references.
|
| 9474 |
+
This forwarding step delivers rvalue arguments as rvalue references and
|
| 9475 |
+
lvalue arguments as lvalue references.
|
|
|
|
|
|
|
|
|
|
| 9476 |
|
| 9477 |
[*Note 1*:
|
| 9478 |
|
| 9479 |
+
In a typical implementation, argument forwarding call wrappers have an
|
| 9480 |
+
overloaded function call operator of the form
|
| 9481 |
|
| 9482 |
``` cpp
|
| 9483 |
template<class... UnBoundArgs>
|
| 9484 |
+
constexpr R operator()(UnBoundArgs&&... unbound_args) cv-qual;
|
| 9485 |
```
|
| 9486 |
|
| 9487 |
— *end note*]
|
| 9488 |
|
| 9489 |
+
A *perfect forwarding call wrapper* is an argument forwarding call
|
| 9490 |
+
wrapper that forwards its state entities to the underlying call
|
| 9491 |
+
expression. This forwarding step delivers a state entity of type `T` as
|
| 9492 |
+
cv `T&` when the call is performed on an lvalue of the call wrapper type
|
| 9493 |
+
and as cv `T&&` otherwise, where cv represents the cv-qualifiers of the
|
| 9494 |
+
call wrapper and where cv shall be neither `volatile` nor
|
| 9495 |
+
`const volatile`.
|
| 9496 |
+
|
| 9497 |
+
A *call pattern* defines the semantics of invoking a perfect forwarding
|
| 9498 |
+
call wrapper. A postfix call performed on a perfect forwarding call
|
| 9499 |
+
wrapper is expression-equivalent [[defns.expression-equivalent]] to an
|
| 9500 |
+
expression `e` determined from its call pattern `cp` by replacing all
|
| 9501 |
+
occurrences of the arguments of the call wrapper and its state entities
|
| 9502 |
+
with references as described in the corresponding forwarding steps.
|
| 9503 |
+
|
| 9504 |
+
A *simple call wrapper* is a perfect forwarding call wrapper that meets
|
| 9505 |
+
the *Cpp17CopyConstructible* and *Cpp17CopyAssignable* requirements and
|
| 9506 |
+
whose copy constructor, move constructor, and assignment operators are
|
| 9507 |
+
constexpr functions that do not throw exceptions.
|
| 9508 |
+
|
| 9509 |
+
The copy/move constructor of an argument forwarding call wrapper has the
|
| 9510 |
+
same apparent semantics as if memberwise copy/move of its state entities
|
| 9511 |
+
were performed [[class.copy.ctor]].
|
| 9512 |
+
|
| 9513 |
+
[*Note 2*: This implies that each of the copy/move constructors has the
|
| 9514 |
+
same exception-specification as the corresponding implicit definition
|
| 9515 |
+
and is declared as `constexpr` if the corresponding implicit definition
|
| 9516 |
+
would be considered to be constexpr. — *end note*]
|
| 9517 |
+
|
| 9518 |
+
Argument forwarding call wrappers returned by a given standard library
|
| 9519 |
+
function template have the same type if the types of their corresponding
|
| 9520 |
+
state entities are the same.
|
| 9521 |
+
|
| 9522 |
### Function template `invoke` <a id="func.invoke">[[func.invoke]]</a>
|
| 9523 |
|
| 9524 |
``` cpp
|
| 9525 |
template<class F, class... Args>
|
| 9526 |
+
constexpr invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
|
| 9527 |
noexcept(is_nothrow_invocable_v<F, Args...>);
|
| 9528 |
```
|
| 9529 |
|
| 9530 |
*Returns:* *INVOKE*(std::forward\<F\>(f),
|
| 9531 |
+
std::forward\<Args\>(args)...) [[func.require]].
|
| 9532 |
|
| 9533 |
### Class template `reference_wrapper` <a id="refwrap">[[refwrap]]</a>
|
| 9534 |
|
| 9535 |
``` cpp
|
| 9536 |
namespace std {
|
|
|
|
| 9538 |
public:
|
| 9539 |
// types
|
| 9540 |
using type = T;
|
| 9541 |
|
| 9542 |
// construct/copy/destroy
|
| 9543 |
+
template<class U>
|
| 9544 |
+
constexpr reference_wrapper(U&&) noexcept(see below);
|
| 9545 |
+
constexpr reference_wrapper(const reference_wrapper& x) noexcept;
|
| 9546 |
|
| 9547 |
// assignment
|
| 9548 |
+
constexpr reference_wrapper& operator=(const reference_wrapper& x) noexcept;
|
| 9549 |
|
| 9550 |
// access
|
| 9551 |
+
constexpr operator T& () const noexcept;
|
| 9552 |
+
constexpr T& get() const noexcept;
|
| 9553 |
|
| 9554 |
// invocation
|
| 9555 |
template<class... ArgTypes>
|
| 9556 |
+
constexpr invoke_result_t<T&, ArgTypes...> operator()(ArgTypes&&...) const;
|
|
|
|
| 9557 |
};
|
|
|
|
| 9558 |
template<class T>
|
| 9559 |
+
reference_wrapper(T&) -> reference_wrapper<T>;
|
| 9560 |
}
|
| 9561 |
```
|
| 9562 |
|
| 9563 |
+
`reference_wrapper<T>` is a *Cpp17CopyConstructible* and
|
| 9564 |
+
*Cpp17CopyAssignable* wrapper around a reference to an object or
|
| 9565 |
+
function of type `T`.
|
| 9566 |
|
| 9567 |
+
`reference_wrapper<T>` is a trivially copyable type [[basic.types]].
|
|
|
|
| 9568 |
|
| 9569 |
+
The template parameter `T` of `reference_wrapper` may be an incomplete
|
| 9570 |
+
type.
|
| 9571 |
+
|
| 9572 |
+
#### Constructors and destructor <a id="refwrap.const">[[refwrap.const]]</a>
|
| 9573 |
|
| 9574 |
``` cpp
|
| 9575 |
+
template<class U>
|
| 9576 |
+
constexpr reference_wrapper(U&& u) noexcept(see below);
|
| 9577 |
```
|
| 9578 |
|
| 9579 |
+
Let *FUN* denote the exposition-only functions
|
| 9580 |
+
|
| 9581 |
+
``` cpp
|
| 9582 |
+
void FUN(T&) noexcept;
|
| 9583 |
+
void FUN(T&&) = delete;
|
| 9584 |
+
```
|
| 9585 |
+
|
| 9586 |
+
*Constraints:* The expression *FUN*(declval\<U\>()) is well-formed and
|
| 9587 |
+
`is_same_v<remove_cvref_t<U>, reference_wrapper>` is `false`.
|
| 9588 |
+
|
| 9589 |
+
*Effects:* Creates a variable `r` as if by `T& r = std::forward<U>(u)`,
|
| 9590 |
+
then constructs a `reference_wrapper` object that stores a reference to
|
| 9591 |
+
`r`.
|
| 9592 |
+
|
| 9593 |
+
*Remarks:* The expression inside `noexcept` is equivalent to
|
| 9594 |
+
`noexcept(`*`FUN`*`(declval<U>()))`.
|
| 9595 |
|
| 9596 |
``` cpp
|
| 9597 |
+
constexpr reference_wrapper(const reference_wrapper& x) noexcept;
|
| 9598 |
```
|
| 9599 |
|
| 9600 |
*Effects:* Constructs a `reference_wrapper` object that stores a
|
| 9601 |
reference to `x.get()`.
|
| 9602 |
|
| 9603 |
+
#### Assignment <a id="refwrap.assign">[[refwrap.assign]]</a>
|
| 9604 |
|
| 9605 |
``` cpp
|
| 9606 |
+
constexpr reference_wrapper& operator=(const reference_wrapper& x) noexcept;
|
| 9607 |
```
|
| 9608 |
|
| 9609 |
+
*Ensures:* `*this` stores a reference to `x.get()`.
|
| 9610 |
|
| 9611 |
+
#### Access <a id="refwrap.access">[[refwrap.access]]</a>
|
| 9612 |
|
| 9613 |
``` cpp
|
| 9614 |
+
constexpr operator T& () const noexcept;
|
| 9615 |
```
|
| 9616 |
|
| 9617 |
*Returns:* The stored reference.
|
| 9618 |
|
| 9619 |
``` cpp
|
| 9620 |
+
constexpr T& get() const noexcept;
|
| 9621 |
```
|
| 9622 |
|
| 9623 |
*Returns:* The stored reference.
|
| 9624 |
|
| 9625 |
+
#### Invocation <a id="refwrap.invoke">[[refwrap.invoke]]</a>
|
| 9626 |
|
| 9627 |
``` cpp
|
| 9628 |
template<class... ArgTypes>
|
| 9629 |
+
constexpr invoke_result_t<T&, ArgTypes...>
|
| 9630 |
operator()(ArgTypes&&... args) const;
|
| 9631 |
```
|
| 9632 |
|
| 9633 |
+
*Mandates:* `T` is a complete type.
|
| 9634 |
+
|
| 9635 |
*Returns:* *INVOKE*(get(),
|
| 9636 |
+
std::forward\<ArgTypes\>(args)...). [[func.require]]
|
| 9637 |
|
| 9638 |
+
#### Helper functions <a id="refwrap.helpers">[[refwrap.helpers]]</a>
|
| 9639 |
+
|
| 9640 |
+
The template parameter `T` of the following `ref` and `cref` function
|
| 9641 |
+
templates may be an incomplete type.
|
| 9642 |
|
| 9643 |
``` cpp
|
| 9644 |
+
template<class T> constexpr reference_wrapper<T> ref(T& t) noexcept;
|
| 9645 |
```
|
| 9646 |
|
| 9647 |
*Returns:* `reference_wrapper<T>(t)`.
|
| 9648 |
|
| 9649 |
``` cpp
|
| 9650 |
+
template<class T> constexpr reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;
|
| 9651 |
```
|
| 9652 |
|
| 9653 |
*Returns:* `ref(t.get())`.
|
| 9654 |
|
| 9655 |
``` cpp
|
| 9656 |
+
template<class T> constexpr reference_wrapper<const T> cref(const T& t) noexcept;
|
| 9657 |
```
|
| 9658 |
|
| 9659 |
*Returns:* `reference_wrapper <const T>(t)`.
|
| 9660 |
|
| 9661 |
``` cpp
|
| 9662 |
+
template<class T> constexpr reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
|
| 9663 |
```
|
| 9664 |
|
| 9665 |
*Returns:* `cref(t.get())`.
|
| 9666 |
|
| 9667 |
### Arithmetic operations <a id="arithmetic.operations">[[arithmetic.operations]]</a>
|
|
|
|
| 9853 |
|
| 9854 |
The library provides basic function object classes for all of the
|
| 9855 |
comparison operators in the language ([[expr.rel]], [[expr.eq]]).
|
| 9856 |
|
| 9857 |
For templates `less`, `greater`, `less_equal`, and `greater_equal`, the
|
| 9858 |
+
specializations for any pointer type yield a result consistent with the
|
| 9859 |
+
implementation-defined strict total order over pointers
|
| 9860 |
+
[[defns.order.ptr]].
|
| 9861 |
|
| 9862 |
+
[*Note 1*: If `a < b` is well-defined for pointers `a` and `b` of type
|
| 9863 |
+
`P`, then `(a < b) == less<P>()(a, b)`, `(a > b) == greater<P>()(a, b)`,
|
| 9864 |
+
and so forth. — *end note*]
|
| 9865 |
|
| 9866 |
For template specializations `less<void>`, `greater<void>`,
|
| 9867 |
`less_equal<void>`, and `greater_equal<void>`, if the call operator
|
| 9868 |
calls a built-in operator comparing pointers, the call operator yields a
|
| 9869 |
+
result consistent with the implementation-defined strict total order
|
| 9870 |
+
over pointers.
|
|
|
|
| 9871 |
|
| 9872 |
+
#### Class template `equal_to` <a id="comparisons.equal.to">[[comparisons.equal.to]]</a>
|
| 9873 |
|
| 9874 |
``` cpp
|
| 9875 |
template<class T = void> struct equal_to {
|
| 9876 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 9877 |
};
|
|
|
|
| 9897 |
-> decltype(std::forward<T>(t) == std::forward<U>(u));
|
| 9898 |
```
|
| 9899 |
|
| 9900 |
*Returns:* `std::forward<T>(t) == std::forward<U>(u)`.
|
| 9901 |
|
| 9902 |
+
#### Class template `not_equal_to` <a id="comparisons.not.equal.to">[[comparisons.not.equal.to]]</a>
|
| 9903 |
|
| 9904 |
``` cpp
|
| 9905 |
template<class T = void> struct not_equal_to {
|
| 9906 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 9907 |
};
|
|
|
|
| 9987 |
-> decltype(std::forward<T>(t) < std::forward<U>(u));
|
| 9988 |
```
|
| 9989 |
|
| 9990 |
*Returns:* `std::forward<T>(t) < std::forward<U>(u)`.
|
| 9991 |
|
| 9992 |
+
#### Class template `greater_equal` <a id="comparisons.greater.equal">[[comparisons.greater.equal]]</a>
|
| 9993 |
|
| 9994 |
``` cpp
|
| 9995 |
template<class T = void> struct greater_equal {
|
| 9996 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 9997 |
};
|
|
|
|
| 10017 |
-> decltype(std::forward<T>(t) >= std::forward<U>(u));
|
| 10018 |
```
|
| 10019 |
|
| 10020 |
*Returns:* `std::forward<T>(t) >= std::forward<U>(u)`.
|
| 10021 |
|
| 10022 |
+
#### Class template `less_equal` <a id="comparisons.less.equal">[[comparisons.less.equal]]</a>
|
| 10023 |
|
| 10024 |
``` cpp
|
| 10025 |
template<class T = void> struct less_equal {
|
| 10026 |
constexpr bool operator()(const T& x, const T& y) const;
|
| 10027 |
};
|
|
|
|
| 10047 |
-> decltype(std::forward<T>(t) <= std::forward<U>(u));
|
| 10048 |
```
|
| 10049 |
|
| 10050 |
*Returns:* `std::forward<T>(t) <= std::forward<U>(u)`.
|
| 10051 |
|
| 10052 |
+
#### Class `compare_three_way` <a id="comparisons.three.way">[[comparisons.three.way]]</a>
|
| 10053 |
+
|
| 10054 |
+
In this subclause, `BUILTIN-PTR-THREE-WAY(T, U)` for types `T` and `U`
|
| 10055 |
+
is a boolean constant expression. `BUILTIN-PTR-THREE-WAY(T, U)` is
|
| 10056 |
+
`true` if and only if `<=>` in the expression
|
| 10057 |
+
|
| 10058 |
+
``` cpp
|
| 10059 |
+
declval<T>() <=> declval<U>()
|
| 10060 |
+
```
|
| 10061 |
+
|
| 10062 |
+
resolves to a built-in operator comparing pointers.
|
| 10063 |
+
|
| 10064 |
+
``` cpp
|
| 10065 |
+
struct compare_three_way {
|
| 10066 |
+
template<class T, class U>
|
| 10067 |
+
requires three_way_comparable_with<T, U> || BUILTIN-PTR-THREE-WAY(T, U)
|
| 10068 |
+
constexpr auto operator()(T&& t, U&& u) const;
|
| 10069 |
+
|
| 10070 |
+
using is_transparent = unspecified;
|
| 10071 |
+
};
|
| 10072 |
+
```
|
| 10073 |
+
|
| 10074 |
+
``` cpp
|
| 10075 |
+
template<class T, class U>
|
| 10076 |
+
requires three_way_comparable_with<T, U> || BUILTIN-PTR-THREE-WAY(T, U)
|
| 10077 |
+
constexpr auto operator()(T&& t, U&& u) const;
|
| 10078 |
+
```
|
| 10079 |
+
|
| 10080 |
+
*Preconditions:* If the expression
|
| 10081 |
+
`std::forward<T>(t) <=> std::forward<U>(u)` results in a call to a
|
| 10082 |
+
built-in operator `<=>` comparing pointers of type `P`, the conversion
|
| 10083 |
+
sequences from both `T` and `U` to `P` are
|
| 10084 |
+
equality-preserving [[concepts.equality]].
|
| 10085 |
+
|
| 10086 |
+
*Effects:*
|
| 10087 |
+
|
| 10088 |
+
- If the expression `std::forward<T>(t) <=> std::forward<U>(u)` results
|
| 10089 |
+
in a call to a built-in operator `<=>` comparing pointers of type `P`,
|
| 10090 |
+
returns `strong_ordering::less` if (the converted value of) `t`
|
| 10091 |
+
precedes `u` in the implementation-defined strict total order over
|
| 10092 |
+
pointers [[defns.order.ptr]], `strong_ordering::greater` if `u`
|
| 10093 |
+
precedes `t`, and otherwise `strong_ordering::equal`.
|
| 10094 |
+
- Otherwise, equivalent to:
|
| 10095 |
+
`return std::forward<T>(t) <=> std::forward<U>(u);`
|
| 10096 |
+
|
| 10097 |
+
### Concept-constrained comparisons <a id="range.cmp">[[range.cmp]]</a>
|
| 10098 |
+
|
| 10099 |
+
In this subclause, `BUILTIN-PTR-CMP(T, op, U)` for types `T` and `U` and
|
| 10100 |
+
where op is an equality [[expr.eq]] or relational operator [[expr.rel]]
|
| 10101 |
+
is a boolean constant expression. `BUILTIN-PTR-CMP(T, op, U)` is `true`
|
| 10102 |
+
if and only if op in the expression `declval<T>() op declval<U>()`
|
| 10103 |
+
resolves to a built-in operator comparing pointers.
|
| 10104 |
+
|
| 10105 |
+
``` cpp
|
| 10106 |
+
struct ranges::equal_to {
|
| 10107 |
+
template<class T, class U>
|
| 10108 |
+
requires equality_comparable_with<T, U> || BUILTIN-PTR-CMP(T, ==, U)
|
| 10109 |
+
constexpr bool operator()(T&& t, U&& u) const;
|
| 10110 |
+
|
| 10111 |
+
using is_transparent = unspecified;
|
| 10112 |
+
};
|
| 10113 |
+
```
|
| 10114 |
+
|
| 10115 |
+
*Preconditions:* If the expression
|
| 10116 |
+
`std::forward<T>(t) == std::forward<U>(u)` results in a call to a
|
| 10117 |
+
built-in operator `==` comparing pointers of type `P`, the conversion
|
| 10118 |
+
sequences from both `T` and `U` to `P` are
|
| 10119 |
+
equality-preserving [[concepts.equality]].
|
| 10120 |
+
|
| 10121 |
+
*Effects:*
|
| 10122 |
+
|
| 10123 |
+
- If the expression `std::forward<T>(t) == std::forward<U>(u)` results
|
| 10124 |
+
in a call to a built-in operator `==` comparing pointers: returns
|
| 10125 |
+
`false` if either (the converted value of) `t` precedes `u` or `u`
|
| 10126 |
+
precedes `t` in the implementation-defined strict total order over
|
| 10127 |
+
pointers [[defns.order.ptr]] and otherwise `true`.
|
| 10128 |
+
- Otherwise, equivalent to:
|
| 10129 |
+
`return std::forward<T>(t) == std::forward<U>(u);`
|
| 10130 |
+
|
| 10131 |
+
``` cpp
|
| 10132 |
+
struct ranges::not_equal_to {
|
| 10133 |
+
template<class T, class U>
|
| 10134 |
+
requires equality_comparable_with<T, U> || BUILTIN-PTR-CMP(T, ==, U)
|
| 10135 |
+
constexpr bool operator()(T&& t, U&& u) const;
|
| 10136 |
+
|
| 10137 |
+
using is_transparent = unspecified;
|
| 10138 |
+
};
|
| 10139 |
+
```
|
| 10140 |
+
|
| 10141 |
+
`operator()` has effects equivalent to:
|
| 10142 |
+
|
| 10143 |
+
``` cpp
|
| 10144 |
+
return !ranges::equal_to{}(std::forward<T>(t), std::forward<U>(u));
|
| 10145 |
+
```
|
| 10146 |
+
|
| 10147 |
+
``` cpp
|
| 10148 |
+
struct ranges::greater {
|
| 10149 |
+
template<class T, class U>
|
| 10150 |
+
requires totally_ordered_with<T, U> || BUILTIN-PTR-CMP(U, <, T)
|
| 10151 |
+
constexpr bool operator()(T&& t, U&& u) const;
|
| 10152 |
+
|
| 10153 |
+
using is_transparent = unspecified;
|
| 10154 |
+
};
|
| 10155 |
+
```
|
| 10156 |
+
|
| 10157 |
+
`operator()` has effects equivalent to:
|
| 10158 |
+
|
| 10159 |
+
``` cpp
|
| 10160 |
+
return ranges::less{}(std::forward<U>(u), std::forward<T>(t));
|
| 10161 |
+
```
|
| 10162 |
+
|
| 10163 |
+
``` cpp
|
| 10164 |
+
struct ranges::less {
|
| 10165 |
+
template<class T, class U>
|
| 10166 |
+
requires totally_ordered_with<T, U> || BUILTIN-PTR-CMP(T, <, U)
|
| 10167 |
+
constexpr bool operator()(T&& t, U&& u) const;
|
| 10168 |
+
|
| 10169 |
+
using is_transparent = unspecified;
|
| 10170 |
+
};
|
| 10171 |
+
```
|
| 10172 |
+
|
| 10173 |
+
*Preconditions:* If the expression
|
| 10174 |
+
`std::forward<T>(t) < std::forward<U>(u)` results in a call to a
|
| 10175 |
+
built-in operator `<` comparing pointers of type `P`, the conversion
|
| 10176 |
+
sequences from both `T` and `U` to `P` are
|
| 10177 |
+
equality-preserving [[concepts.equality]]. For any expressions `ET` and
|
| 10178 |
+
`EU` such that `decltype((ET))` is `T` and `decltype((EU))` is `U`,
|
| 10179 |
+
exactly one of `ranges::less{}(ET, EU)`, `ranges::less{}(EU, ET)`, or
|
| 10180 |
+
`ranges::equal_to{}(ET, EU)` is `true`.
|
| 10181 |
+
|
| 10182 |
+
*Effects:*
|
| 10183 |
+
|
| 10184 |
+
- If the expression `std::forward<T>(t) < std::forward<U>(u)` results in
|
| 10185 |
+
a call to a built-in operator `<` comparing pointers: returns `true`
|
| 10186 |
+
if (the converted value of) `t` precedes `u` in the
|
| 10187 |
+
implementation-defined strict total order over
|
| 10188 |
+
pointers [[defns.order.ptr]] and otherwise `false`.
|
| 10189 |
+
- Otherwise, equivalent to:
|
| 10190 |
+
`return std::forward<T>(t) < std::forward<U>(u);`
|
| 10191 |
+
|
| 10192 |
+
``` cpp
|
| 10193 |
+
struct ranges::greater_equal {
|
| 10194 |
+
template<class T, class U>
|
| 10195 |
+
requires totally_ordered_with<T, U> || BUILTIN-PTR-CMP(T, <, U)
|
| 10196 |
+
constexpr bool operator()(T&& t, U&& u) const;
|
| 10197 |
+
|
| 10198 |
+
using is_transparent = unspecified;
|
| 10199 |
+
};
|
| 10200 |
+
```
|
| 10201 |
+
|
| 10202 |
+
`operator()` has effects equivalent to:
|
| 10203 |
+
|
| 10204 |
+
``` cpp
|
| 10205 |
+
return !ranges::less{}(std::forward<T>(t), std::forward<U>(u));
|
| 10206 |
+
```
|
| 10207 |
+
|
| 10208 |
+
``` cpp
|
| 10209 |
+
struct ranges::less_equal {
|
| 10210 |
+
template<class T, class U>
|
| 10211 |
+
requires totally_ordered_with<T, U> || BUILTIN-PTR-CMP(U, <, T)
|
| 10212 |
+
constexpr bool operator()(T&& t, U&& u) const;
|
| 10213 |
+
|
| 10214 |
+
using is_transparent = unspecified;
|
| 10215 |
+
};
|
| 10216 |
+
```
|
| 10217 |
+
|
| 10218 |
+
`operator()` has effects equivalent to:
|
| 10219 |
+
|
| 10220 |
+
``` cpp
|
| 10221 |
+
return !ranges::less{}(std::forward<U>(u), std::forward<T>(t));
|
| 10222 |
+
```
|
| 10223 |
+
|
| 10224 |
### Logical operations <a id="logical.operations">[[logical.operations]]</a>
|
| 10225 |
|
| 10226 |
The library provides basic function object classes for all of the
|
| 10227 |
logical operators in the language ([[expr.log.and]], [[expr.log.or]],
|
| 10228 |
[[expr.unary.op]]).
|
|
|
|
| 10441 |
-> decltype(~std::forward<T>(t));
|
| 10442 |
```
|
| 10443 |
|
| 10444 |
*Returns:* `~std::forward<T>(t)`.
|
| 10445 |
|
| 10446 |
+
### Class `identity` <a id="func.identity">[[func.identity]]</a>
|
| 10447 |
|
| 10448 |
``` cpp
|
| 10449 |
+
struct identity {
|
| 10450 |
+
template<class T>
|
| 10451 |
+
constexpr T&& operator()(T&& t) const noexcept;
|
| 10452 |
|
| 10453 |
+
using is_transparent = unspecified;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10454 |
};
|
| 10455 |
+
|
| 10456 |
+
template<class T>
|
| 10457 |
+
constexpr T&& operator()(T&& t) const noexcept;
|
| 10458 |
```
|
| 10459 |
|
| 10460 |
+
*Effects:* Equivalent to: `return std::forward<T>(t);`
|
| 10461 |
+
|
| 10462 |
+
### Function template `not_fn` <a id="func.not.fn">[[func.not.fn]]</a>
|
| 10463 |
+
|
| 10464 |
``` cpp
|
| 10465 |
+
template<class F> constexpr unspecified not_fn(F&& f);
|
| 10466 |
```
|
| 10467 |
|
| 10468 |
+
In the text that follows:
|
|
|
|
|
|
|
| 10469 |
|
| 10470 |
+
- `g` is a value of the result of a `not_fn` invocation,
|
| 10471 |
+
- `FD` is the type `decay_t<F>`,
|
| 10472 |
+
- `fd` is the target object of `g` [[func.def]] of type `FD`,
|
| 10473 |
+
direct-non-list-initialized with `std::forward<F>(f)`,
|
| 10474 |
+
- `call_args` is an argument pack used in a function call
|
| 10475 |
+
expression [[expr.call]] of `g`.
|
| 10476 |
|
| 10477 |
+
*Mandates:* `is_constructible_v<FD, F> && is_move_constructible_v<FD>`
|
| 10478 |
+
is `true`.
|
| 10479 |
|
| 10480 |
+
*Preconditions:* `FD` meets the *Cpp17MoveConstructible* requirements.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10481 |
|
| 10482 |
+
*Returns:* A perfect forwarding call wrapper `g` with call pattern
|
| 10483 |
+
`!invoke(fd, call_args...)`.
|
| 10484 |
|
| 10485 |
+
*Throws:* Any exception thrown by the initialization of `fd`.
|
| 10486 |
+
|
| 10487 |
+
### Function template `bind_front` <a id="func.bind.front">[[func.bind.front]]</a>
|
| 10488 |
|
| 10489 |
``` cpp
|
| 10490 |
+
template<class F, class... Args>
|
| 10491 |
+
constexpr unspecified bind_front(F&& f, Args&&... args);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10492 |
```
|
| 10493 |
|
| 10494 |
+
In the text that follows:
|
| 10495 |
+
|
| 10496 |
+
- `g` is a value of the result of a `bind_front` invocation,
|
| 10497 |
+
- `FD` is the type `decay_t<F>`,
|
| 10498 |
+
- `fd` is the target object of `g` [[func.def]] of type `FD`,
|
| 10499 |
+
direct-non-list-initialized with `std::forward<F>(f)`,
|
| 10500 |
+
- `BoundArgs` is a pack that denotes `decay_t<Args>...`,
|
| 10501 |
+
- `bound_args` is a pack of bound argument entities of `g` [[func.def]]
|
| 10502 |
+
of types `BoundArgs...`, direct-non-list-initialized with
|
| 10503 |
+
`std::forward<Args>(args)...`, respectively, and
|
| 10504 |
+
- `call_args` is an argument pack used in a function call
|
| 10505 |
+
expression [[expr.call]] of `g`.
|
| 10506 |
+
|
| 10507 |
+
*Mandates:*
|
| 10508 |
|
| 10509 |
``` cpp
|
| 10510 |
+
is_constructible_v<FD, F> &&
|
| 10511 |
+
is_move_constructible_v<FD> &&
|
| 10512 |
+
(is_constructible_v<BoundArgs, Args> && ...) &&
|
| 10513 |
+
(is_move_constructible_v<BoundArgs> && ...)
|
| 10514 |
```
|
| 10515 |
|
| 10516 |
+
is `true`.
|
| 10517 |
+
|
| 10518 |
+
*Preconditions:* `FD` meets the *Cpp17MoveConstructible* requirements.
|
| 10519 |
+
For each `Tᵢ` in `BoundArgs`, if `Tᵢ` is an object type, `Tᵢ` meets the
|
| 10520 |
+
*Cpp17MoveConstructible* requirements.
|
| 10521 |
+
|
| 10522 |
+
*Returns:* A perfect forwarding call wrapper `g` with call pattern
|
| 10523 |
+
`invoke(fd, bound_args..., call_args...)`.
|
| 10524 |
+
|
| 10525 |
+
*Throws:* Any exception thrown by the initialization of the state
|
| 10526 |
+
entities of `g` [[func.def]].
|
| 10527 |
+
|
| 10528 |
### Function object binders <a id="func.bind">[[func.bind]]</a>
|
| 10529 |
|
| 10530 |
This subclause describes a uniform mechanism for binding arguments of
|
| 10531 |
callable objects.
|
| 10532 |
|
|
|
|
| 10540 |
|
| 10541 |
The class template `is_bind_expression` can be used to detect function
|
| 10542 |
objects generated by `bind`. The function template `bind` uses
|
| 10543 |
`is_bind_expression` to detect subexpressions.
|
| 10544 |
|
| 10545 |
+
Specializations of the `is_bind_expression` template shall meet the
|
| 10546 |
+
*Cpp17UnaryTypeTrait* requirements [[meta.rqmts]]. The implementation
|
| 10547 |
+
provides a definition that has a base characteristic of `true_type` if
|
| 10548 |
+
`T` is a type returned from `bind`, otherwise it has a base
|
| 10549 |
characteristic of `false_type`. A program may specialize this template
|
| 10550 |
+
for a program-defined type `T` to have a base characteristic of
|
| 10551 |
+
`true_type` to indicate that `T` should be treated as a subexpression in
|
| 10552 |
+
a `bind` call.
|
| 10553 |
|
| 10554 |
#### Class template `is_placeholder` <a id="func.bind.isplace">[[func.bind.isplace]]</a>
|
| 10555 |
|
| 10556 |
``` cpp
|
| 10557 |
namespace std {
|
|
|
|
| 10561 |
|
| 10562 |
The class template `is_placeholder` can be used to detect the standard
|
| 10563 |
placeholders `_1`, `_2`, and so on. The function template `bind` uses
|
| 10564 |
`is_placeholder` to detect placeholders.
|
| 10565 |
|
| 10566 |
+
Specializations of the `is_placeholder` template shall meet the
|
| 10567 |
+
*Cpp17UnaryTypeTrait* requirements [[meta.rqmts]]. The implementation
|
| 10568 |
+
provides a definition that has the base characteristic of
|
| 10569 |
`integral_constant<int, J>` if `T` is the type of
|
| 10570 |
+
`std::placeholders::_J`, otherwise it has a base characteristic of
|
| 10571 |
+
`integral_constant<int, 0>`. A program may specialize this template for
|
| 10572 |
+
a program-defined type `T` to have a base characteristic of
|
| 10573 |
`integral_constant<int, N>` with `N > 0` to indicate that `T` should be
|
| 10574 |
treated as a placeholder type.
|
| 10575 |
|
| 10576 |
#### Function template `bind` <a id="func.bind.bind">[[func.bind.bind]]</a>
|
| 10577 |
|
| 10578 |
In the text that follows:
|
| 10579 |
|
| 10580 |
+
- `g` is a value of the result of a `bind` invocation,
|
| 10581 |
- `FD` is the type `decay_t<F>`,
|
| 10582 |
+
- `fd` is an lvalue that is a target object of `g` [[func.def]] of type
|
| 10583 |
+
`FD` direct-non-list-initialized with `std::forward<F>(f)`,
|
| 10584 |
- `Tᵢ` is the iᵗʰ type in the template parameter pack `BoundArgs`,
|
| 10585 |
- `TDᵢ` is the type `decay_t<Tᵢ>`,
|
| 10586 |
- `tᵢ` is the iᵗʰ argument in the function parameter pack `bound_args`,
|
| 10587 |
+
- `tdᵢ` is a bound argument entity of `g` [[func.def]] of type `TDᵢ`
|
| 10588 |
+
direct-non-list-initialized with `std::forward<{}Tᵢ>(tᵢ)`,
|
| 10589 |
- `Uⱼ` is the jᵗʰ deduced type of the `UnBoundArgs&&...` parameter of
|
| 10590 |
+
the argument forwarding call wrapper, and
|
| 10591 |
- `uⱼ` is the jᵗʰ argument associated with `Uⱼ`.
|
| 10592 |
|
| 10593 |
``` cpp
|
| 10594 |
template<class F, class... BoundArgs>
|
| 10595 |
+
constexpr unspecified bind(F&& f, BoundArgs&&... bound_args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10596 |
template<class R, class F, class... BoundArgs>
|
| 10597 |
+
constexpr unspecified bind(F&& f, BoundArgs&&... bound_args);
|
| 10598 |
```
|
| 10599 |
|
| 10600 |
+
*Mandates:* `is_constructible_v<FD, F>` is `true`. For each `Tᵢ` in
|
| 10601 |
+
`BoundArgs`, `is_constructible_v<``TDᵢ``, ``Tᵢ``>` is `true`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10602 |
|
| 10603 |
+
*Preconditions:* `FD` and each `TDᵢ` meet the *Cpp17MoveConstructible*
|
| 10604 |
+
and *Cpp17Destructible* requirements. *INVOKE*(fd, w₁, w₂, …,
|
| 10605 |
+
$w_N$) [[func.require]] is a valid expression for some values `w₁`,
|
| 10606 |
+
`w₂`, …, `w_N`, where N has the value `sizeof...(bound_args)`.
|
| 10607 |
+
|
| 10608 |
+
*Returns:* An argument forwarding call wrapper `g` [[func.require]]. A
|
| 10609 |
+
program that attempts to invoke a volatile-qualified `g` is ill-formed.
|
| 10610 |
+
When `g` is not volatile-qualified, invocation of
|
| 10611 |
+
`g(``u₁``, ``u₂``, `…`, ``u_M``)` is
|
| 10612 |
+
expression-equivalent [[defns.expression-equivalent]] to
|
| 10613 |
|
| 10614 |
``` cpp
|
| 10615 |
+
INVOKE(static_cast<$V_fd$>($v_fd$),
|
| 10616 |
+
static_cast<$V_1$>($v_1$), static_cast<$V_2$>($v_2$), …, static_cast<$V_N$>($v_N$))
|
| 10617 |
```
|
| 10618 |
|
| 10619 |
+
for the first overload, and
|
| 10620 |
+
|
| 10621 |
+
``` cpp
|
| 10622 |
+
INVOKE<R>(static_cast<$V_fd$>($v_fd$),
|
| 10623 |
+
static_cast<$V_1$>($v_1$), static_cast<$V_2$>($v_2$), …, static_cast<$V_N$>($v_N$))
|
| 10624 |
+
```
|
| 10625 |
|
| 10626 |
+
for the second overload, where the values and types of the target
|
| 10627 |
+
argument `v`_`fd` and of the bound arguments `v₁`, `v₂`, …, `v_N` are
|
| 10628 |
+
determined as specified below.
|
| 10629 |
|
| 10630 |
+
*Throws:* Any exception thrown by the initialization of the state
|
| 10631 |
+
entities of `g`.
|
|
|
|
|
|
|
| 10632 |
|
| 10633 |
+
[*Note 1*: If all of `FD` and `TDᵢ` meet the requirements of
|
| 10634 |
+
*Cpp17CopyConstructible*, then the return type meets the requirements of
|
| 10635 |
+
*Cpp17CopyConstructible*. — *end note*]
|
| 10636 |
|
| 10637 |
The values of the *bound arguments* `v₁`, `v₂`, …, `v_N` and their
|
| 10638 |
corresponding types `V₁`, `V₂`, …, `V_N` depend on the types `TDᵢ`
|
| 10639 |
derived from the call to `bind` and the cv-qualifiers cv of the call
|
| 10640 |
wrapper `g` as follows:
|
| 10641 |
|
| 10642 |
- if `TDᵢ` is `reference_wrapper<T>`, the argument is `tdᵢ.get()` and
|
| 10643 |
its type `Vᵢ` is `T&`;
|
| 10644 |
- if the value of `is_bind_expression_v<TDᵢ>` is `true`, the argument is
|
| 10645 |
+
``` cpp
|
| 10646 |
+
static_cast<cv `TD`_i&>(td_i)(std::forward<U_j>(u_j)...)
|
| 10647 |
+
```
|
| 10648 |
+
|
| 10649 |
+
and its type `Vᵢ` is `invoke_result_t<cv TDᵢ&, Uⱼ...>&&`;
|
| 10650 |
- if the value `j` of `is_placeholder_v<TDᵢ>` is not zero, the argument
|
| 10651 |
is `std::forward<Uⱼ>(uⱼ)` and its type `Vᵢ` is `Uⱼ&&`;
|
| 10652 |
+
- otherwise, the value is `tdᵢ` and its type `Vᵢ` is `cv TDᵢ&`.
|
| 10653 |
+
|
| 10654 |
+
The value of the target argument `v`_`fd` is `fd` and its corresponding
|
| 10655 |
+
type `V`_`fd` is `cv FD&`.
|
| 10656 |
|
| 10657 |
#### Placeholders <a id="func.bind.place">[[func.bind.place]]</a>
|
| 10658 |
|
| 10659 |
``` cpp
|
| 10660 |
namespace std::placeholders {
|
|
|
|
| 10666 |
.
|
| 10667 |
see below _M;
|
| 10668 |
}
|
| 10669 |
```
|
| 10670 |
|
| 10671 |
+
All placeholder types meet the *Cpp17DefaultConstructible* and
|
| 10672 |
+
*Cpp17CopyConstructible* requirements, and their default constructors
|
| 10673 |
+
and copy/move constructors are constexpr functions that do not throw
|
| 10674 |
+
exceptions. It is *implementation-defined* whether placeholder types
|
| 10675 |
+
meet the *Cpp17CopyAssignable* requirements, but if so, their copy
|
| 10676 |
+
assignment operators are constexpr functions that do not throw
|
| 10677 |
+
exceptions.
|
| 10678 |
|
| 10679 |
Placeholders should be defined as:
|
| 10680 |
|
| 10681 |
``` cpp
|
| 10682 |
inline constexpr unspecified _1{};
|
| 10683 |
```
|
| 10684 |
|
| 10685 |
+
If they are not, they are declared as:
|
| 10686 |
|
| 10687 |
``` cpp
|
| 10688 |
extern unspecified _1;
|
| 10689 |
```
|
| 10690 |
|
| 10691 |
### Function template `mem_fn` <a id="func.memfn">[[func.memfn]]</a>
|
| 10692 |
|
| 10693 |
``` cpp
|
| 10694 |
+
template<class R, class T> constexpr unspecified mem_fn(R T::* pm) noexcept;
|
| 10695 |
```
|
| 10696 |
|
| 10697 |
+
*Returns:* A simple call wrapper [[func.def]] `fn` with call pattern
|
| 10698 |
+
`invoke(pmd, call_args...)`, where `pmd` is the target object of `fn` of
|
| 10699 |
+
type `R T::*` direct-non-list-initialized with `pm`, and `call_args` is
|
| 10700 |
+
an argument pack used in a function call expression [[expr.call]] of
|
| 10701 |
+
`pm`.
|
| 10702 |
|
| 10703 |
### Polymorphic function wrappers <a id="func.wrap">[[func.wrap]]</a>
|
| 10704 |
|
| 10705 |
This subclause describes a polymorphic wrapper class that encapsulates
|
| 10706 |
arbitrary callable objects.
|
| 10707 |
|
| 10708 |
#### Class `bad_function_call` <a id="func.wrap.badcall">[[func.wrap.badcall]]</a>
|
| 10709 |
|
| 10710 |
An exception of type `bad_function_call` is thrown by
|
| 10711 |
+
`function::operator()` [[func.wrap.func.inv]] when the function wrapper
|
| 10712 |
+
object has no target.
|
| 10713 |
|
| 10714 |
``` cpp
|
| 10715 |
namespace std {
|
| 10716 |
class bad_function_call : public exception {
|
| 10717 |
public:
|
| 10718 |
+
// see [exception] for the specification of the special member functions
|
| 10719 |
+
const char* what() const noexcept override;
|
| 10720 |
};
|
| 10721 |
}
|
| 10722 |
```
|
| 10723 |
|
|
|
|
|
|
|
| 10724 |
``` cpp
|
| 10725 |
+
const char* what() const noexcept override;
|
| 10726 |
```
|
| 10727 |
|
| 10728 |
+
*Returns:* An *implementation-defined* NTBS.
|
|
|
|
|
|
|
| 10729 |
|
| 10730 |
#### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
|
| 10731 |
|
| 10732 |
``` cpp
|
| 10733 |
namespace std {
|
|
|
|
| 10740 |
|
| 10741 |
// [func.wrap.func.con], construct/copy/destroy
|
| 10742 |
function() noexcept;
|
| 10743 |
function(nullptr_t) noexcept;
|
| 10744 |
function(const function&);
|
| 10745 |
+
function(function&&) noexcept;
|
| 10746 |
template<class F> function(F);
|
| 10747 |
|
| 10748 |
function& operator=(const function&);
|
| 10749 |
function& operator=(function&&);
|
| 10750 |
function& operator=(nullptr_t) noexcept;
|
|
|
|
| 10771 |
template<class R, class... ArgTypes>
|
| 10772 |
function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>;
|
| 10773 |
|
| 10774 |
template<class F> function(F) -> function<see below>;
|
| 10775 |
|
| 10776 |
+
// [func.wrap.func.nullptr], null pointer comparison functions
|
| 10777 |
template<class R, class... ArgTypes>
|
| 10778 |
bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
|
| 10779 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10780 |
// [func.wrap.func.alg], specialized algorithms
|
| 10781 |
template<class R, class... ArgTypes>
|
| 10782 |
void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
|
| 10783 |
}
|
| 10784 |
```
|
| 10785 |
|
| 10786 |
The `function` class template provides polymorphic wrappers that
|
| 10787 |
generalize the notion of a function pointer. Wrappers can store, copy,
|
| 10788 |
+
and call arbitrary callable objects [[func.def]], given a call signature
|
| 10789 |
+
[[func.def]], allowing functions to be first-class objects.
|
| 10790 |
|
| 10791 |
+
A callable type [[func.def]] `F` is *Lvalue-Callable* for argument types
|
| 10792 |
+
`ArgTypes` and return type `R` if the expression
|
| 10793 |
`INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
|
| 10794 |
+
unevaluated operand [[expr.prop]], is well-formed [[func.require]].
|
|
|
|
| 10795 |
|
| 10796 |
+
The `function` class template is a call wrapper [[func.def]] whose call
|
| 10797 |
+
signature [[func.def]] is `R(ArgTypes...)`.
|
| 10798 |
|
| 10799 |
[*Note 1*: The types deduced by the deduction guides for `function` may
|
| 10800 |
change in future versions of this International Standard. — *end note*]
|
| 10801 |
|
| 10802 |
+
##### Constructors and destructor <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
|
| 10803 |
|
| 10804 |
``` cpp
|
| 10805 |
function() noexcept;
|
| 10806 |
```
|
| 10807 |
|
| 10808 |
+
*Ensures:* `!*this`.
|
| 10809 |
|
| 10810 |
``` cpp
|
| 10811 |
function(nullptr_t) noexcept;
|
| 10812 |
```
|
| 10813 |
|
| 10814 |
+
*Ensures:* `!*this`.
|
| 10815 |
|
| 10816 |
``` cpp
|
| 10817 |
function(const function& f);
|
| 10818 |
```
|
| 10819 |
|
| 10820 |
+
*Ensures:* `!*this` if `!f`; otherwise, `*this` targets a copy of
|
| 10821 |
`f.target()`.
|
| 10822 |
|
| 10823 |
+
*Throws:* Nothing if `f`’s target is a specialization of
|
| 10824 |
+
`reference_wrapper` or a function pointer. Otherwise, may throw
|
| 10825 |
`bad_alloc` or any exception thrown by the copy constructor of the
|
| 10826 |
stored callable object.
|
| 10827 |
|
| 10828 |
+
[*Note 1*: Implementations should avoid the use of dynamically
|
| 10829 |
+
allocated memory for small callable objects, for example, where `f`’s
|
| 10830 |
+
target is an object holding only a pointer or reference to an object and
|
| 10831 |
+
a member function pointer. — *end note*]
|
| 10832 |
|
| 10833 |
``` cpp
|
| 10834 |
+
function(function&& f) noexcept;
|
| 10835 |
```
|
| 10836 |
|
| 10837 |
+
*Ensures:* If `!f`, `*this` has no target; otherwise, the target of
|
| 10838 |
+
`*this` is equivalent to the target of `f` before the construction, and
|
| 10839 |
+
`f` is in a valid state with an unspecified value.
|
| 10840 |
|
| 10841 |
+
[*Note 2*: Implementations should avoid the use of dynamically
|
| 10842 |
+
allocated memory for small callable objects, for example, where `f`’s
|
| 10843 |
+
target is an object holding only a pointer or reference to an object and
|
| 10844 |
+
a member function pointer. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10845 |
|
| 10846 |
``` cpp
|
| 10847 |
template<class F> function(F f);
|
| 10848 |
```
|
| 10849 |
|
| 10850 |
+
*Constraints:* `F` is Lvalue-Callable [[func.wrap.func]] for argument
|
| 10851 |
+
types `ArgTypes...` and return type `R`.
|
| 10852 |
|
| 10853 |
+
*Preconditions:* `F` meets the *Cpp17CopyConstructible* requirements.
|
|
|
|
|
|
|
| 10854 |
|
| 10855 |
+
*Ensures:* `!*this` if any of the following hold:
|
| 10856 |
|
| 10857 |
- `f` is a null function pointer value.
|
| 10858 |
- `f` is a null member pointer value.
|
| 10859 |
- `F` is an instance of the `function` class template, and `!f`.
|
| 10860 |
|
| 10861 |
Otherwise, `*this` targets a copy of `f` initialized with
|
| 10862 |
`std::move(f)`.
|
| 10863 |
|
| 10864 |
+
[*Note 3*: Implementations should avoid the use of dynamically
|
| 10865 |
+
allocated memory for small callable objects, for example, where `f` is
|
| 10866 |
+
an object holding only a pointer or reference to an object and a member
|
| 10867 |
+
function pointer. — *end note*]
|
| 10868 |
|
| 10869 |
+
*Throws:* Nothing if `f` is a specialization of `reference_wrapper` or a
|
| 10870 |
+
function pointer. Otherwise, may throw `bad_alloc` or any exception
|
| 10871 |
+
thrown by `F`’s copy or move constructor.
|
| 10872 |
|
| 10873 |
``` cpp
|
| 10874 |
template<class F> function(F) -> function<see below>;
|
| 10875 |
```
|
| 10876 |
|
| 10877 |
+
*Constraints:* `&F::operator()` is well-formed when treated as an
|
| 10878 |
+
unevaluated operand and `decltype(&F::operator())` is of the form
|
| 10879 |
+
`R(G::*)(A...)` cv \\ₒₚₜ ` `noexceptₒₚₜ for a class type `G`.
|
| 10880 |
+
|
| 10881 |
+
*Remarks:* The deduced type is `function<R(A...)>`.
|
| 10882 |
|
| 10883 |
[*Example 1*:
|
| 10884 |
|
| 10885 |
``` cpp
|
| 10886 |
void f() {
|
|
|
|
| 10911 |
function& operator=(nullptr_t) noexcept;
|
| 10912 |
```
|
| 10913 |
|
| 10914 |
*Effects:* If `*this != nullptr`, destroys the target of `this`.
|
| 10915 |
|
| 10916 |
+
*Ensures:* `!(*this)`.
|
| 10917 |
|
| 10918 |
*Returns:* `*this`.
|
| 10919 |
|
| 10920 |
``` cpp
|
| 10921 |
template<class F> function& operator=(F&& f);
|
| 10922 |
```
|
| 10923 |
|
| 10924 |
+
*Constraints:* `decay_t<F>` is Lvalue-Callable [[func.wrap.func]] for
|
| 10925 |
+
argument types `ArgTypes...` and return type `R`.
|
| 10926 |
+
|
| 10927 |
*Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
|
| 10928 |
|
| 10929 |
*Returns:* `*this`.
|
| 10930 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10931 |
``` cpp
|
| 10932 |
template<class F> function& operator=(reference_wrapper<F> f) noexcept;
|
| 10933 |
```
|
| 10934 |
|
| 10935 |
*Effects:* As if by: `function(f).swap(*this);`
|
|
|
|
| 10940 |
~function();
|
| 10941 |
```
|
| 10942 |
|
| 10943 |
*Effects:* If `*this != nullptr`, destroys the target of `this`.
|
| 10944 |
|
| 10945 |
+
##### Modifiers <a id="func.wrap.func.mod">[[func.wrap.func.mod]]</a>
|
| 10946 |
|
| 10947 |
``` cpp
|
| 10948 |
void swap(function& other) noexcept;
|
| 10949 |
```
|
| 10950 |
|
| 10951 |
+
*Effects:* Interchanges the targets of `*this` and `other`.
|
| 10952 |
|
| 10953 |
+
##### Capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
|
| 10954 |
|
| 10955 |
``` cpp
|
| 10956 |
explicit operator bool() const noexcept;
|
| 10957 |
```
|
| 10958 |
|
| 10959 |
*Returns:* `true` if `*this` has a target, otherwise `false`.
|
| 10960 |
|
| 10961 |
+
##### Invocation <a id="func.wrap.func.inv">[[func.wrap.func.inv]]</a>
|
| 10962 |
|
| 10963 |
``` cpp
|
| 10964 |
R operator()(ArgTypes... args) const;
|
| 10965 |
```
|
| 10966 |
|
| 10967 |
*Returns:* *INVOKE*\<R\>(f,
|
| 10968 |
+
std::forward\<ArgTypes\>(args)...) [[func.require]], where `f` is the
|
| 10969 |
+
target object [[func.def]] of `*this`.
|
| 10970 |
|
| 10971 |
*Throws:* `bad_function_call` if `!*this`; otherwise, any exception
|
| 10972 |
thrown by the wrapped callable object.
|
| 10973 |
|
| 10974 |
+
##### Target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
|
| 10975 |
|
| 10976 |
``` cpp
|
| 10977 |
const type_info& target_type() const noexcept;
|
| 10978 |
```
|
| 10979 |
|
|
|
|
| 10986 |
```
|
| 10987 |
|
| 10988 |
*Returns:* If `target_type() == typeid(T)` a pointer to the stored
|
| 10989 |
function target; otherwise a null pointer.
|
| 10990 |
|
| 10991 |
+
##### Null pointer comparison functions <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
|
| 10992 |
|
| 10993 |
``` cpp
|
| 10994 |
template<class R, class... ArgTypes>
|
| 10995 |
bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
|
|
|
|
|
|
|
| 10996 |
```
|
| 10997 |
|
| 10998 |
*Returns:* `!f`.
|
| 10999 |
|
| 11000 |
+
##### Specialized algorithms <a id="func.wrap.func.alg">[[func.wrap.func.alg]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11001 |
|
| 11002 |
``` cpp
|
| 11003 |
template<class R, class... ArgTypes>
|
| 11004 |
void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
|
| 11005 |
```
|
| 11006 |
|
| 11007 |
*Effects:* As if by: `f1.swap(f2);`
|
| 11008 |
|
| 11009 |
### Searchers <a id="func.search">[[func.search]]</a>
|
| 11010 |
|
| 11011 |
+
This subclause provides function object types [[function.objects]] for
|
| 11012 |
+
operations that search for a sequence \[`pat``first`, `pat_last`) in
|
| 11013 |
another sequence \[`first`, `last`) that is provided to the object’s
|
| 11014 |
function call operator. The first sequence (the pattern to be searched
|
| 11015 |
for) is provided to the object’s constructor, and the second (the
|
| 11016 |
sequence to be searched) is provided to the function call operator.
|
| 11017 |
|
| 11018 |
Each specialization of a class template specified in this subclause
|
| 11019 |
+
[[func.search]] shall meet the *Cpp17CopyConstructible* and
|
| 11020 |
+
*Cpp17CopyAssignable* requirements. Template parameters named
|
| 11021 |
|
| 11022 |
- `ForwardIterator`,
|
| 11023 |
- `ForwardIterator1`,
|
| 11024 |
- `ForwardIterator2`,
|
| 11025 |
- `RandomAccessIterator`,
|
|
|
|
| 11027 |
- `RandomAccessIterator2`, and
|
| 11028 |
- `BinaryPredicate`
|
| 11029 |
|
| 11030 |
of templates specified in this subclause [[func.search]] shall meet the
|
| 11031 |
same requirements and semantics as specified in [[algorithms.general]].
|
| 11032 |
+
Template parameters named `Hash` shall meet the *Cpp17Hash* requirements
|
| 11033 |
+
([[cpp17.hash]]).
|
| 11034 |
|
| 11035 |
The Boyer-Moore searcher implements the Boyer-Moore search algorithm.
|
| 11036 |
The Boyer-Moore-Horspool searcher implements the Boyer-Moore-Horspool
|
| 11037 |
search algorithm. In general, the Boyer-Moore searcher will use more
|
| 11038 |
memory and give better runtime performance than Boyer-Moore-Horspool.
|
|
|
|
| 11041 |
|
| 11042 |
``` cpp
|
| 11043 |
template<class ForwardIterator1, class BinaryPredicate = equal_to<>>
|
| 11044 |
class default_searcher {
|
| 11045 |
public:
|
| 11046 |
+
constexpr default_searcher(ForwardIterator1 pat_first, ForwardIterator1 pat_last,
|
| 11047 |
BinaryPredicate pred = BinaryPredicate());
|
| 11048 |
|
| 11049 |
template<class ForwardIterator2>
|
| 11050 |
+
constexpr pair<ForwardIterator2, ForwardIterator2>
|
| 11051 |
operator()(ForwardIterator2 first, ForwardIterator2 last) const;
|
| 11052 |
|
| 11053 |
private:
|
| 11054 |
ForwardIterator1 pat_first_; // exposition only
|
| 11055 |
ForwardIterator1 pat_last_; // exposition only
|
| 11056 |
BinaryPredicate pred_; // exposition only
|
| 11057 |
};
|
| 11058 |
```
|
| 11059 |
|
| 11060 |
``` cpp
|
| 11061 |
+
constexpr default_searcher(ForwardIterator pat_first, ForwardIterator pat_last,
|
| 11062 |
BinaryPredicate pred = BinaryPredicate());
|
| 11063 |
```
|
| 11064 |
|
| 11065 |
*Effects:* Constructs a `default_searcher` object, initializing
|
| 11066 |
`pat_first_` with `pat_first`, \texttt{pat_last\_} with `pat_last`, and
|
|
|
|
| 11069 |
*Throws:* Any exception thrown by the copy constructor of
|
| 11070 |
`BinaryPredicate` or `ForwardIterator1`.
|
| 11071 |
|
| 11072 |
``` cpp
|
| 11073 |
template<class ForwardIterator2>
|
| 11074 |
+
constexpr pair<ForwardIterator2, ForwardIterator2>
|
| 11075 |
operator()(ForwardIterator2 first, ForwardIterator2 last) const;
|
| 11076 |
```
|
| 11077 |
|
| 11078 |
*Effects:* Returns a pair of iterators `i` and `j` such that
|
| 11079 |
|
|
|
|
| 11111 |
RandomAccessIterator1 pat_last,
|
| 11112 |
Hash hf = Hash(),
|
| 11113 |
BinaryPredicate pred = BinaryPredicate());
|
| 11114 |
```
|
| 11115 |
|
| 11116 |
+
*Preconditions:* The value type of `RandomAccessIterator1` meets the
|
| 11117 |
+
*Cpp17DefaultConstructible* requirements, the *Cpp17CopyConstructible*
|
| 11118 |
+
requirements, and the *Cpp17CopyAssignable* requirements.
|
| 11119 |
|
| 11120 |
+
*Preconditions:* Let `V` be
|
| 11121 |
+
`iterator_traits<RandomAccessIterator1>::value_type`. For any two values
|
| 11122 |
+
`A` and `B` of type `V`, if `pred(A, B) == true`, then `hf(A) == hf(B)`
|
| 11123 |
+
is `true`.
|
| 11124 |
|
| 11125 |
+
*Effects:* Initializes `pat_first_` with `pat_first`, `pat_last_` with
|
| 11126 |
+
`pat_last`, `hash_` with `hf`, and `pred_` with `pred`.
|
|
|
|
| 11127 |
|
| 11128 |
*Throws:* Any exception thrown by the copy constructor of
|
| 11129 |
`RandomAccessIterator1`, or by the default constructor, copy
|
| 11130 |
constructor, or the copy assignment operator of the value type of
|
| 11131 |
`RandomAccessIterator1`, or the copy constructor or `operator()` of
|
|
|
|
| 11136 |
template<class RandomAccessIterator2>
|
| 11137 |
pair<RandomAccessIterator2, RandomAccessIterator2>
|
| 11138 |
operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
|
| 11139 |
```
|
| 11140 |
|
| 11141 |
+
*Mandates:* `RandomAccessIterator1` and `RandomAccessIterator2` have the
|
| 11142 |
+
same value type.
|
| 11143 |
|
| 11144 |
*Effects:* Finds a subsequence of equal values in a sequence.
|
| 11145 |
|
| 11146 |
*Returns:* A pair of iterators `i` and `j` such that
|
| 11147 |
|
|
|
|
| 11188 |
RandomAccessIterator1 pat_last,
|
| 11189 |
Hash hf = Hash(),
|
| 11190 |
BinaryPredicate pred = BinaryPredicate());
|
| 11191 |
```
|
| 11192 |
|
| 11193 |
+
*Preconditions:* The value type of `RandomAccessIterator1` meets the
|
| 11194 |
+
*Cpp17DefaultConstructible*, *Cpp17CopyConstructible*, and
|
| 11195 |
+
*Cpp17CopyAssignable* requirements.
|
| 11196 |
|
| 11197 |
+
*Preconditions:* Let `V` be
|
| 11198 |
+
`iterator_traits<RandomAccessIterator1>::value_type`. For any two values
|
| 11199 |
+
`A` and `B` of type `V`, if `pred(A, B) == true`, then `hf(A) == hf(B)`
|
| 11200 |
+
is `true`.
|
| 11201 |
|
| 11202 |
+
*Effects:* Initializes `pat_first_` with `pat_first`, `pat_last_` with
|
| 11203 |
+
`pat_last`, `hash_` with `hf`, and `pred_` with `pred`.
|
|
|
|
| 11204 |
|
| 11205 |
*Throws:* Any exception thrown by the copy constructor of
|
| 11206 |
`RandomAccessIterator1`, or by the default constructor, copy
|
| 11207 |
constructor, or the copy assignment operator of the value type of
|
| 11208 |
`RandomAccessIterator1` or the copy constructor or `operator()` of
|
|
|
|
| 11213 |
template<class RandomAccessIterator2>
|
| 11214 |
pair<RandomAccessIterator2, RandomAccessIterator2>
|
| 11215 |
operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
|
| 11216 |
```
|
| 11217 |
|
| 11218 |
+
*Mandates:* `RandomAccessIterator1` and `RandomAccessIterator2` have the
|
| 11219 |
+
same value type.
|
| 11220 |
|
| 11221 |
*Effects:* Finds a subsequence of equal values in a sequence.
|
| 11222 |
|
| 11223 |
*Returns:* A pair of iterators `i` and `j` such that
|
| 11224 |
|
|
|
|
| 11236 |
applications of the predicate.
|
| 11237 |
|
| 11238 |
### Class template `hash` <a id="unord.hash">[[unord.hash]]</a>
|
| 11239 |
|
| 11240 |
The unordered associative containers defined in [[unord]] use
|
| 11241 |
+
specializations of the class template `hash` [[functional.syn]] as the
|
| 11242 |
+
default hash function.
|
| 11243 |
|
| 11244 |
Each specialization of `hash` is either enabled or disabled, as
|
| 11245 |
described below.
|
| 11246 |
|
| 11247 |
+
[*Note 1*: Enabled specializations meet the *Cpp17Hash* requirements,
|
| 11248 |
+
and disabled specializations do not. — *end note*]
|
| 11249 |
|
| 11250 |
Each header that declares the template `hash` provides enabled
|
| 11251 |
specializations of `hash` for `nullptr_t` and all cv-unqualified
|
| 11252 |
arithmetic, enumeration, and pointer types. For any type `Key` for which
|
| 11253 |
neither the library nor the user provides an explicit or partial
|
|
|
|
| 11259 |
|
| 11260 |
If `H` is a disabled specialization of `hash`, these values are `false`:
|
| 11261 |
`is_default_constructible_v<H>`, `is_copy_constructible_v<H>`,
|
| 11262 |
`is_move_constructible_v<H>`, `is_copy_assignable_v<H>`, and
|
| 11263 |
`is_move_assignable_v<H>`. Disabled specializations of `hash` are not
|
| 11264 |
+
function object types [[function.objects]].
|
| 11265 |
|
| 11266 |
[*Note 2*: This means that the specialization of `hash` exists, but any
|
| 11267 |
+
attempts to use it as a *Cpp17Hash* will be ill-formed. — *end note*]
|
| 11268 |
|
| 11269 |
An enabled specialization `hash<Key>` will:
|
| 11270 |
|
| 11271 |
+
- meet the *Cpp17Hash* requirements ([[cpp17.hash]]), with `Key` as the
|
| 11272 |
+
function call argument type, the *Cpp17DefaultConstructible*
|
| 11273 |
+
requirements ([[cpp17.defaultconstructible]]), the
|
| 11274 |
+
*Cpp17CopyAssignable* requirements ([[cpp17.copyassignable]]),
|
| 11275 |
+
- be swappable [[swappable.requirements]] for lvalues,
|
| 11276 |
+
- meet the requirement that if `k1 == k2` is `true`, `h(k1) == h(k2)` is
|
| 11277 |
+
also `true`, where `h` is an object of type `hash<Key>` and `k1` and
|
| 11278 |
+
`k2` are objects of type `Key`;
|
| 11279 |
+
- meet the requirement that the expression `h(k)`, where `h` is an
|
| 11280 |
object of type `hash<Key>` and `k` is an object of type `Key`, shall
|
| 11281 |
+
not throw an exception unless `hash<Key>` is a program-defined
|
| 11282 |
+
specialization that depends on at least one program-defined type.
|
| 11283 |
|
| 11284 |
## Metaprogramming and type traits <a id="meta">[[meta]]</a>
|
| 11285 |
|
| 11286 |
+
This subclause describes components used by C++ programs, particularly
|
| 11287 |
+
in templates, to support the widest possible range of types, optimise
|
| 11288 |
template code usage, detect type related user errors, and perform type
|
| 11289 |
inference and transformation at compile time. It includes type
|
| 11290 |
classification traits, type property inspection traits, and type
|
| 11291 |
transformations. The type classification traits describe a complete
|
| 11292 |
taxonomy of all possible C++ types, and state where in that taxonomy a
|
| 11293 |
given type belongs. The type property inspection traits allow important
|
| 11294 |
characteristics of types or of combinations of types to be inspected.
|
| 11295 |
The type transformations allow certain properties of types to be
|
| 11296 |
manipulated.
|
| 11297 |
|
| 11298 |
+
All functions specified in this subclause are signal-safe
|
| 11299 |
+
[[support.signal]].
|
| 11300 |
|
| 11301 |
### Requirements <a id="meta.rqmts">[[meta.rqmts]]</a>
|
| 11302 |
|
| 11303 |
+
A describes a property of a type. It shall be a class template that
|
| 11304 |
+
takes one template type argument and, optionally, additional arguments
|
| 11305 |
+
that help define the property being described. It shall be
|
| 11306 |
+
*Cpp17DefaultConstructible*, *Cpp17CopyConstructible*, and publicly and
|
| 11307 |
unambiguously derived, directly or indirectly, from its *base
|
| 11308 |
characteristic*, which is a specialization of the template
|
| 11309 |
+
`integral_constant` [[meta.help]], with the arguments to the template
|
| 11310 |
`integral_constant` determined by the requirements for the particular
|
| 11311 |
property being described. The member names of the base characteristic
|
| 11312 |
shall not be hidden and shall be unambiguously available in the
|
| 11313 |
+
*Cpp17UnaryTypeTrait*.
|
| 11314 |
|
| 11315 |
+
A describes a relationship between two types. It shall be a class
|
| 11316 |
+
template that takes two template type arguments and, optionally,
|
| 11317 |
+
additional arguments that help define the relationship being described.
|
| 11318 |
+
It shall be *Cpp17DefaultConstructible*, *Cpp17CopyConstructible*, and
|
| 11319 |
publicly and unambiguously derived, directly or indirectly, from its
|
| 11320 |
*base characteristic*, which is a specialization of the template
|
| 11321 |
+
`integral_constant` [[meta.help]], with the arguments to the template
|
| 11322 |
`integral_constant` determined by the requirements for the particular
|
| 11323 |
relationship being described. The member names of the base
|
| 11324 |
characteristic shall not be hidden and shall be unambiguously available
|
| 11325 |
+
in the *Cpp17BinaryTypeTrait*.
|
| 11326 |
|
| 11327 |
+
A modifies a property of a type. It shall be a class template that takes
|
| 11328 |
+
one template type argument and, optionally, additional arguments that
|
| 11329 |
+
help define the modification. It shall define a publicly accessible
|
| 11330 |
+
nested type named `type`, which shall be a synonym for the modified
|
| 11331 |
+
type.
|
| 11332 |
+
|
| 11333 |
+
Unless otherwise specified, the behavior of a program that adds
|
| 11334 |
+
specializations for any of the templates specified in this subclause
|
| 11335 |
+
[[meta]] is undefined.
|
| 11336 |
+
|
| 11337 |
+
Unless otherwise specified, an incomplete type may be used to
|
| 11338 |
+
instantiate a template specified in this subclause. The behavior of a
|
| 11339 |
+
program is undefined if:
|
| 11340 |
+
|
| 11341 |
+
- an instantiation of a template specified in subclause [[meta]]
|
| 11342 |
+
directly or indirectly depends on an incompletely-defined object type
|
| 11343 |
+
`T`, and
|
| 11344 |
+
- that instantiation could yield a different result were `T`
|
| 11345 |
+
hypothetically completed.
|
| 11346 |
|
| 11347 |
### Header `<type_traits>` synopsis <a id="meta.type.synop">[[meta.type.synop]]</a>
|
| 11348 |
|
| 11349 |
``` cpp
|
| 11350 |
namespace std {
|
|
|
|
| 11385 |
template<class T> struct is_const;
|
| 11386 |
template<class T> struct is_volatile;
|
| 11387 |
template<class T> struct is_trivial;
|
| 11388 |
template<class T> struct is_trivially_copyable;
|
| 11389 |
template<class T> struct is_standard_layout;
|
|
|
|
| 11390 |
template<class T> struct is_empty;
|
| 11391 |
template<class T> struct is_polymorphic;
|
| 11392 |
template<class T> struct is_abstract;
|
| 11393 |
template<class T> struct is_final;
|
| 11394 |
template<class T> struct is_aggregate;
|
| 11395 |
|
| 11396 |
template<class T> struct is_signed;
|
| 11397 |
template<class T> struct is_unsigned;
|
| 11398 |
+
template<class T> struct is_bounded_array;
|
| 11399 |
+
template<class T> struct is_unbounded_array;
|
| 11400 |
|
| 11401 |
template<class T, class... Args> struct is_constructible;
|
| 11402 |
template<class T> struct is_default_constructible;
|
| 11403 |
template<class T> struct is_copy_constructible;
|
| 11404 |
template<class T> struct is_move_constructible;
|
|
|
|
| 11447 |
|
| 11448 |
// [meta.rel], type relations
|
| 11449 |
template<class T, class U> struct is_same;
|
| 11450 |
template<class Base, class Derived> struct is_base_of;
|
| 11451 |
template<class From, class To> struct is_convertible;
|
| 11452 |
+
template<class From, class To> struct is_nothrow_convertible;
|
| 11453 |
+
template<class T, class U> struct is_layout_compatible;
|
| 11454 |
+
template<class Base, class Derived> struct is_pointer_interconvertible_base_of;
|
| 11455 |
|
| 11456 |
template<class Fn, class... ArgTypes> struct is_invocable;
|
| 11457 |
template<class R, class Fn, class... ArgTypes> struct is_invocable_r;
|
| 11458 |
|
| 11459 |
template<class Fn, class... ArgTypes> struct is_nothrow_invocable;
|
|
|
|
| 11518 |
using remove_pointer_t = typename remove_pointer<T>::type;
|
| 11519 |
template<class T>
|
| 11520 |
using add_pointer_t = typename add_pointer<T>::type;
|
| 11521 |
|
| 11522 |
// [meta.trans.other], other transformations
|
| 11523 |
+
template<class T> struct type_identity;
|
| 11524 |
+
template<size_t Len, size_t Align = default-alignment> // see [meta.trans.other]
|
| 11525 |
struct aligned_storage;
|
| 11526 |
template<size_t Len, class... Types> struct aligned_union;
|
| 11527 |
+
template<class T> struct remove_cvref;
|
| 11528 |
template<class T> struct decay;
|
| 11529 |
template<bool, class T = void> struct enable_if;
|
| 11530 |
template<bool, class T, class F> struct conditional;
|
| 11531 |
template<class... T> struct common_type;
|
| 11532 |
+
template<class T, class U, template<class> class TQual, template<class> class UQual>
|
| 11533 |
+
struct basic_common_reference { };
|
| 11534 |
+
template<class... T> struct common_reference;
|
| 11535 |
template<class T> struct underlying_type;
|
| 11536 |
template<class Fn, class... ArgTypes> struct invoke_result;
|
| 11537 |
+
template<class T> struct unwrap_reference;
|
| 11538 |
+
template<class T> struct unwrap_ref_decay;
|
| 11539 |
|
| 11540 |
+
template<class T>
|
| 11541 |
+
using type_identity_t = typename type_identity<T>::type;
|
| 11542 |
+
template<size_t Len, size_t Align = default-alignment> // see [meta.trans.other]
|
| 11543 |
using aligned_storage_t = typename aligned_storage<Len, Align>::type;
|
| 11544 |
template<size_t Len, class... Types>
|
| 11545 |
using aligned_union_t = typename aligned_union<Len, Types...>::type;
|
| 11546 |
+
template<class T>
|
| 11547 |
+
using remove_cvref_t = typename remove_cvref<T>::type;
|
| 11548 |
template<class T>
|
| 11549 |
using decay_t = typename decay<T>::type;
|
| 11550 |
template<bool b, class T = void>
|
| 11551 |
using enable_if_t = typename enable_if<b, T>::type;
|
| 11552 |
template<bool b, class T, class F>
|
| 11553 |
using conditional_t = typename conditional<b, T, F>::type;
|
| 11554 |
template<class... T>
|
| 11555 |
using common_type_t = typename common_type<T...>::type;
|
| 11556 |
+
template<class... T>
|
| 11557 |
+
using common_reference_t = typename common_reference<T...>::type;
|
| 11558 |
template<class T>
|
| 11559 |
using underlying_type_t = typename underlying_type<T>::type;
|
| 11560 |
template<class Fn, class... ArgTypes>
|
| 11561 |
using invoke_result_t = typename invoke_result<Fn, ArgTypes...>::type;
|
| 11562 |
+
template<class T>
|
| 11563 |
+
using unwrap_reference_t = typename unwrap_reference<T>::type;
|
| 11564 |
+
template<class T>
|
| 11565 |
+
using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type;
|
| 11566 |
template<class...>
|
| 11567 |
using void_t = void;
|
| 11568 |
|
| 11569 |
// [meta.logical], logical operator traits
|
| 11570 |
template<class... B> struct conjunction;
|
| 11571 |
template<class... B> struct disjunction;
|
| 11572 |
template<class B> struct negation;
|
| 11573 |
|
| 11574 |
// [meta.unary.cat], primary type categories
|
| 11575 |
+
template<class T>
|
| 11576 |
+
inline constexpr bool is_void_v = is_void<T>::value;
|
| 11577 |
+
template<class T>
|
| 11578 |
+
inline constexpr bool is_null_pointer_v = is_null_pointer<T>::value;
|
| 11579 |
+
template<class T>
|
| 11580 |
+
inline constexpr bool is_integral_v = is_integral<T>::value;
|
| 11581 |
+
template<class T>
|
| 11582 |
+
inline constexpr bool is_floating_point_v = is_floating_point<T>::value;
|
| 11583 |
+
template<class T>
|
| 11584 |
+
inline constexpr bool is_array_v = is_array<T>::value;
|
| 11585 |
+
template<class T>
|
| 11586 |
+
inline constexpr bool is_pointer_v = is_pointer<T>::value;
|
| 11587 |
+
template<class T>
|
| 11588 |
+
inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<T>::value;
|
| 11589 |
+
template<class T>
|
| 11590 |
+
inline constexpr bool is_rvalue_reference_v = is_rvalue_reference<T>::value;
|
| 11591 |
+
template<class T>
|
| 11592 |
+
inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<T>::value;
|
| 11593 |
+
template<class T>
|
| 11594 |
+
inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<T>::value;
|
| 11595 |
+
template<class T>
|
| 11596 |
+
inline constexpr bool is_enum_v = is_enum<T>::value;
|
| 11597 |
+
template<class T>
|
| 11598 |
+
inline constexpr bool is_union_v = is_union<T>::value;
|
| 11599 |
+
template<class T>
|
| 11600 |
+
inline constexpr bool is_class_v = is_class<T>::value;
|
| 11601 |
+
template<class T>
|
| 11602 |
+
inline constexpr bool is_function_v = is_function<T>::value;
|
| 11603 |
|
| 11604 |
// [meta.unary.comp], composite type categories
|
| 11605 |
+
template<class T>
|
| 11606 |
+
inline constexpr bool is_reference_v = is_reference<T>::value;
|
| 11607 |
+
template<class T>
|
| 11608 |
+
inline constexpr bool is_arithmetic_v = is_arithmetic<T>::value;
|
| 11609 |
+
template<class T>
|
| 11610 |
+
inline constexpr bool is_fundamental_v = is_fundamental<T>::value;
|
| 11611 |
+
template<class T>
|
| 11612 |
+
inline constexpr bool is_object_v = is_object<T>::value;
|
| 11613 |
+
template<class T>
|
| 11614 |
+
inline constexpr bool is_scalar_v = is_scalar<T>::value;
|
| 11615 |
+
template<class T>
|
| 11616 |
+
inline constexpr bool is_compound_v = is_compound<T>::value;
|
| 11617 |
+
template<class T>
|
| 11618 |
+
inline constexpr bool is_member_pointer_v = is_member_pointer<T>::value;
|
| 11619 |
|
| 11620 |
// [meta.unary.prop], type properties
|
| 11621 |
+
template<class T>
|
| 11622 |
+
inline constexpr bool is_const_v = is_const<T>::value;
|
| 11623 |
+
template<class T>
|
| 11624 |
+
inline constexpr bool is_volatile_v = is_volatile<T>::value;
|
| 11625 |
+
template<class T>
|
| 11626 |
+
inline constexpr bool is_trivial_v = is_trivial<T>::value;
|
| 11627 |
+
template<class T>
|
| 11628 |
+
inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::value;
|
| 11629 |
+
template<class T>
|
| 11630 |
+
inline constexpr bool is_standard_layout_v = is_standard_layout<T>::value;
|
| 11631 |
+
template<class T>
|
| 11632 |
+
inline constexpr bool is_empty_v = is_empty<T>::value;
|
| 11633 |
+
template<class T>
|
| 11634 |
+
inline constexpr bool is_polymorphic_v = is_polymorphic<T>::value;
|
| 11635 |
+
template<class T>
|
| 11636 |
+
inline constexpr bool is_abstract_v = is_abstract<T>::value;
|
| 11637 |
+
template<class T>
|
| 11638 |
+
inline constexpr bool is_final_v = is_final<T>::value;
|
| 11639 |
+
template<class T>
|
| 11640 |
+
inline constexpr bool is_aggregate_v = is_aggregate<T>::value;
|
| 11641 |
+
template<class T>
|
| 11642 |
+
inline constexpr bool is_signed_v = is_signed<T>::value;
|
| 11643 |
+
template<class T>
|
| 11644 |
+
inline constexpr bool is_unsigned_v = is_unsigned<T>::value;
|
| 11645 |
+
template<class T>
|
| 11646 |
+
inline constexpr bool is_bounded_array_v = is_bounded_array<T>::value;
|
| 11647 |
+
template<class T>
|
| 11648 |
+
inline constexpr bool is_unbounded_array_v = is_unbounded_array<T>::value;
|
| 11649 |
+
template<class T, class... Args>
|
| 11650 |
+
inline constexpr bool is_constructible_v = is_constructible<T, Args...>::value;
|
| 11651 |
+
template<class T>
|
| 11652 |
+
inline constexpr bool is_default_constructible_v = is_default_constructible<T>::value;
|
| 11653 |
+
template<class T>
|
| 11654 |
+
inline constexpr bool is_copy_constructible_v = is_copy_constructible<T>::value;
|
| 11655 |
+
template<class T>
|
| 11656 |
+
inline constexpr bool is_move_constructible_v = is_move_constructible<T>::value;
|
| 11657 |
+
template<class T, class U>
|
| 11658 |
+
inline constexpr bool is_assignable_v = is_assignable<T, U>::value;
|
| 11659 |
+
template<class T>
|
| 11660 |
+
inline constexpr bool is_copy_assignable_v = is_copy_assignable<T>::value;
|
| 11661 |
+
template<class T>
|
| 11662 |
+
inline constexpr bool is_move_assignable_v = is_move_assignable<T>::value;
|
| 11663 |
+
template<class T, class U>
|
| 11664 |
+
inline constexpr bool is_swappable_with_v = is_swappable_with<T, U>::value;
|
| 11665 |
+
template<class T>
|
| 11666 |
+
inline constexpr bool is_swappable_v = is_swappable<T>::value;
|
| 11667 |
+
template<class T>
|
| 11668 |
+
inline constexpr bool is_destructible_v = is_destructible<T>::value;
|
| 11669 |
+
template<class T, class... Args>
|
| 11670 |
+
inline constexpr bool is_trivially_constructible_v
|
| 11671 |
= is_trivially_constructible<T, Args...>::value;
|
| 11672 |
+
template<class T>
|
| 11673 |
+
inline constexpr bool is_trivially_default_constructible_v
|
| 11674 |
= is_trivially_default_constructible<T>::value;
|
| 11675 |
+
template<class T>
|
| 11676 |
+
inline constexpr bool is_trivially_copy_constructible_v
|
| 11677 |
= is_trivially_copy_constructible<T>::value;
|
| 11678 |
+
template<class T>
|
| 11679 |
+
inline constexpr bool is_trivially_move_constructible_v
|
| 11680 |
= is_trivially_move_constructible<T>::value;
|
| 11681 |
+
template<class T, class U>
|
| 11682 |
+
inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<T, U>::value;
|
| 11683 |
+
template<class T>
|
| 11684 |
+
inline constexpr bool is_trivially_copy_assignable_v
|
| 11685 |
= is_trivially_copy_assignable<T>::value;
|
| 11686 |
+
template<class T>
|
| 11687 |
+
inline constexpr bool is_trivially_move_assignable_v
|
| 11688 |
= is_trivially_move_assignable<T>::value;
|
| 11689 |
+
template<class T>
|
| 11690 |
+
inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<T>::value;
|
| 11691 |
+
template<class T, class... Args>
|
| 11692 |
+
inline constexpr bool is_nothrow_constructible_v
|
| 11693 |
= is_nothrow_constructible<T, Args...>::value;
|
| 11694 |
+
template<class T>
|
| 11695 |
+
inline constexpr bool is_nothrow_default_constructible_v
|
| 11696 |
= is_nothrow_default_constructible<T>::value;
|
| 11697 |
+
template<class T>
|
| 11698 |
+
inline constexpr bool is_nothrow_copy_constructible_v
|
| 11699 |
= is_nothrow_copy_constructible<T>::value;
|
| 11700 |
+
template<class T>
|
| 11701 |
+
inline constexpr bool is_nothrow_move_constructible_v
|
| 11702 |
= is_nothrow_move_constructible<T>::value;
|
| 11703 |
+
template<class T, class U>
|
| 11704 |
+
inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<T, U>::value;
|
| 11705 |
+
template<class T>
|
| 11706 |
+
inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<T>::value;
|
| 11707 |
+
template<class T>
|
| 11708 |
+
inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<T>::value;
|
| 11709 |
+
template<class T, class U>
|
| 11710 |
+
inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<T, U>::value;
|
| 11711 |
+
template<class T>
|
| 11712 |
+
inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<T>::value;
|
| 11713 |
+
template<class T>
|
| 11714 |
+
inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<T>::value;
|
| 11715 |
+
template<class T>
|
| 11716 |
+
inline constexpr bool has_virtual_destructor_v = has_virtual_destructor<T>::value;
|
| 11717 |
+
template<class T>
|
| 11718 |
+
inline constexpr bool has_unique_object_representations_v
|
| 11719 |
= has_unique_object_representations<T>::value;
|
| 11720 |
|
| 11721 |
// [meta.unary.prop.query], type property queries
|
| 11722 |
+
template<class T>
|
| 11723 |
+
inline constexpr size_t alignment_of_v = alignment_of<T>::value;
|
| 11724 |
+
template<class T>
|
| 11725 |
+
inline constexpr size_t rank_v = rank<T>::value;
|
| 11726 |
+
template<class T, unsigned I = 0>
|
| 11727 |
+
inline constexpr size_t extent_v = extent<T, I>::value;
|
| 11728 |
|
| 11729 |
// [meta.rel], type relations
|
| 11730 |
+
template<class T, class U>
|
| 11731 |
+
inline constexpr bool is_same_v = is_same<T, U>::value;
|
| 11732 |
+
template<class Base, class Derived>
|
| 11733 |
+
inline constexpr bool is_base_of_v = is_base_of<Base, Derived>::value;
|
| 11734 |
+
template<class From, class To>
|
| 11735 |
+
inline constexpr bool is_convertible_v = is_convertible<From, To>::value;
|
| 11736 |
+
template<class From, class To>
|
| 11737 |
+
inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<From, To>::value;
|
| 11738 |
+
template<class T, class U>
|
| 11739 |
+
inline constexpr bool is_layout_compatible_v = is_layout_compatible<T, U>::value;
|
| 11740 |
+
template<class Base, class Derived>
|
| 11741 |
+
inline constexpr bool is_pointer_interconvertible_base_of_v
|
| 11742 |
+
= is_pointer_interconvertible_base_of<Base, Derived>::value;
|
| 11743 |
+
template<class Fn, class... ArgTypes>
|
| 11744 |
+
inline constexpr bool is_invocable_v = is_invocable<Fn, ArgTypes...>::value;
|
| 11745 |
+
template<class R, class Fn, class... ArgTypes>
|
| 11746 |
+
inline constexpr bool is_invocable_r_v = is_invocable_r<R, Fn, ArgTypes...>::value;
|
| 11747 |
+
template<class Fn, class... ArgTypes>
|
| 11748 |
+
inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<Fn, ArgTypes...>::value;
|
| 11749 |
+
template<class R, class Fn, class... ArgTypes>
|
| 11750 |
+
inline constexpr bool is_nothrow_invocable_r_v
|
| 11751 |
= is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;
|
| 11752 |
|
| 11753 |
// [meta.logical], logical operator traits
|
| 11754 |
+
template<class... B>
|
| 11755 |
+
inline constexpr bool conjunction_v = conjunction<B...>::value;
|
| 11756 |
+
template<class... B>
|
| 11757 |
+
inline constexpr bool disjunction_v = disjunction<B...>::value;
|
| 11758 |
+
template<class B>
|
| 11759 |
+
inline constexpr bool negation_v = negation<B>::value;
|
| 11760 |
+
|
| 11761 |
+
// [meta.member], member relationships
|
| 11762 |
+
template<class S, class M>
|
| 11763 |
+
constexpr bool is_pointer_interconvertible_with_class(M S::*m) noexcept;
|
| 11764 |
+
template<class S1, class S2, class M1, class M2>
|
| 11765 |
+
constexpr bool is_corresponding_member(M1 S1::*m1, M2 S2::*m2) noexcept;
|
| 11766 |
+
|
| 11767 |
+
// [meta.const.eval], constant evaluation context
|
| 11768 |
+
constexpr bool is_constant_evaluated() noexcept;
|
| 11769 |
}
|
| 11770 |
```
|
| 11771 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11772 |
### Helper classes <a id="meta.help">[[meta.help]]</a>
|
| 11773 |
|
| 11774 |
``` cpp
|
| 11775 |
namespace std {
|
| 11776 |
+
template<class T, T v> struct integral_constant {
|
|
|
|
| 11777 |
static constexpr T value = v;
|
| 11778 |
+
|
| 11779 |
using value_type = T;
|
| 11780 |
using type = integral_constant<T, v>;
|
| 11781 |
+
|
| 11782 |
constexpr operator value_type() const noexcept { return value; }
|
| 11783 |
constexpr value_type operator()() const noexcept { return value; }
|
| 11784 |
};
|
| 11785 |
}
|
| 11786 |
```
|
|
|
|
| 11792 |
### Unary type traits <a id="meta.unary">[[meta.unary]]</a>
|
| 11793 |
|
| 11794 |
This subclause contains templates that may be used to query the
|
| 11795 |
properties of a type at compile time.
|
| 11796 |
|
| 11797 |
+
Each of these templates shall be a *Cpp17UnaryTypeTrait* [[meta.rqmts]]
|
| 11798 |
with a base characteristic of `true_type` if the corresponding condition
|
| 11799 |
is `true`, otherwise `false_type`.
|
| 11800 |
|
| 11801 |
#### Primary type categories <a id="meta.unary.cat">[[meta.unary.cat]]</a>
|
| 11802 |
|
| 11803 |
The primary type categories correspond to the descriptions given in
|
| 11804 |
+
subclause [[basic.types]] of the C++ standard.
|
| 11805 |
|
| 11806 |
For any given type `T`, the result of applying one of these templates to
|
| 11807 |
`T` and to cv `T` shall yield the same result.
|
| 11808 |
|
| 11809 |
[*Note 1*: For any given type `T`, exactly one of the primary type
|
| 11810 |
categories has a `value` member that evaluates to `true`. — *end note*]
|
| 11811 |
|
| 11812 |
#### Composite type traits <a id="meta.unary.comp">[[meta.unary.comp]]</a>
|
| 11813 |
|
| 11814 |
These templates provide convenient compositions of the primary type
|
| 11815 |
+
categories, corresponding to the descriptions given in subclause
|
| 11816 |
[[basic.types]].
|
| 11817 |
|
| 11818 |
For any given type `T`, the result of applying one of these templates to
|
| 11819 |
`T` and to cv `T` shall yield the same result.
|
| 11820 |
|
|
|
|
| 11828 |
|
| 11829 |
For all of the class templates `X` declared in this subclause,
|
| 11830 |
instantiating that template with a template-argument that is a class
|
| 11831 |
template specialization may result in the implicit instantiation of the
|
| 11832 |
template argument if and only if the semantics of `X` require that the
|
| 11833 |
+
argument is a complete type.
|
| 11834 |
|
| 11835 |
For the purpose of defining the templates in this subclause, a function
|
| 11836 |
call expression `declval<T>()` for any type `T` is considered to be a
|
| 11837 |
trivial ([[basic.types]], [[special]]) function call that is not an
|
| 11838 |
+
odr-use [[basic.def.odr]] of `declval` in the context of the
|
| 11839 |
corresponding definition notwithstanding the restrictions of
|
| 11840 |
[[declval]].
|
| 11841 |
|
| 11842 |
[*Note 1*: A union is a class type that can be marked with
|
| 11843 |
`final`. — *end note*]
|
|
|
|
| 11918 |
|
| 11919 |
The set of scalar types for which this condition holds is
|
| 11920 |
*implementation-defined*.
|
| 11921 |
|
| 11922 |
[*Note 4*: If a type has padding bits, the condition does not hold;
|
| 11923 |
+
otherwise, the condition holds true for integral types. — *end note*]
|
|
|
|
| 11924 |
|
| 11925 |
### Type property queries <a id="meta.unary.prop.query">[[meta.unary.prop.query]]</a>
|
| 11926 |
|
| 11927 |
This subclause contains templates that may be used to query properties
|
| 11928 |
of types at compile time.
|
| 11929 |
|
| 11930 |
+
Each of these templates shall be a *Cpp17UnaryTypeTrait* [[meta.rqmts]]
|
| 11931 |
with a base characteristic of `integral_constant<size_t, Value>`.
|
| 11932 |
|
| 11933 |
[*Example 1*:
|
| 11934 |
|
| 11935 |
``` cpp
|
|
|
|
| 11960 |
### Relationships between types <a id="meta.rel">[[meta.rel]]</a>
|
| 11961 |
|
| 11962 |
This subclause contains templates that may be used to query
|
| 11963 |
relationships between types at compile time.
|
| 11964 |
|
| 11965 |
+
Each of these templates shall be a *Cpp17BinaryTypeTrait* [[meta.rqmts]]
|
| 11966 |
with a base characteristic of `true_type` if the corresponding condition
|
| 11967 |
is true, otherwise `false_type`.
|
| 11968 |
|
| 11969 |
[*Note 1*: Base classes that are private, protected, or ambiguous are,
|
| 11970 |
nonetheless, base classes. — *end note*]
|
| 11971 |
|
| 11972 |
For the purpose of defining the templates in this subclause, a function
|
| 11973 |
call expression `declval<T>()` for any type `T` is considered to be a
|
| 11974 |
trivial ([[basic.types]], [[special]]) function call that is not an
|
| 11975 |
+
odr-use [[basic.def.odr]] of `declval` in the context of the
|
| 11976 |
corresponding definition notwithstanding the restrictions of
|
| 11977 |
[[declval]].
|
| 11978 |
|
| 11979 |
[*Example 1*:
|
| 11980 |
|
|
|
|
| 12005 |
To test() {
|
| 12006 |
return declval<From>();
|
| 12007 |
}
|
| 12008 |
```
|
| 12009 |
|
| 12010 |
+
[*Note 2*: This requirement gives well-defined results for reference
|
| 12011 |
types, void types, array types, and function types. — *end note*]
|
| 12012 |
|
| 12013 |
Access checking is performed in a context unrelated to `To` and `From`.
|
| 12014 |
Only the validity of the immediate context of the *expression* of the
|
| 12015 |
+
`return` statement [[stmt.return]] (including initialization of the
|
| 12016 |
+
returned object or reference) is considered.
|
| 12017 |
|
| 12018 |
[*Note 3*: The initialization can result in side effects such as the
|
| 12019 |
instantiation of class template specializations and function template
|
| 12020 |
specializations, the generation of implicitly-defined functions, and so
|
| 12021 |
on. Such side effects are not in the “immediate context” and can result
|
|
|
|
| 12025 |
|
| 12026 |
This subclause contains templates that may be used to transform one type
|
| 12027 |
to another following some predefined rule.
|
| 12028 |
|
| 12029 |
Each of the templates in this subclause shall be a
|
| 12030 |
+
*Cpp17TransformationTrait* [[meta.rqmts]].
|
| 12031 |
|
| 12032 |
#### Const-volatile modifications <a id="meta.trans.cv">[[meta.trans.cv]]</a>
|
| 12033 |
|
| 12034 |
[*Example 1*: `remove_const_t<const volatile int>` evaluates to
|
| 12035 |
`volatile int`, whereas `remove_const_t<const int*>` evaluates to
|
| 12036 |
`const int*`. — *end example*]
|
| 12037 |
|
| 12038 |
#### Reference modifications <a id="meta.trans.ref">[[meta.trans.ref]]</a>
|
| 12039 |
|
| 12040 |
+
[*Note 1*: This rule reflects the semantics of reference collapsing
|
| 12041 |
+
[[dcl.ref]]. — *end note*]
|
| 12042 |
|
| 12043 |
#### Sign modifications <a id="meta.trans.sign">[[meta.trans.sign]]</a>
|
| 12044 |
|
| 12045 |
#### Array modifications <a id="meta.trans.arr">[[meta.trans.arr]]</a>
|
| 12046 |
|
|
|
|
| 12074 |
|
| 12075 |
#### Pointer modifications <a id="meta.trans.ptr">[[meta.trans.ptr]]</a>
|
| 12076 |
|
| 12077 |
#### Other transformations <a id="meta.trans.other">[[meta.trans.other]]</a>
|
| 12078 |
|
| 12079 |
+
[*Note 1*: This behavior is similar to the lvalue-to-rvalue
|
| 12080 |
+
[[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
|
| 12081 |
+
[[conv.func]] conversions applied when an lvalue is used as an rvalue,
|
| 12082 |
+
but also strips cv-qualifiers from class types in order to more closely
|
| 12083 |
+
model by-value argument passing. — *end note*]
|
|
|
|
| 12084 |
|
| 12085 |
[*Note 2*:
|
| 12086 |
|
| 12087 |
A typical implementation would define `aligned_storage` as:
|
| 12088 |
|
|
|
|
| 12095 |
};
|
| 12096 |
```
|
| 12097 |
|
| 12098 |
— *end note*]
|
| 12099 |
|
| 12100 |
+
In addition to being available via inclusion of the `<type_traits>`
|
| 12101 |
+
header, the templates `unwrap_reference`, `unwrap_ref_decay`,
|
| 12102 |
+
`unwrap_reference_t`, and `unwrap_ref_decay_t` are available when the
|
| 12103 |
+
header `<functional>` [[functional.syn]] is included.
|
| 12104 |
|
| 12105 |
+
Let:
|
| 12106 |
+
|
| 12107 |
+
- `CREF(A)` be `add_lvalue_reference_t<const remove_reference_t<A>{}>`,
|
| 12108 |
+
- `XREF(A)` denote a unary alias template `T` such that `T<U>` denotes
|
| 12109 |
+
the same type as `U` with the addition of `A`’s cv and reference
|
| 12110 |
+
qualifiers, for a non-reference cv-unqualified type `U`,
|
| 12111 |
+
- `COPYCV(FROM, TO)` be an alias for type `TO` with the addition of
|
| 12112 |
+
`FROM`’s top-level cv-qualifiers,
|
| 12113 |
+
\[*Example 1*: `COPYCV(const int, volatile short)` is an alias for
|
| 12114 |
+
`const volatile short`. — *end example*]
|
| 12115 |
+
- `COND-RES(X, Y)` be
|
| 12116 |
+
`decltype(false ? declval<X(&)()>()() : declval<Y(&)()>()())`.
|
| 12117 |
+
|
| 12118 |
+
Given types `A` and `B`, let `X` be `remove_reference_t<A>`, let `Y` be
|
| 12119 |
+
`remove_reference_t<B>`, and let `COMMON-{REF}(A, B)` be:
|
| 12120 |
+
|
| 12121 |
+
- If `A` and `B` are both lvalue reference types, `COMMON-REF(A, B)` is
|
| 12122 |
+
`COND-RES(COPYCV(X, Y) &,
|
| 12123 |
+
COPYCV({}Y, X) &)` if that type exists and is a reference type.
|
| 12124 |
+
- Otherwise, let `C` be `remove_reference_t<COMMON-REF(X&, Y&)>&&`. If
|
| 12125 |
+
`A` and `B` are both rvalue reference types, `C` is well-formed, and
|
| 12126 |
+
`is_convertible_v<A, C> && is_convertible_v<B, C>` is `true`, then
|
| 12127 |
+
`COMMON-REF(A, B)` is `C`.
|
| 12128 |
+
- Otherwise, let `D` be `COMMON-REF(const X&, Y&)`. If `A` is an rvalue
|
| 12129 |
+
reference and `B` is an lvalue reference and `D` is well-formed and
|
| 12130 |
+
`is_convertible_v<A, D>` is `true`, then `COMMON-REF(A, B)` is `D`.
|
| 12131 |
+
- Otherwise, if `A` is an lvalue reference and `B` is an rvalue
|
| 12132 |
+
reference, then `COMMON-REF(A, B)` is `COMMON-REF(B, A)`.
|
| 12133 |
+
- Otherwise, `COMMON-REF(A, B)` is ill-formed.
|
| 12134 |
+
|
| 12135 |
+
If any of the types computed above is ill-formed, then
|
| 12136 |
+
`COMMON-REF(A, B)` is ill-formed.
|
| 12137 |
+
|
| 12138 |
+
Note A: For the `common_type` trait applied to a template parameter pack
|
| 12139 |
+
`T` of types, the member `type` shall be either defined or not present
|
| 12140 |
+
as follows:
|
| 12141 |
|
| 12142 |
- If `sizeof...(T)` is zero, there shall be no member `type`.
|
| 12143 |
- If `sizeof...(T)` is one, let `T0` denote the sole type constituting
|
| 12144 |
the pack `T`. The member *typedef-name* `type` shall denote the same
|
| 12145 |
type, if any, as `common_type_t<T0, T0>`; otherwise there shall be no
|
|
|
|
| 12148 |
`T` be denoted by `T1` and `T2`, respectively, and let `D1` and `D2`
|
| 12149 |
denote the same types as `decay_t<T1>` and `decay_t<T2>`,
|
| 12150 |
respectively.
|
| 12151 |
- If `is_same_v<T1, D1>` is `false` or `is_same_v<T2, D2>` is `false`,
|
| 12152 |
let `C` denote the same type, if any, as `common_type_t<D1, D2>`.
|
| 12153 |
+
- \[*Note 3*: None of the following will apply if there is a
|
| 12154 |
+
specialization `common_type<D1, D2>`. — *end note*]
|
| 12155 |
+
- Otherwise, if
|
| 12156 |
``` cpp
|
| 12157 |
decay_t<decltype(false ? declval<D1>() : declval<D2>())>
|
| 12158 |
```
|
| 12159 |
|
| 12160 |
+
denotes a valid type, let `C` denote that type.
|
| 12161 |
+
- Otherwise, if `COND-RES(CREF(D1),
|
| 12162 |
+
CREF(D2))` denotes a type, let `C` denote the type
|
| 12163 |
+
`decay_t<COND-RES(CREF(D1),
|
| 12164 |
+
CREF(D2))>`.
|
| 12165 |
|
| 12166 |
In either case, the member *typedef-name* `type` shall denote the same
|
| 12167 |
type, if any, as `C`. Otherwise, there shall be no member `type`.
|
| 12168 |
- If `sizeof...(T)` is greater than two, let `T1`, `T2`, and `R`,
|
| 12169 |
respectively, denote the first, second, and (pack of) remaining types
|
|
|
|
| 12187 |
types `T1` and `T2` is explicitly convertible. Moreover,
|
| 12188 |
`common_type_t<T1, T2>` shall denote the same type, if any, as does
|
| 12189 |
`common_type_t<T2, T1>`. No diagnostic is required for a violation of
|
| 12190 |
this Note’s rules.
|
| 12191 |
|
| 12192 |
+
Note C: For the `common_reference` trait applied to a parameter pack `T`
|
| 12193 |
+
of types, the member `type` shall be either defined or not present as
|
| 12194 |
+
follows:
|
| 12195 |
+
|
| 12196 |
+
- If `sizeof...(T)` is zero, there shall be no member `type`.
|
| 12197 |
+
- Otherwise, if `sizeof...(T)` is one, let `T0` denote the sole type in
|
| 12198 |
+
the pack `T`. The member typedef `type` shall denote the same type as
|
| 12199 |
+
`T0`.
|
| 12200 |
+
- Otherwise, if `sizeof...(T)` is two, let `T1` and `T2` denote the two
|
| 12201 |
+
types in the pack `T`. Then
|
| 12202 |
+
- If `T1` and `T2` are reference types and `COMMON-REF(T1, T2)` is
|
| 12203 |
+
well-formed, then the member typedef `type` denotes that type.
|
| 12204 |
+
- Otherwise, if
|
| 12205 |
+
`basic_common_reference<remove_cvref_t<T1>, remove_cvref_t<T2>,
|
| 12206 |
+
{}XREF({}T1), XREF(T2)>::type` is well-formed, then the member
|
| 12207 |
+
typedef `type` denotes that type.
|
| 12208 |
+
- Otherwise, if `COND-RES(T1, T2)` is well-formed, then the member
|
| 12209 |
+
typedef `type` denotes that type.
|
| 12210 |
+
- Otherwise, if `common_type_t<T1, T2>` is well-formed, then the
|
| 12211 |
+
member typedef `type` denotes that type.
|
| 12212 |
+
- Otherwise, there shall be no member `type`.
|
| 12213 |
+
- Otherwise, if `sizeof...(T)` is greater than two, let `T1`, `T2`, and
|
| 12214 |
+
`Rest`, respectively, denote the first, second, and (pack of)
|
| 12215 |
+
remaining types comprising `T`. Let `C` be the type
|
| 12216 |
+
`common_reference_t<T1, T2>`. Then:
|
| 12217 |
+
- If there is such a type `C`, the member typedef `type` shall denote
|
| 12218 |
+
the same type, if any, as `common_reference_t<C, Rest...>`.
|
| 12219 |
+
- Otherwise, there shall be no member `type`.
|
| 12220 |
+
|
| 12221 |
+
Note D: Notwithstanding the provisions of [[meta.type.synop]], and
|
| 12222 |
+
pursuant to [[namespace.std]], a program may partially specialize
|
| 12223 |
+
`basic_common_reference<T, U, TQual, UQual>` for types `T` and `U` such
|
| 12224 |
+
that `is_same_v<T, decay_t<T>{>}` and `is_same_v<U, decay_t<U>{>}` are
|
| 12225 |
+
each `true`.
|
| 12226 |
+
|
| 12227 |
+
[*Note 5*: Such specializations can be used to influence the result of
|
| 12228 |
+
`common_reference`, and are needed when only explicit conversions are
|
| 12229 |
+
desired between the template arguments. — *end note*]
|
| 12230 |
+
|
| 12231 |
+
Such a specialization need not have a member named `type`, but if it
|
| 12232 |
+
does, that member shall be a *typedef-name* for an accessible and
|
| 12233 |
+
unambiguous type `C` to which each of the types `TQual<T>` and
|
| 12234 |
+
`UQual<U>` is convertible. Moreover,
|
| 12235 |
+
`basic_common_reference<T, U, TQual, UQual>::type` shall denote the same
|
| 12236 |
+
type, if any, as does
|
| 12237 |
+
`basic_common_reference<U, T, UQual, TQual>::type`. No diagnostic is
|
| 12238 |
+
required for a violation of these rules.
|
| 12239 |
+
|
| 12240 |
+
[*Example 2*:
|
| 12241 |
|
| 12242 |
Given these definitions:
|
| 12243 |
|
| 12244 |
``` cpp
|
| 12245 |
using PF1 = bool (&)();
|
|
|
|
| 12279 |
```
|
| 12280 |
|
| 12281 |
The class template `conjunction` forms the logical conjunction of its
|
| 12282 |
template type arguments.
|
| 12283 |
|
| 12284 |
+
For a specialization `conjunction<``B₁``, `…`, ``B_N``>`, if there is a
|
| 12285 |
+
template type argument `Bᵢ` for which `bool(``Bᵢ``::value)` is `false`,
|
| 12286 |
+
then instantiating `conjunction<``B₁``, `…`, ``B_N``>::value` does not
|
| 12287 |
+
require the instantiation of `Bⱼ``::value` for j > i.
|
| 12288 |
|
| 12289 |
[*Note 1*: This is analogous to the short-circuiting behavior of the
|
| 12290 |
built-in operator `&&`. — *end note*]
|
| 12291 |
|
| 12292 |
+
Every template type argument for which `Bᵢ``::value` is instantiated
|
| 12293 |
+
shall be usable as a base class and shall have a member `value` which is
|
| 12294 |
convertible to `bool`, is not hidden, and is unambiguously available in
|
| 12295 |
the type.
|
| 12296 |
|
| 12297 |
+
The specialization `conjunction<``B₁``, `…`, ``B_N``>` has a public and
|
| 12298 |
unambiguous base that is either
|
| 12299 |
|
| 12300 |
+
- the first type `Bᵢ` in the list `true_type, ``B₁``, `…`, ``B_N` for
|
| 12301 |
+
which `bool(``Bᵢ``::value)` is `false`, or
|
| 12302 |
+
- if there is no such `Bᵢ`, the last type in the list.
|
| 12303 |
|
| 12304 |
[*Note 2*: This means a specialization of `conjunction` does not
|
| 12305 |
necessarily inherit from either `true_type` or
|
| 12306 |
`false_type`. — *end note*]
|
| 12307 |
|
|
|
|
| 12314 |
```
|
| 12315 |
|
| 12316 |
The class template `disjunction` forms the logical disjunction of its
|
| 12317 |
template type arguments.
|
| 12318 |
|
| 12319 |
+
For a specialization `disjunction<``B₁``, `…`, ``B_N``>`, if there is a
|
| 12320 |
+
template type argument `Bᵢ` for which `bool(``Bᵢ``::value)` is `true`,
|
| 12321 |
+
then instantiating `disjunction<``B₁``, `…`, ``B_N``>::value` does not
|
| 12322 |
+
require the instantiation of `Bⱼ``::value` for j > i.
|
| 12323 |
|
| 12324 |
[*Note 3*: This is analogous to the short-circuiting behavior of the
|
| 12325 |
built-in operator `||`. — *end note*]
|
| 12326 |
|
| 12327 |
+
Every template type argument for which `Bᵢ``::value` is instantiated
|
| 12328 |
+
shall be usable as a base class and shall have a member `value` which is
|
| 12329 |
convertible to `bool`, is not hidden, and is unambiguously available in
|
| 12330 |
the type.
|
| 12331 |
|
| 12332 |
+
The specialization `disjunction<``B₁``, `…`, ``B_N``>` has a public and
|
| 12333 |
unambiguous base that is either
|
| 12334 |
|
| 12335 |
+
- the first type `Bᵢ` in the list `false_type, ``B₁``, `…`, ``B_N` for
|
| 12336 |
+
which `bool(``Bᵢ``::value)` is `true`, or
|
| 12337 |
+
- if there is no such `Bᵢ`, the last type in the list.
|
| 12338 |
|
| 12339 |
[*Note 4*: This means a specialization of `disjunction` does not
|
| 12340 |
necessarily inherit from either `true_type` or
|
| 12341 |
`false_type`. — *end note*]
|
| 12342 |
|
|
|
|
| 12347 |
``` cpp
|
| 12348 |
template<class B> struct negation : see below { };
|
| 12349 |
```
|
| 12350 |
|
| 12351 |
The class template `negation` forms the logical negation of its template
|
| 12352 |
+
type argument. The type `negation<B>` is a *Cpp17UnaryTypeTrait* with a
|
| 12353 |
+
base characteristic of `bool_constant<!bool(B::value)>`.
|
| 12354 |
+
|
| 12355 |
+
### Member relationships <a id="meta.member">[[meta.member]]</a>
|
| 12356 |
+
|
| 12357 |
+
``` cpp
|
| 12358 |
+
template<class S, class M>
|
| 12359 |
+
constexpr bool is_pointer_interconvertible_with_class(M S::*m) noexcept;
|
| 12360 |
+
```
|
| 12361 |
+
|
| 12362 |
+
*Mandates:* `S` is a complete type.
|
| 12363 |
+
|
| 12364 |
+
*Returns:* `true` if and only if `S` is a standard-layout type, `M` is
|
| 12365 |
+
an object type, `m` is not null, and each object `s` of type `S` is
|
| 12366 |
+
pointer-interconvertible [[basic.compound]] with its subobject `s.*m`.
|
| 12367 |
+
|
| 12368 |
+
``` cpp
|
| 12369 |
+
template<class S1, class S2, class M1, class M2>
|
| 12370 |
+
constexpr bool is_corresponding_member(M1 S1::*m1, M2 S2::*m2) noexcept;
|
| 12371 |
+
```
|
| 12372 |
+
|
| 12373 |
+
*Mandates:* `S1` and `S2` are complete types.
|
| 12374 |
+
|
| 12375 |
+
*Returns:* `true` if and only if `S1` and `S2` are standard-layout
|
| 12376 |
+
types, `M1` and `M2` are object types, `m1` and `m2` are not null, and
|
| 12377 |
+
`m1` and `m2` point to corresponding members of the common initial
|
| 12378 |
+
sequence [[class.mem]] of `S1` and `S2`.
|
| 12379 |
+
|
| 12380 |
+
[*Note 1*:
|
| 12381 |
+
|
| 12382 |
+
The type of a pointer-to-member expression `&C::b` is not always a
|
| 12383 |
+
pointer to member of `C`, leading to potentially surprising results when
|
| 12384 |
+
using these functions in conjunction with inheritance.
|
| 12385 |
+
|
| 12386 |
+
[*Example 1*:
|
| 12387 |
+
|
| 12388 |
+
``` cpp
|
| 12389 |
+
struct A { int a; }; // a standard-layout class
|
| 12390 |
+
struct B { int b; }; // a standard-layout class
|
| 12391 |
+
struct C: public A, public B { }; // not a standard-layout class
|
| 12392 |
+
|
| 12393 |
+
static_assert( is_pointer_interconvertible_with_class( &C::b ) );
|
| 12394 |
+
// Succeeds because, despite its appearance, &C::b has type
|
| 12395 |
+
// ``pointer to member of B of type int''.
|
| 12396 |
+
static_assert( is_pointer_interconvertible_with_class<C>( &C::b ) );
|
| 12397 |
+
// Forces the use of class C, and fails.
|
| 12398 |
+
|
| 12399 |
+
static_assert( is_corresponding_member( &C::a, &C::b ) );
|
| 12400 |
+
// Succeeds because, despite its appearance, &C::a and &C::b have types
|
| 12401 |
+
// ``pointer to member of A of type int'' and
|
| 12402 |
+
// ``pointer to member of B of type int'', respectively.
|
| 12403 |
+
static_assert( is_corresponding_member<C, C>( &C::a, &C::b ) );
|
| 12404 |
+
// Forces the use of class C, and fails.
|
| 12405 |
+
```
|
| 12406 |
+
|
| 12407 |
+
— *end example*]
|
| 12408 |
+
|
| 12409 |
+
— *end note*]
|
| 12410 |
+
|
| 12411 |
+
### Constant evaluation context <a id="meta.const.eval">[[meta.const.eval]]</a>
|
| 12412 |
+
|
| 12413 |
+
``` cpp
|
| 12414 |
+
constexpr bool is_constant_evaluated() noexcept;
|
| 12415 |
+
```
|
| 12416 |
+
|
| 12417 |
+
*Returns:* `true` if and only if evaluation of the call occurs within
|
| 12418 |
+
the evaluation of an expression or conversion that is manifestly
|
| 12419 |
+
constant-evaluated [[expr.const]].
|
| 12420 |
+
|
| 12421 |
+
[*Example 1*:
|
| 12422 |
+
|
| 12423 |
+
``` cpp
|
| 12424 |
+
constexpr void f(unsigned char *p, int n) {
|
| 12425 |
+
if (std::is_constant_evaluated()) { // should not be a constexpr if statement
|
| 12426 |
+
for (int k = 0; k<n; ++k) p[k] = 0;
|
| 12427 |
+
} else {
|
| 12428 |
+
memset(p, 0, n); // not a core constant expression
|
| 12429 |
+
}
|
| 12430 |
+
}
|
| 12431 |
+
```
|
| 12432 |
+
|
| 12433 |
+
— *end example*]
|
| 12434 |
|
| 12435 |
## Compile-time rational arithmetic <a id="ratio">[[ratio]]</a>
|
| 12436 |
|
| 12437 |
### In general <a id="ratio.general">[[ratio.general]]</a>
|
| 12438 |
|
| 12439 |
+
Subclause [[ratio]] describes the ratio library. It provides a class
|
| 12440 |
+
template `ratio` which exactly represents any finite rational number
|
| 12441 |
+
with a numerator and denominator representable by compile-time constants
|
| 12442 |
+
of type `intmax_t`.
|
| 12443 |
|
| 12444 |
+
Throughout subclause [[ratio]], the names of template parameters are
|
| 12445 |
+
used to express type requirements. If a template parameter is named `R1`
|
| 12446 |
+
or `R2`, and the template argument is not a specialization of the
|
| 12447 |
+
`ratio` template, the program is ill-formed.
|
| 12448 |
|
| 12449 |
### Header `<ratio>` synopsis <a id="ratio.syn">[[ratio.syn]]</a>
|
| 12450 |
|
| 12451 |
``` cpp
|
| 12452 |
namespace std {
|
|
|
|
| 12506 |
|
| 12507 |
### Class template `ratio` <a id="ratio.ratio">[[ratio.ratio]]</a>
|
| 12508 |
|
| 12509 |
``` cpp
|
| 12510 |
namespace std {
|
| 12511 |
+
template<intmax_t N, intmax_t D = 1> class ratio {
|
|
|
|
| 12512 |
public:
|
| 12513 |
static constexpr intmax_t num;
|
| 12514 |
static constexpr intmax_t den;
|
| 12515 |
using type = ratio<num, den>;
|
| 12516 |
};
|
|
|
|
| 12521 |
the template arguments `N` and `D` is not representable by type
|
| 12522 |
`intmax_t`, the program is ill-formed.
|
| 12523 |
|
| 12524 |
[*Note 1*: These rules ensure that infinite ratios are avoided and that
|
| 12525 |
for any negative input, there exists a representable value of its
|
| 12526 |
+
absolute value which is positive. This excludes the most negative
|
| 12527 |
+
value. — *end note*]
|
| 12528 |
|
| 12529 |
The static data members `num` and `den` shall have the following values,
|
| 12530 |
where `gcd` represents the greatest common divisor of the absolute
|
| 12531 |
values of `N` and `D`:
|
| 12532 |
|
|
|
|
| 12536 |
### Arithmetic on `ratio`s <a id="ratio.arithmetic">[[ratio.arithmetic]]</a>
|
| 12537 |
|
| 12538 |
Each of the alias templates `ratio_add`, `ratio_subtract`,
|
| 12539 |
`ratio_multiply`, and `ratio_divide` denotes the result of an arithmetic
|
| 12540 |
computation on two `ratio`s `R1` and `R2`. With `X` and `Y` computed (in
|
| 12541 |
+
the absence of arithmetic overflow) as specified by
|
| 12542 |
+
[[ratio.arithmetic]], each alias denotes a `ratio<U, V>` such that `U`
|
| 12543 |
+
is the same as `ratio<X, Y>::num` and `V` is the same as
|
| 12544 |
`ratio<X, Y>::den`.
|
| 12545 |
|
| 12546 |
If it is not possible to represent `U` or `V` with `intmax_t`, the
|
| 12547 |
program is ill-formed. Otherwise, an implementation should yield correct
|
| 12548 |
values of `U` and `V`. If it is not possible to represent `X` or `Y`
|
| 12549 |
with `intmax_t`, the program is ill-formed unless the implementation
|
| 12550 |
yields correct values of `U` and `V`.
|
| 12551 |
|
| 12552 |
+
**Table: Expressions used to perform ratio arithmetic** <a id="ratio.arithmetic">[ratio.arithmetic]</a>
|
| 12553 |
|
| 12554 |
| Type | Value of `X` | Value of `Y` |
|
| 12555 |
| ------------------------ | --------------------- | ------------------- |
|
| 12556 |
| `ratio_add<R1, R2>` | `R1::num * R2::den +` | `R1::den * R2::den` |
|
| 12557 |
| | `R2::num * R1::den` | |
|
|
|
|
| 12622 |
|
| 12623 |
### SI types for `ratio` <a id="ratio.si">[[ratio.si]]</a>
|
| 12624 |
|
| 12625 |
For each of the *typedef-name*s `yocto`, `zepto`, `zetta`, and `yotta`,
|
| 12626 |
if both of the constants used in its specification are representable by
|
| 12627 |
+
`intmax_t`, the typedef is defined; if either of the constants is not
|
| 12628 |
+
representable by `intmax_t`, the typedef is not defined.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12629 |
|
| 12630 |
## Class `type_index` <a id="type.index">[[type.index]]</a>
|
| 12631 |
|
| 12632 |
### Header `<typeindex>` synopsis <a id="type.index.synopsis">[[type.index.synopsis]]</a>
|
| 12633 |
|
| 12634 |
``` cpp
|
| 12635 |
+
#include <compare> // see [compare.syn]
|
| 12636 |
+
|
| 12637 |
namespace std {
|
| 12638 |
class type_index;
|
| 12639 |
template<class T> struct hash;
|
| 12640 |
template<> struct hash<type_index>;
|
| 12641 |
}
|
|
|
|
| 12647 |
namespace std {
|
| 12648 |
class type_index {
|
| 12649 |
public:
|
| 12650 |
type_index(const type_info& rhs) noexcept;
|
| 12651 |
bool operator==(const type_index& rhs) const noexcept;
|
|
|
|
| 12652 |
bool operator< (const type_index& rhs) const noexcept;
|
|
|
|
| 12653 |
bool operator> (const type_index& rhs) const noexcept;
|
| 12654 |
+
bool operator<=(const type_index& rhs) const noexcept;
|
| 12655 |
bool operator>=(const type_index& rhs) const noexcept;
|
| 12656 |
+
strong_ordering operator<=>(const type_index& rhs) const noexcept;
|
| 12657 |
size_t hash_code() const noexcept;
|
| 12658 |
const char* name() const noexcept;
|
| 12659 |
+
|
| 12660 |
private:
|
| 12661 |
const type_info* target; // exposition only
|
| 12662 |
// Note that the use of a pointer here, rather than a reference,
|
| 12663 |
// means that the default copy/move constructor and assignment
|
| 12664 |
// operators will be provided and work as expected.
|
| 12665 |
};
|
| 12666 |
}
|
| 12667 |
```
|
| 12668 |
|
| 12669 |
The class `type_index` provides a simple wrapper for `type_info` which
|
| 12670 |
+
can be used as an index type in associative containers [[associative]]
|
| 12671 |
+
and in unordered associative containers [[unord]].
|
| 12672 |
|
| 12673 |
### `type_index` members <a id="type.index.members">[[type.index.members]]</a>
|
| 12674 |
|
| 12675 |
``` cpp
|
| 12676 |
type_index(const type_info& rhs) noexcept;
|
|
|
|
| 12683 |
bool operator==(const type_index& rhs) const noexcept;
|
| 12684 |
```
|
| 12685 |
|
| 12686 |
*Returns:* `*target == *rhs.target`.
|
| 12687 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12688 |
``` cpp
|
| 12689 |
bool operator<(const type_index& rhs) const noexcept;
|
| 12690 |
```
|
| 12691 |
|
| 12692 |
*Returns:* `target->before(*rhs.target)`.
|
| 12693 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12694 |
``` cpp
|
| 12695 |
bool operator>(const type_index& rhs) const noexcept;
|
| 12696 |
```
|
| 12697 |
|
| 12698 |
*Returns:* `rhs.target->before(*target)`.
|
| 12699 |
|
| 12700 |
+
``` cpp
|
| 12701 |
+
bool operator<=(const type_index& rhs) const noexcept;
|
| 12702 |
+
```
|
| 12703 |
+
|
| 12704 |
+
*Returns:* `!rhs.target->before(*target)`.
|
| 12705 |
+
|
| 12706 |
``` cpp
|
| 12707 |
bool operator>=(const type_index& rhs) const noexcept;
|
| 12708 |
```
|
| 12709 |
|
| 12710 |
*Returns:* `!target->before(*rhs.target)`.
|
| 12711 |
|
| 12712 |
+
``` cpp
|
| 12713 |
+
strong_ordering operator<=>(const type_index& rhs) const noexcept;
|
| 12714 |
+
```
|
| 12715 |
+
|
| 12716 |
+
*Effects:* Equivalent to:
|
| 12717 |
+
|
| 12718 |
+
``` cpp
|
| 12719 |
+
if (*target == *rhs.target) return strong_ordering::equal;
|
| 12720 |
+
if (target->before(*rhs.target)) return strong_ordering::less;
|
| 12721 |
+
return strong_ordering::greater;
|
| 12722 |
+
```
|
| 12723 |
+
|
| 12724 |
``` cpp
|
| 12725 |
size_t hash_code() const noexcept;
|
| 12726 |
```
|
| 12727 |
|
| 12728 |
*Returns:* `target->hash_code()`.
|
|
|
|
| 12744 |
|
| 12745 |
## Execution policies <a id="execpol">[[execpol]]</a>
|
| 12746 |
|
| 12747 |
### In general <a id="execpol.general">[[execpol.general]]</a>
|
| 12748 |
|
| 12749 |
+
Subclause [[execpol]] describes classes that are *execution policy*
|
| 12750 |
+
types. An object of an execution policy type indicates the kinds of
|
| 12751 |
+
parallelism allowed in the execution of an algorithm and expresses the
|
| 12752 |
+
consequent requirements on the element access functions.
|
| 12753 |
|
| 12754 |
[*Example 1*:
|
| 12755 |
|
| 12756 |
``` cpp
|
| 12757 |
using namespace std;
|
|
|
|
| 12794 |
class parallel_policy;
|
| 12795 |
|
| 12796 |
// [execpol.parunseq], parallel and unsequenced execution policy
|
| 12797 |
class parallel_unsequenced_policy;
|
| 12798 |
|
| 12799 |
+
// [execpol.unseq], unsequenced execution policy
|
| 12800 |
+
class unsequenced_policy;
|
| 12801 |
+
|
| 12802 |
// [execpol.objects], execution policy objects
|
| 12803 |
inline constexpr sequenced_policy seq{ unspecified };
|
| 12804 |
inline constexpr parallel_policy par{ unspecified };
|
| 12805 |
inline constexpr parallel_unsequenced_policy par_unseq{ unspecified };
|
| 12806 |
+
inline constexpr unsequenced_policy unseq{ unspecified };
|
| 12807 |
}
|
| 12808 |
```
|
| 12809 |
|
| 12810 |
### Execution policy type trait <a id="execpol.type">[[execpol.type]]</a>
|
| 12811 |
|
|
|
|
| 12815 |
|
| 12816 |
`is_execution_policy` can be used to detect execution policies for the
|
| 12817 |
purpose of excluding function signatures from otherwise ambiguous
|
| 12818 |
overload resolution participation.
|
| 12819 |
|
| 12820 |
+
`is_execution_policy<T>` is a *Cpp17UnaryTypeTrait* with a base
|
| 12821 |
characteristic of `true_type` if `T` is the type of a standard or
|
| 12822 |
*implementation-defined* execution policy, otherwise `false_type`.
|
| 12823 |
|
| 12824 |
[*Note 1*: This provision reserves the privilege of creating
|
| 12825 |
non-standard execution policies to the library
|
|
|
|
| 12838 |
as a unique type to disambiguate parallel algorithm overloading and
|
| 12839 |
require that a parallel algorithm’s execution may not be parallelized.
|
| 12840 |
|
| 12841 |
During the execution of a parallel algorithm with the
|
| 12842 |
`execution::sequenced_policy` policy, if the invocation of an element
|
| 12843 |
+
access function exits via an uncaught exception, `terminate()` is
|
| 12844 |
called.
|
| 12845 |
|
| 12846 |
### Parallel execution policy <a id="execpol.par">[[execpol.par]]</a>
|
| 12847 |
|
| 12848 |
``` cpp
|
|
|
|
| 12853 |
as a unique type to disambiguate parallel algorithm overloading and
|
| 12854 |
indicate that a parallel algorithm’s execution may be parallelized.
|
| 12855 |
|
| 12856 |
During the execution of a parallel algorithm with the
|
| 12857 |
`execution::parallel_policy` policy, if the invocation of an element
|
| 12858 |
+
access function exits via an uncaught exception, `terminate()` is
|
| 12859 |
called.
|
| 12860 |
|
| 12861 |
### Parallel and unsequenced execution policy <a id="execpol.parunseq">[[execpol.parunseq]]</a>
|
| 12862 |
|
| 12863 |
``` cpp
|
|
|
|
| 12870 |
parallelized and vectorized.
|
| 12871 |
|
| 12872 |
During the execution of a parallel algorithm with the
|
| 12873 |
`execution::parallel_unsequenced_policy` policy, if the invocation of an
|
| 12874 |
element access function exits via an uncaught exception, `terminate()`
|
| 12875 |
+
is called.
|
| 12876 |
+
|
| 12877 |
+
### Unsequenced execution policy <a id="execpol.unseq">[[execpol.unseq]]</a>
|
| 12878 |
+
|
| 12879 |
+
``` cpp
|
| 12880 |
+
class execution::unsequenced_policy { unspecified };
|
| 12881 |
+
```
|
| 12882 |
+
|
| 12883 |
+
The class `unsequenced_policy` is an execution policy type used as a
|
| 12884 |
+
unique type to disambiguate parallel algorithm overloading and indicate
|
| 12885 |
+
that a parallel algorithm’s execution may be vectorized, e.g., executed
|
| 12886 |
+
on a single thread using instructions that operate on multiple data
|
| 12887 |
+
items.
|
| 12888 |
+
|
| 12889 |
+
During the execution of a parallel algorithm with the
|
| 12890 |
+
`execution::unsequenced_policy` policy, if the invocation of an element
|
| 12891 |
+
access function exits via an uncaught exception, `terminate()` is
|
| 12892 |
+
called.
|
| 12893 |
|
| 12894 |
### Execution policy objects <a id="execpol.objects">[[execpol.objects]]</a>
|
| 12895 |
|
| 12896 |
``` cpp
|
| 12897 |
inline constexpr execution::sequenced_policy execution::seq{ unspecified };
|
| 12898 |
inline constexpr execution::parallel_policy execution::par{ unspecified };
|
| 12899 |
inline constexpr execution::parallel_unsequenced_policy execution::par_unseq{ unspecified };
|
| 12900 |
+
inline constexpr execution::unsequenced_policy execution::unseq{ unspecified };
|
| 12901 |
```
|
| 12902 |
|
| 12903 |
The header `<execution>` declares global objects associated with each
|
| 12904 |
type of execution policy.
|
| 12905 |
|
| 12906 |
+
## Primitive numeric conversions <a id="charconv">[[charconv]]</a>
|
| 12907 |
+
|
| 12908 |
+
### Header `<charconv>` synopsis <a id="charconv.syn">[[charconv.syn]]</a>
|
| 12909 |
+
|
| 12910 |
+
``` cpp
|
| 12911 |
+
%
|
| 12912 |
+
%
|
| 12913 |
+
{chars_format{chars_format{chars_format{chars_formatnamespace std {
|
| 12914 |
+
// floating-point format for primitive numerical conversion
|
| 12915 |
+
enum class chars_format {
|
| 12916 |
+
scientific = unspecified,
|
| 12917 |
+
fixed = unspecified,
|
| 12918 |
+
hex = unspecified,
|
| 12919 |
+
general = fixed | scientific
|
| 12920 |
+
};
|
| 12921 |
+
%
|
| 12922 |
+
%
|
| 12923 |
+
{to_chars_result{to_chars_result}
|
| 12924 |
+
|
| 12925 |
+
// [charconv.to.chars], primitive numerical output conversion
|
| 12926 |
+
struct to_chars_result {
|
| 12927 |
+
char* ptr;
|
| 12928 |
+
errc ec;
|
| 12929 |
+
friend bool operator==(const to_chars_result&, const to_chars_result&) = default;
|
| 12930 |
+
};
|
| 12931 |
+
|
| 12932 |
+
to_chars_result to_chars(char* first, char* last, see below value, int base = 10);
|
| 12933 |
+
to_chars_result to_chars(char* first, char* last, bool value, int base = 10) = delete;
|
| 12934 |
+
|
| 12935 |
+
to_chars_result to_chars(char* first, char* last, float value);
|
| 12936 |
+
to_chars_result to_chars(char* first, char* last, double value);
|
| 12937 |
+
to_chars_result to_chars(char* first, char* last, long double value);
|
| 12938 |
+
|
| 12939 |
+
to_chars_result to_chars(char* first, char* last, float value, chars_format fmt);
|
| 12940 |
+
to_chars_result to_chars(char* first, char* last, double value, chars_format fmt);
|
| 12941 |
+
to_chars_result to_chars(char* first, char* last, long double value, chars_format fmt);
|
| 12942 |
+
|
| 12943 |
+
to_chars_result to_chars(char* first, char* last, float value,
|
| 12944 |
+
chars_format fmt, int precision);
|
| 12945 |
+
to_chars_result to_chars(char* first, char* last, double value,
|
| 12946 |
+
chars_format fmt, int precision);
|
| 12947 |
+
to_chars_result to_chars(char* first, char* last, long double value,
|
| 12948 |
+
chars_format fmt, int precision);
|
| 12949 |
+
%
|
| 12950 |
+
%
|
| 12951 |
+
{from_chars_result{from_chars_result}
|
| 12952 |
+
|
| 12953 |
+
// [charconv.from.chars], primitive numerical input conversion
|
| 12954 |
+
struct from_chars_result {
|
| 12955 |
+
const char* ptr;
|
| 12956 |
+
errc ec;
|
| 12957 |
+
friend bool operator==(const from_chars_result&, const from_chars_result&) = default;
|
| 12958 |
+
};
|
| 12959 |
+
|
| 12960 |
+
from_chars_result from_chars(const char* first, const char* last,
|
| 12961 |
+
see below& value, int base = 10);
|
| 12962 |
+
|
| 12963 |
+
from_chars_result from_chars(const char* first, const char* last, float& value,
|
| 12964 |
+
chars_format fmt = chars_format::general);
|
| 12965 |
+
from_chars_result from_chars(const char* first, const char* last, double& value,
|
| 12966 |
+
chars_format fmt = chars_format::general);
|
| 12967 |
+
from_chars_result from_chars(const char* first, const char* last, long double& value,
|
| 12968 |
+
chars_format fmt = chars_format::general);
|
| 12969 |
+
}
|
| 12970 |
+
```
|
| 12971 |
+
|
| 12972 |
+
The type `chars_format` is a bitmask type [[bitmask.types]] with
|
| 12973 |
+
elements `scientific`, `fixed`, and `hex`.
|
| 12974 |
+
|
| 12975 |
+
The types `to_chars_result` and `from_chars_result` have the data
|
| 12976 |
+
members and special members specified above. They have no base classes
|
| 12977 |
+
or members other than those specified.
|
| 12978 |
+
|
| 12979 |
+
### Primitive numeric output conversion <a id="charconv.to.chars">[[charconv.to.chars]]</a>
|
| 12980 |
+
|
| 12981 |
+
All functions named `to_chars` convert `value` into a character string
|
| 12982 |
+
by successively filling the range \[`first`, `last`), where \[`first`,
|
| 12983 |
+
`last`) is required to be a valid range. If the member `ec` of the
|
| 12984 |
+
return value is such that the value is equal to the value of a
|
| 12985 |
+
value-initialized `errc`, the conversion was successful and the member
|
| 12986 |
+
`ptr` is the one-past-the-end pointer of the characters written.
|
| 12987 |
+
Otherwise, the member `ec` has the value `errc::value_too_large`, the
|
| 12988 |
+
member `ptr` has the value `last`, and the contents of the range
|
| 12989 |
+
\[`first`, `last`) are unspecified.
|
| 12990 |
+
|
| 12991 |
+
The functions that take a floating-point `value` but not a `precision`
|
| 12992 |
+
parameter ensure that the string representation consists of the smallest
|
| 12993 |
+
number of characters such that there is at least one digit before the
|
| 12994 |
+
radix point (if present) and parsing the representation using the
|
| 12995 |
+
corresponding `from_chars` function recovers `value` exactly.
|
| 12996 |
+
|
| 12997 |
+
[*Note 1*: This guarantee applies only if `to_chars` and `from_chars`
|
| 12998 |
+
are executed on the same implementation. — *end note*]
|
| 12999 |
+
|
| 13000 |
+
If there are several such representations, the representation with the
|
| 13001 |
+
smallest difference from the floating-point argument value is chosen,
|
| 13002 |
+
resolving any remaining ties using rounding according to
|
| 13003 |
+
`round_to_nearest` [[round.style]].
|
| 13004 |
+
|
| 13005 |
+
The functions taking a `chars_format` parameter determine the conversion
|
| 13006 |
+
specifier for `printf` as follows: The conversion specifier is `f` if
|
| 13007 |
+
`fmt` is `chars_format::fixed`, `e` if `fmt` is
|
| 13008 |
+
`chars_format::scientific`, `a` (without leading `"0x"` in the result)
|
| 13009 |
+
if `fmt` is `chars_format::hex`, and `g` if `fmt` is
|
| 13010 |
+
`chars_format::general`.
|
| 13011 |
+
|
| 13012 |
+
``` cpp
|
| 13013 |
+
to_chars_result to_chars(char* first, char* last, see below value, int base = 10);
|
| 13014 |
+
```
|
| 13015 |
+
|
| 13016 |
+
*Preconditions:* `base` has a value between 2 and 36 (inclusive).
|
| 13017 |
+
|
| 13018 |
+
*Effects:* The value of `value` is converted to a string of digits in
|
| 13019 |
+
the given base (with no redundant leading zeroes). Digits in the range
|
| 13020 |
+
10..35 (inclusive) are represented as lowercase characters `a`..`z`. If
|
| 13021 |
+
`value` is less than zero, the representation starts with `’-’`.
|
| 13022 |
+
|
| 13023 |
+
*Throws:* Nothing.
|
| 13024 |
+
|
| 13025 |
+
*Remarks:* The implementation shall provide overloads for all signed and
|
| 13026 |
+
unsigned integer types and `char` as the type of the parameter `value`.
|
| 13027 |
+
|
| 13028 |
+
``` cpp
|
| 13029 |
+
to_chars_result to_chars(char* first, char* last, float value);
|
| 13030 |
+
to_chars_result to_chars(char* first, char* last, double value);
|
| 13031 |
+
to_chars_result to_chars(char* first, char* last, long double value);
|
| 13032 |
+
```
|
| 13033 |
+
|
| 13034 |
+
*Effects:* `value` is converted to a string in the style of `printf` in
|
| 13035 |
+
the `"C"` locale. The conversion specifier is `f` or `e`, chosen
|
| 13036 |
+
according to the requirement for a shortest representation (see above);
|
| 13037 |
+
a tie is resolved in favor of `f`.
|
| 13038 |
+
|
| 13039 |
+
*Throws:* Nothing.
|
| 13040 |
+
|
| 13041 |
+
``` cpp
|
| 13042 |
+
to_chars_result to_chars(char* first, char* last, float value, chars_format fmt);
|
| 13043 |
+
to_chars_result to_chars(char* first, char* last, double value, chars_format fmt);
|
| 13044 |
+
to_chars_result to_chars(char* first, char* last, long double value, chars_format fmt);
|
| 13045 |
+
```
|
| 13046 |
+
|
| 13047 |
+
*Preconditions:* `fmt` has the value of one of the enumerators of
|
| 13048 |
+
`chars_format`.
|
| 13049 |
+
|
| 13050 |
+
*Effects:* `value` is converted to a string in the style of `printf` in
|
| 13051 |
+
the `"C"` locale.
|
| 13052 |
+
|
| 13053 |
+
*Throws:* Nothing.
|
| 13054 |
+
|
| 13055 |
+
``` cpp
|
| 13056 |
+
to_chars_result to_chars(char* first, char* last, float value,
|
| 13057 |
+
chars_format fmt, int precision);
|
| 13058 |
+
to_chars_result to_chars(char* first, char* last, double value,
|
| 13059 |
+
chars_format fmt, int precision);
|
| 13060 |
+
to_chars_result to_chars(char* first, char* last, long double value,
|
| 13061 |
+
chars_format fmt, int precision);
|
| 13062 |
+
```
|
| 13063 |
+
|
| 13064 |
+
*Preconditions:* `fmt` has the value of one of the enumerators of
|
| 13065 |
+
`chars_format`.
|
| 13066 |
+
|
| 13067 |
+
*Effects:* `value` is converted to a string in the style of `printf` in
|
| 13068 |
+
the `"C"` locale with the given precision.
|
| 13069 |
+
|
| 13070 |
+
*Throws:* Nothing.
|
| 13071 |
+
|
| 13072 |
+
See also: ISO C 7.21.6.1
|
| 13073 |
+
|
| 13074 |
+
### Primitive numeric input conversion <a id="charconv.from.chars">[[charconv.from.chars]]</a>
|
| 13075 |
+
|
| 13076 |
+
All functions named `from_chars` analyze the string \[`first`, `last`)
|
| 13077 |
+
for a pattern, where \[`first`, `last`) is required to be a valid range.
|
| 13078 |
+
If no characters match the pattern, `value` is unmodified, the member
|
| 13079 |
+
`ptr` of the return value is `first` and the member `ec` is equal to
|
| 13080 |
+
`errc::invalid_argument`.
|
| 13081 |
+
|
| 13082 |
+
[*Note 1*: If the pattern allows for an optional sign, but the string
|
| 13083 |
+
has no digit characters following the sign, no characters match the
|
| 13084 |
+
pattern. — *end note*]
|
| 13085 |
+
|
| 13086 |
+
Otherwise, the characters matching the pattern are interpreted as a
|
| 13087 |
+
representation of a value of the type of `value`. The member `ptr` of
|
| 13088 |
+
the return value points to the first character not matching the pattern,
|
| 13089 |
+
or has the value `last` if all characters match. If the parsed value is
|
| 13090 |
+
not in the range representable by the type of `value`, `value` is
|
| 13091 |
+
unmodified and the member `ec` of the return value is equal to
|
| 13092 |
+
`errc::result_out_of_range`. Otherwise, `value` is set to the parsed
|
| 13093 |
+
value, after rounding according to `round_to_nearest` [[round.style]],
|
| 13094 |
+
and the member `ec` is value-initialized.
|
| 13095 |
+
|
| 13096 |
+
``` cpp
|
| 13097 |
+
from_chars_result from_chars(const char* first, const char* last,
|
| 13098 |
+
see below& value, int base = 10);
|
| 13099 |
+
```
|
| 13100 |
+
|
| 13101 |
+
*Preconditions:* `base` has a value between 2 and 36 (inclusive).
|
| 13102 |
+
|
| 13103 |
+
*Effects:* The pattern is the expected form of the subject sequence in
|
| 13104 |
+
the `"C"` locale for the given nonzero base, as described for `strtol`,
|
| 13105 |
+
except that no `"0x"` or `"0X"` prefix shall appear if the value of
|
| 13106 |
+
`base` is 16, and except that `’-’` is the only sign that may appear,
|
| 13107 |
+
and only if `value` has a signed type.
|
| 13108 |
+
|
| 13109 |
+
*Throws:* Nothing.
|
| 13110 |
+
|
| 13111 |
+
*Remarks:* The implementation shall provide overloads for all signed and
|
| 13112 |
+
unsigned integer types and `char` as the referenced type of the
|
| 13113 |
+
parameter `value`.
|
| 13114 |
+
|
| 13115 |
+
``` cpp
|
| 13116 |
+
from_chars_result from_chars(const char* first, const char* last, float& value,
|
| 13117 |
+
chars_format fmt = chars_format::general);
|
| 13118 |
+
from_chars_result from_chars(const char* first, const char* last, double& value,
|
| 13119 |
+
chars_format fmt = chars_format::general);
|
| 13120 |
+
from_chars_result from_chars(const char* first, const char* last, long double& value,
|
| 13121 |
+
chars_format fmt = chars_format::general);
|
| 13122 |
+
```
|
| 13123 |
+
|
| 13124 |
+
*Preconditions:* `fmt` has the value of one of the enumerators of
|
| 13125 |
+
`chars_format`.
|
| 13126 |
+
|
| 13127 |
+
*Effects:* The pattern is the expected form of the subject sequence in
|
| 13128 |
+
the `"C"` locale, as described for `strtod`, except that
|
| 13129 |
+
|
| 13130 |
+
- the sign `’+’` may only appear in the exponent part;
|
| 13131 |
+
- if `fmt` has `chars_format::scientific` set but not
|
| 13132 |
+
`chars_format::fixed`, the otherwise optional exponent part shall
|
| 13133 |
+
appear;
|
| 13134 |
+
- if `fmt` has `chars_format::fixed` set but not
|
| 13135 |
+
`chars_format::scientific`, the optional exponent part shall not
|
| 13136 |
+
appear; and
|
| 13137 |
+
- if `fmt` is `chars_format::hex`, the prefix `"0x"` or `"0X"` is
|
| 13138 |
+
assumed. \[*Example 1*: The string `0x123` is parsed to have the value
|
| 13139 |
+
`0` with remaining characters `x123`. — *end example*]
|
| 13140 |
+
|
| 13141 |
+
In any case, the resulting `value` is one of at most two floating-point
|
| 13142 |
+
values closest to the value of the string matching the pattern.
|
| 13143 |
+
|
| 13144 |
+
*Throws:* Nothing.
|
| 13145 |
+
|
| 13146 |
+
See also: ISO C 7.22.1.3, 7.22.1.4
|
| 13147 |
+
|
| 13148 |
+
## Formatting <a id="format">[[format]]</a>
|
| 13149 |
+
|
| 13150 |
+
### Header `<format>` synopsis <a id="format.syn">[[format.syn]]</a>
|
| 13151 |
+
|
| 13152 |
+
``` cpp
|
| 13153 |
+
namespace std {
|
| 13154 |
+
// [format.functions], formatting functions
|
| 13155 |
+
template<class... Args>
|
| 13156 |
+
string format(string_view fmt, const Args&... args);
|
| 13157 |
+
template<class... Args>
|
| 13158 |
+
wstring format(wstring_view fmt, const Args&... args);
|
| 13159 |
+
template<class... Args>
|
| 13160 |
+
string format(const locale& loc, string_view fmt, const Args&... args);
|
| 13161 |
+
template<class... Args>
|
| 13162 |
+
wstring format(const locale& loc, wstring_view fmt, const Args&... args);
|
| 13163 |
+
|
| 13164 |
+
string vformat(string_view fmt, format_args args);
|
| 13165 |
+
wstring vformat(wstring_view fmt, wformat_args args);
|
| 13166 |
+
string vformat(const locale& loc, string_view fmt, format_args args);
|
| 13167 |
+
wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
|
| 13168 |
+
|
| 13169 |
+
template<class Out, class... Args>
|
| 13170 |
+
Out format_to(Out out, string_view fmt, const Args&... args);
|
| 13171 |
+
template<class Out, class... Args>
|
| 13172 |
+
Out format_to(Out out, wstring_view fmt, const Args&... args);
|
| 13173 |
+
template<class Out, class... Args>
|
| 13174 |
+
Out format_to(Out out, const locale& loc, string_view fmt, const Args&... args);
|
| 13175 |
+
template<class Out, class... Args>
|
| 13176 |
+
Out format_to(Out out, const locale& loc, wstring_view fmt, const Args&... args);
|
| 13177 |
+
|
| 13178 |
+
template<class Out>
|
| 13179 |
+
Out vformat_to(Out out, string_view fmt,
|
| 13180 |
+
format_args_t<type_identity_t<Out>, char> args);
|
| 13181 |
+
template<class Out>
|
| 13182 |
+
Out vformat_to(Out out, wstring_view fmt,
|
| 13183 |
+
format_args_t<type_identity_t<Out>, wchar_t> args);
|
| 13184 |
+
template<class Out>
|
| 13185 |
+
Out vformat_to(Out out, const locale& loc, string_view fmt,
|
| 13186 |
+
format_args_t<type_identity_t<Out>, char> args);
|
| 13187 |
+
template<class Out>
|
| 13188 |
+
Out vformat_to(Out out, const locale& loc, wstring_view fmt,
|
| 13189 |
+
format_args_t<type_identity_t<Out>, wchar_t> args);
|
| 13190 |
+
|
| 13191 |
+
template<class Out> struct format_to_n_result {
|
| 13192 |
+
Out out;
|
| 13193 |
+
iter_difference_t<Out> size;
|
| 13194 |
+
};
|
| 13195 |
+
template<class Out, class... Args>
|
| 13196 |
+
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
| 13197 |
+
string_view fmt, const Args&... args);
|
| 13198 |
+
template<class Out, class... Args>
|
| 13199 |
+
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
| 13200 |
+
wstring_view fmt, const Args&... args);
|
| 13201 |
+
template<class Out, class... Args>
|
| 13202 |
+
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
| 13203 |
+
const locale& loc, string_view fmt,
|
| 13204 |
+
const Args&... args);
|
| 13205 |
+
template<class Out, class... Args>
|
| 13206 |
+
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
| 13207 |
+
const locale& loc, wstring_view fmt,
|
| 13208 |
+
const Args&... args);
|
| 13209 |
+
|
| 13210 |
+
template<class... Args>
|
| 13211 |
+
size_t formatted_size(string_view fmt, const Args&... args);
|
| 13212 |
+
template<class... Args>
|
| 13213 |
+
size_t formatted_size(wstring_view fmt, const Args&... args);
|
| 13214 |
+
template<class... Args>
|
| 13215 |
+
size_t formatted_size(const locale& loc, string_view fmt, const Args&... args);
|
| 13216 |
+
template<class... Args>
|
| 13217 |
+
size_t formatted_size(const locale& loc, wstring_view fmt, const Args&... args);
|
| 13218 |
+
|
| 13219 |
+
// [format.formatter], formatter
|
| 13220 |
+
template<class T, class charT = char> struct formatter;
|
| 13221 |
+
|
| 13222 |
+
// [format.parse.ctx], class template basic_format_parse_context
|
| 13223 |
+
template<class charT> class basic_format_parse_context;
|
| 13224 |
+
using format_parse_context = basic_format_parse_context<char>;
|
| 13225 |
+
using wformat_parse_context = basic_format_parse_context<wchar_t>;
|
| 13226 |
+
|
| 13227 |
+
template<class Out, class charT> class basic_format_context;
|
| 13228 |
+
using format_context = basic_format_context<unspecified, char>;
|
| 13229 |
+
using wformat_context = basic_format_context<unspecified, wchar_t>;
|
| 13230 |
+
|
| 13231 |
+
// [format.arguments], arguments
|
| 13232 |
+
// [format.arg], class template basic_format_arg
|
| 13233 |
+
template<class Context> class basic_format_arg;
|
| 13234 |
+
|
| 13235 |
+
template<class Visitor, class Context>
|
| 13236 |
+
see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
|
| 13237 |
+
|
| 13238 |
+
// [format.arg.store], class template format-arg-store
|
| 13239 |
+
template<class Context, class... Args> struct format-arg-store; // exposition only
|
| 13240 |
+
|
| 13241 |
+
template<class Context = format_context, class... Args>
|
| 13242 |
+
format-arg-store<Context, Args...>
|
| 13243 |
+
make_format_args(const Args&... args);
|
| 13244 |
+
template<class... Args>
|
| 13245 |
+
format-arg-store<wformat_context, Args...>
|
| 13246 |
+
make_wformat_args(const Args&... args);
|
| 13247 |
+
|
| 13248 |
+
// [format.args], class template basic_format_args
|
| 13249 |
+
template<class Context> class basic_format_args;
|
| 13250 |
+
using format_args = basic_format_args<format_context>;
|
| 13251 |
+
using wformat_args = basic_format_args<wformat_context>;
|
| 13252 |
+
|
| 13253 |
+
template<class Out, class charT>
|
| 13254 |
+
using format_args_t = basic_format_args<basic_format_context<Out, charT>>;
|
| 13255 |
+
|
| 13256 |
+
// [format.error], class format_error
|
| 13257 |
+
class format_error;
|
| 13258 |
+
}
|
| 13259 |
+
```
|
| 13260 |
+
|
| 13261 |
+
The class template `format_to_n_result` has the template parameters,
|
| 13262 |
+
data members, and special members specified above. It has no base
|
| 13263 |
+
classes or members other than those specified.
|
| 13264 |
+
|
| 13265 |
+
### Format string <a id="format.string">[[format.string]]</a>
|
| 13266 |
+
|
| 13267 |
+
#### In general <a id="format.string.general">[[format.string.general]]</a>
|
| 13268 |
+
|
| 13269 |
+
A *format string* for arguments `args` is a (possibly empty) sequence of
|
| 13270 |
+
*replacement fields*, *escape sequences*, and characters other than `{`
|
| 13271 |
+
and `}`. Let `charT` be the character type of the format string. Each
|
| 13272 |
+
character that is not part of a replacement field or an escape sequence
|
| 13273 |
+
is copied unchanged to the output. An escape sequence is one of `{{` or
|
| 13274 |
+
`}}`. It is replaced with `{` or `}`, respectively, in the output. The
|
| 13275 |
+
syntax of replacement fields is as follows:
|
| 13276 |
+
|
| 13277 |
+
``` bnf
|
| 13278 |
+
replacement-field
|
| 13279 |
+
'{' arg-idₒₚₜ format-specifierₒₚₜ '}'
|
| 13280 |
+
```
|
| 13281 |
+
|
| 13282 |
+
``` bnf
|
| 13283 |
+
arg-id
|
| 13284 |
+
'0'
|
| 13285 |
+
positive-integer
|
| 13286 |
+
```
|
| 13287 |
+
|
| 13288 |
+
``` bnf
|
| 13289 |
+
positive-integer
|
| 13290 |
+
nonzero-digit
|
| 13291 |
+
positive-integer digit
|
| 13292 |
+
```
|
| 13293 |
+
|
| 13294 |
+
``` bnf
|
| 13295 |
+
nonnegative-integer
|
| 13296 |
+
digit
|
| 13297 |
+
nonnegative-integer digit
|
| 13298 |
+
```
|
| 13299 |
+
|
| 13300 |
+
``` bnf
|
| 13301 |
+
nonzero-digit one of
|
| 13302 |
+
'1 2 3 4 5 6 7 8 9'
|
| 13303 |
+
```
|
| 13304 |
+
|
| 13305 |
+
``` bnf
|
| 13306 |
+
digit one of
|
| 13307 |
+
'0 1 2 3 4 5 6 7 8 9'
|
| 13308 |
+
```
|
| 13309 |
+
|
| 13310 |
+
``` bnf
|
| 13311 |
+
format-specifier
|
| 13312 |
+
':' format-spec
|
| 13313 |
+
```
|
| 13314 |
+
|
| 13315 |
+
``` bnf
|
| 13316 |
+
format-spec
|
| 13317 |
+
as specified by the formatter specialization for the argument type
|
| 13318 |
+
```
|
| 13319 |
+
|
| 13320 |
+
The *arg-id* field specifies the index of the argument in `args` whose
|
| 13321 |
+
value is to be formatted and inserted into the output instead of the
|
| 13322 |
+
replacement field. If there is no argument with the index *arg-id* in
|
| 13323 |
+
`args`, the string is not a format string for `args`. The optional
|
| 13324 |
+
*format-specifier* field explicitly specifies a format for the
|
| 13325 |
+
replacement value.
|
| 13326 |
+
|
| 13327 |
+
[*Example 1*:
|
| 13328 |
+
|
| 13329 |
+
``` cpp
|
| 13330 |
+
string s = format("{0}-{{", 8); // value of s is "8-{"
|
| 13331 |
+
```
|
| 13332 |
+
|
| 13333 |
+
— *end example*]
|
| 13334 |
+
|
| 13335 |
+
If all *arg-id*s in a format string are omitted (including those in the
|
| 13336 |
+
*format-spec*, as interpreted by the corresponding `formatter`
|
| 13337 |
+
specialization), argument indices 0, 1, 2, … will automatically be used
|
| 13338 |
+
in that order. If some *arg-id*s are omitted and some are present, the
|
| 13339 |
+
string is not a format string.
|
| 13340 |
+
|
| 13341 |
+
[*Note 1*: A format string cannot contain a mixture of automatic and
|
| 13342 |
+
manual indexing. — *end note*]
|
| 13343 |
+
|
| 13344 |
+
[*Example 2*:
|
| 13345 |
+
|
| 13346 |
+
``` cpp
|
| 13347 |
+
string s0 = format("{} to {}", "a", "b"); // OK, automatic indexing
|
| 13348 |
+
string s1 = format("{1} to {0}", "a", "b"); // OK, manual indexing
|
| 13349 |
+
string s2 = format("{0} to {}", "a", "b"); // not a format string (mixing automatic and manual indexing),
|
| 13350 |
+
// throws format_error
|
| 13351 |
+
string s3 = format("{} to {1}", "a", "b"); // not a format string (mixing automatic and manual indexing),
|
| 13352 |
+
// throws format_error
|
| 13353 |
+
```
|
| 13354 |
+
|
| 13355 |
+
— *end example*]
|
| 13356 |
+
|
| 13357 |
+
The *format-spec* field contains *format specifications* that define how
|
| 13358 |
+
the value should be presented. Each type can define its own
|
| 13359 |
+
interpretation of the *format-spec* field. If *format-spec* does not
|
| 13360 |
+
conform to the format specifications for the argument type referred to
|
| 13361 |
+
by *arg-id*, the string is not a format string for `args`.
|
| 13362 |
+
|
| 13363 |
+
[*Example 3*:
|
| 13364 |
+
|
| 13365 |
+
- For arithmetic, pointer, and string types the *format-spec* is
|
| 13366 |
+
interpreted as a *std-format-spec* as described in
|
| 13367 |
+
[[format.string.std]].
|
| 13368 |
+
- For chrono types the *format-spec* is interpreted as a
|
| 13369 |
+
*chrono-format-spec* as described in [[time.format]].
|
| 13370 |
+
- For user-defined `formatter` specializations, the behavior of the
|
| 13371 |
+
`parse` member function determines how the *format-spec* is
|
| 13372 |
+
interpreted.
|
| 13373 |
+
|
| 13374 |
+
— *end example*]
|
| 13375 |
+
|
| 13376 |
+
#### Standard format specifiers <a id="format.string.std">[[format.string.std]]</a>
|
| 13377 |
+
|
| 13378 |
+
Each `formatter` specializations described in [[format.formatter.spec]]
|
| 13379 |
+
for fundamental and string types interprets *format-spec* as a
|
| 13380 |
+
*std-format-spec*.
|
| 13381 |
+
|
| 13382 |
+
[*Note 1*: The format specification can be used to specify such details
|
| 13383 |
+
as field width, alignment, padding, and decimal precision. Some of the
|
| 13384 |
+
formatting options are only supported for arithmetic
|
| 13385 |
+
types. — *end note*]
|
| 13386 |
+
|
| 13387 |
+
The syntax of format specifications is as follows:
|
| 13388 |
+
|
| 13389 |
+
``` bnf
|
| 13390 |
+
std-format-spec
|
| 13391 |
+
fill-and-alignₒₚₜ signₒₚₜ '#'ₒₚₜ '0'ₒₚₜ widthₒₚₜ precisionₒₚₜ 'L'ₒₚₜ typeₒₚₜ
|
| 13392 |
+
```
|
| 13393 |
+
|
| 13394 |
+
``` bnf
|
| 13395 |
+
fill-and-align
|
| 13396 |
+
fillₒₚₜ align
|
| 13397 |
+
```
|
| 13398 |
+
|
| 13399 |
+
``` bnf
|
| 13400 |
+
fill
|
| 13401 |
+
any character other than \{ or \}
|
| 13402 |
+
```
|
| 13403 |
+
|
| 13404 |
+
``` bnf
|
| 13405 |
+
align one of
|
| 13406 |
+
'< > ^'
|
| 13407 |
+
```
|
| 13408 |
+
|
| 13409 |
+
``` bnf
|
| 13410 |
+
sign one of
|
| 13411 |
+
'+ -' space
|
| 13412 |
+
```
|
| 13413 |
+
|
| 13414 |
+
``` bnf
|
| 13415 |
+
width
|
| 13416 |
+
positive-integer
|
| 13417 |
+
'{' arg-idₒₚₜ '}'
|
| 13418 |
+
```
|
| 13419 |
+
|
| 13420 |
+
``` bnf
|
| 13421 |
+
precision
|
| 13422 |
+
'.' nonnegative-integer
|
| 13423 |
+
'.' '{' arg-idₒₚₜ '}'
|
| 13424 |
+
```
|
| 13425 |
+
|
| 13426 |
+
``` bnf
|
| 13427 |
+
type one of
|
| 13428 |
+
'a A b B c d e E f F g G o p s x X'
|
| 13429 |
+
```
|
| 13430 |
+
|
| 13431 |
+
[*Note 2*: The *fill* character can be any character other than `{` or
|
| 13432 |
+
`}`. The presence of a fill character is signaled by the character
|
| 13433 |
+
following it, which must be one of the alignment options. If the second
|
| 13434 |
+
character of *std-format-spec* is not a valid alignment option, then it
|
| 13435 |
+
is assumed that both the fill character and the alignment option are
|
| 13436 |
+
absent. — *end note*]
|
| 13437 |
+
|
| 13438 |
+
The *align* specifier applies to all argument types. The meaning of the
|
| 13439 |
+
various alignment options is as specified in [[format.align]].
|
| 13440 |
+
|
| 13441 |
+
[*Example 1*:
|
| 13442 |
+
|
| 13443 |
+
``` cpp
|
| 13444 |
+
char c = 120;
|
| 13445 |
+
string s0 = format("{:6}", 42); // value of s0 is "\ \ \ \ 42"
|
| 13446 |
+
string s1 = format("{:6}", 'x'); // value of s1 is "x\ \ \ \ \ "
|
| 13447 |
+
string s2 = format("{:*<6}", 'x'); // value of s2 is "x*****"
|
| 13448 |
+
string s3 = format("{:*>6}", 'x'); // value of s3 is "*****x"
|
| 13449 |
+
string s4 = format("{:*^6}", 'x'); // value of s4 is "**x***"
|
| 13450 |
+
string s5 = format("{:6d}", c); // value of s5 is "\ \ \ 120"
|
| 13451 |
+
string s6 = format("{:6}", true); // value of s6 is "true\ \ "
|
| 13452 |
+
```
|
| 13453 |
+
|
| 13454 |
+
— *end example*]
|
| 13455 |
+
|
| 13456 |
+
[*Note 3*: Unless a minimum field width is defined, the field width is
|
| 13457 |
+
determined by the size of the content and the alignment option has no
|
| 13458 |
+
effect. — *end note*]
|
| 13459 |
+
|
| 13460 |
+
**Table: Meaning of align options** <a id="format.align">[format.align]</a>
|
| 13461 |
+
|
| 13462 |
+
| Option | Meaning |
|
| 13463 |
+
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 13464 |
+
| `<` | Forces the field to be aligned to the start of the available space. This is the default for non-arithmetic types, `charT`, and `bool`, unless an integer presentation type is specified. |
|
| 13465 |
+
| % `>` | Forces the field to be aligned to the end of the available space. This is the default for arithmetic types other than `charT` and `bool` or when an integer presentation type is specified. |
|
| 13466 |
+
| % `^` | Forces the field to be centered within the available space by inserting $\bigl\lfloor \frac{n}{2} \bigr\rfloor$ characters before and $\bigl\lceil \frac{n}{2} \bigr\rceil$ characters after the value, where $n$ is the total number of fill characters to insert. |
|
| 13467 |
+
|
| 13468 |
+
|
| 13469 |
+
The *sign* option is only valid for arithmetic types other than `charT`
|
| 13470 |
+
and `bool` or when an integer presentation type is specified. The
|
| 13471 |
+
meaning of the various options is as specified in [[format.sign]].
|
| 13472 |
+
|
| 13473 |
+
[*Note 4*: For negative numbers and negative zero the output of
|
| 13474 |
+
`to_chars` will already contain the sign so no additional transformation
|
| 13475 |
+
is performed. — *end note*]
|
| 13476 |
+
|
| 13477 |
+
The *sign* option applies to floating-point infinity and NaN.
|
| 13478 |
+
|
| 13479 |
+
[*Example 2*:
|
| 13480 |
+
|
| 13481 |
+
``` cpp
|
| 13482 |
+
double inf = numeric_limits<double>::infinity();
|
| 13483 |
+
double nan = numeric_limits<double>::quiet_NaN();
|
| 13484 |
+
string s0 = format("{0:},{0:+},{0:-},{0: }", 1); // value of s0 is "1,+1,1, 1"
|
| 13485 |
+
string s1 = format("{0:},{0:+},{0:-},{0: }", -1); // value of s1 is "-1,-1,-1,-1"
|
| 13486 |
+
string s2 = format("{0:},{0:+},{0:-},{0: }", inf); // value of s2 is "inf,+inf,inf, inf"
|
| 13487 |
+
string s3 = format("{0:},{0:+},{0:-},{0: }", nan); // value of s3 is "nan,+nan,nan, nan"
|
| 13488 |
+
```
|
| 13489 |
+
|
| 13490 |
+
— *end example*]
|
| 13491 |
+
|
| 13492 |
+
The `#` option causes the *alternate form* to be used for the
|
| 13493 |
+
conversion. This option is valid for arithmetic types other than `charT`
|
| 13494 |
+
and `bool` or when an integer presentation type is specified, and not
|
| 13495 |
+
otherwise. For integral types, the alternate form inserts the base
|
| 13496 |
+
prefix (if any) specified in [[format.type.int]] into the output after
|
| 13497 |
+
the sign character (possibly space) if there is one, or before the
|
| 13498 |
+
output of `to_chars` otherwise. For floating-point types, the alternate
|
| 13499 |
+
form causes the result of the conversion of finite values to always
|
| 13500 |
+
contain a decimal-point character, even if no digits follow it.
|
| 13501 |
+
Normally, a decimal-point character appears in the result of these
|
| 13502 |
+
conversions only if a digit follows it. In addition, for `g` and `G`
|
| 13503 |
+
conversions, trailing zeros are not removed from the result.
|
| 13504 |
+
|
| 13505 |
+
If `{ \opt{arg-id} }` is used in a *width* or *precision*, the value of
|
| 13506 |
+
the corresponding formatting argument is used in its place. If the
|
| 13507 |
+
corresponding formatting argument is not of integral type, or its value
|
| 13508 |
+
is negative for *precision* or non-positive for *width*, an exception of
|
| 13509 |
+
type `format_error` is thrown.
|
| 13510 |
+
|
| 13511 |
+
The *positive-integer* in *width* is a decimal integer defining the
|
| 13512 |
+
minimum field width. If *width* is not specified, there is no minimum
|
| 13513 |
+
field width, and the field width is determined based on the content of
|
| 13514 |
+
the field.
|
| 13515 |
+
|
| 13516 |
+
The *width* of a string is defined as the estimated number of column
|
| 13517 |
+
positions appropriate for displaying it in a terminal.
|
| 13518 |
+
|
| 13519 |
+
[*Note 5*: This is similar to the semantics of the POSIX `wcswidth`
|
| 13520 |
+
function. — *end note*]
|
| 13521 |
+
|
| 13522 |
+
For the purposes of width computation, a string is assumed to be in a
|
| 13523 |
+
locale-independent, implementation-defined encoding. Implementations
|
| 13524 |
+
should use a Unicode encoding on platforms capable of displaying Unicode
|
| 13525 |
+
text in a terminal.
|
| 13526 |
+
|
| 13527 |
+
[*Note 6*: This is the case for Windows-based and many POSIX-based
|
| 13528 |
+
operating systems. — *end note*]
|
| 13529 |
+
|
| 13530 |
+
For a string in a Unicode encoding, implementations should estimate the
|
| 13531 |
+
width of a string as the sum of estimated widths of the first code
|
| 13532 |
+
points in its extended grapheme clusters. The extended grapheme clusters
|
| 13533 |
+
of a string are defined by UAX \#29. The estimated width of the
|
| 13534 |
+
following code points is 2:
|
| 13535 |
+
|
| 13536 |
+
- `U+1100-U+115F`
|
| 13537 |
+
- `U+2329-U+232A`
|
| 13538 |
+
- `U+2E80-U+303E`
|
| 13539 |
+
- `U+3040-U+A4CF`
|
| 13540 |
+
- `U+AC00-U+D7A3`
|
| 13541 |
+
- `U+F900-U+FAFF`
|
| 13542 |
+
- `U+FE10-U+FE19`
|
| 13543 |
+
- `U+FE30-U+FE6F`
|
| 13544 |
+
- `U+FF00-U+FF60`
|
| 13545 |
+
- `U+FFE0-U+FFE6`
|
| 13546 |
+
- `U+1F300-U+1F64F`
|
| 13547 |
+
- `U+1F900-U+1F9FF`
|
| 13548 |
+
- `U+20000-U+2FFFD`
|
| 13549 |
+
- `U+30000-U+3FFFD`
|
| 13550 |
+
|
| 13551 |
+
The estimated width of other code points is 1.
|
| 13552 |
+
|
| 13553 |
+
For a string in a non-Unicode encoding, the width of a string is
|
| 13554 |
+
unspecified.
|
| 13555 |
+
|
| 13556 |
+
A zero (`0`) character preceding the *width* field pads the field with
|
| 13557 |
+
leading zeros (following any indication of sign or base) to the field
|
| 13558 |
+
width, except when applied to an infinity or NaN. This option is only
|
| 13559 |
+
valid for arithmetic types other than `charT` and `bool` or when an
|
| 13560 |
+
integer presentation type is specified. If the `0` character and an
|
| 13561 |
+
*align* option both appear, the `0` character is ignored.
|
| 13562 |
+
|
| 13563 |
+
[*Example 3*:
|
| 13564 |
+
|
| 13565 |
+
``` cpp
|
| 13566 |
+
char c = 120;
|
| 13567 |
+
string s1 = format("{:+06d}", c); // value of s1 is "+00120"
|
| 13568 |
+
string s2 = format("{:#06x}", 0xa); // value of s2 is "0x000a"
|
| 13569 |
+
string s3 = format("{:<06}", -42); // value of s3 is "-42\ \ \ " (0 is ignored because of < alignment)
|
| 13570 |
+
```
|
| 13571 |
+
|
| 13572 |
+
— *end example*]
|
| 13573 |
+
|
| 13574 |
+
The *nonnegative-integer* in *precision* is a decimal integer defining
|
| 13575 |
+
the precision or maximum field size. It can only be used with
|
| 13576 |
+
floating-point and string types. For floating-point types this field
|
| 13577 |
+
specifies the formatting precision. For string types, this field
|
| 13578 |
+
provides an upper bound for the estimated width of the prefix of the
|
| 13579 |
+
input string that is copied into the output. For a string in a Unicode
|
| 13580 |
+
encoding, the formatter copies to the output the longest prefix of whole
|
| 13581 |
+
extended grapheme clusters whose estimated width is no greater than the
|
| 13582 |
+
precision.
|
| 13583 |
+
|
| 13584 |
+
When the `L` option is used, the form used for the conversion is called
|
| 13585 |
+
the *locale-specific form*. The `L` option is only valid for arithmetic
|
| 13586 |
+
types, and its effect depends upon the type.
|
| 13587 |
+
|
| 13588 |
+
- For integral types, the locale-specific form causes the context’s
|
| 13589 |
+
locale to be used to insert the appropriate digit group separator
|
| 13590 |
+
characters.
|
| 13591 |
+
- For floating-point types, the locale-specific form causes the
|
| 13592 |
+
context’s locale to be used to insert the appropriate digit group and
|
| 13593 |
+
radix separator characters.
|
| 13594 |
+
- For the textual representation of `bool`, the locale-specific form
|
| 13595 |
+
causes the context’s locale to be used to insert the appropriate
|
| 13596 |
+
string as if obtained with `numpunct::truename` or
|
| 13597 |
+
`numpunct::falsename`.
|
| 13598 |
+
|
| 13599 |
+
The *type* determines how the data should be presented.
|
| 13600 |
+
|
| 13601 |
+
The available string presentation types are specified in
|
| 13602 |
+
[[format.type.string]].
|
| 13603 |
+
|
| 13604 |
+
**Table: Meaning of type options for strings** <a id="format.type.string">[format.type.string]</a>
|
| 13605 |
+
|
| 13606 |
+
| Type | Meaning |
|
| 13607 |
+
| --------- | -------------------------------- |
|
| 13608 |
+
| none, `s` | Copies the string to the output. |
|
| 13609 |
+
|
| 13610 |
+
|
| 13611 |
+
The meaning of some non-string presentation types is defined in terms of
|
| 13612 |
+
a call to `to_chars`. In such cases, let \[`first`, `last`) be a range
|
| 13613 |
+
large enough to hold the `to_chars` output and `value` be the formatting
|
| 13614 |
+
argument value. Formatting is done as if by calling `to_chars` as
|
| 13615 |
+
specified and copying the output through the output iterator of the
|
| 13616 |
+
format context.
|
| 13617 |
+
|
| 13618 |
+
[*Note 7*: Additional padding and adjustments are performed prior to
|
| 13619 |
+
copying the output through the output iterator as specified by the
|
| 13620 |
+
format specifiers. — *end note*]
|
| 13621 |
+
|
| 13622 |
+
The available integer presentation types for integral types other than
|
| 13623 |
+
`bool` and `charT` are specified in [[format.type.int]].
|
| 13624 |
+
|
| 13625 |
+
[*Example 4*:
|
| 13626 |
+
|
| 13627 |
+
``` cpp
|
| 13628 |
+
string s0 = format("{}", 42); // value of s0 is "42"
|
| 13629 |
+
string s1 = format("{0:b} {0:d} {0:o} {0:x}", 42); // value of s1 is "101010 42 52 2a"
|
| 13630 |
+
string s2 = format("{0:#x} {0:#X}", 42); // value of s2 is "0x2a 0X2A"
|
| 13631 |
+
string s3 = format("{:L}", 1234); // value of s3 might be "1,234"
|
| 13632 |
+
// (depending on the locale)
|
| 13633 |
+
```
|
| 13634 |
+
|
| 13635 |
+
— *end example*]
|
| 13636 |
+
|
| 13637 |
+
[*Note 8*: If the formatting argument type is `charT` or `bool`, the
|
| 13638 |
+
default is instead `c` or `s`, respectively. — *end note*]
|
| 13639 |
+
|
| 13640 |
+
The available `charT` presentation types are specified in
|
| 13641 |
+
[[format.type.char]].
|
| 13642 |
+
|
| 13643 |
+
**Table: Meaning of type options for `charT`** <a id="format.type.char">[format.type.char]</a>
|
| 13644 |
+
|
| 13645 |
+
| Type | Meaning |
|
| 13646 |
+
| ------------------------------ | ------------------------------------ |
|
| 13647 |
+
| none, `c` | Copies the character to the output. |
|
| 13648 |
+
| % `b`, `B`, `d`, `o`, `x`, `X` | As specified in [[format.type.int]]. |
|
| 13649 |
+
|
| 13650 |
+
|
| 13651 |
+
The available `bool` presentation types are specified in
|
| 13652 |
+
[[format.type.bool]].
|
| 13653 |
+
|
| 13654 |
+
**Table: Meaning of type options for `bool`** <a id="format.type.bool">[format.type.bool]</a>
|
| 13655 |
+
|
| 13656 |
+
| Type | Meaning |
|
| 13657 |
+
| ----------------------------------- | -------------------------------------------------------------------------------------- |
|
| 13658 |
+
| none, `s` | Copies textual representation, either `true` or `false`, to the output. |
|
| 13659 |
+
| % `b`, `B`, `c`, `d`, `o`, `x`, `X` | As specified in [[format.type.int]] for the value `static_cast<unsigned char>(value)`. |
|
| 13660 |
+
|
| 13661 |
+
|
| 13662 |
+
The available floating-point presentation types and their meanings for
|
| 13663 |
+
values other than infinity and NaN are specified in
|
| 13664 |
+
[[format.type.float]]. For lower-case presentation types, infinity and
|
| 13665 |
+
NaN are formatted as `inf` and `nan`, respectively. For upper-case
|
| 13666 |
+
presentation types, infinity and NaN are formatted as `INF` and `NAN`,
|
| 13667 |
+
respectively.
|
| 13668 |
+
|
| 13669 |
+
[*Note 9*: In either case, a sign is included if indicated by the
|
| 13670 |
+
*sign* option. — *end note*]
|
| 13671 |
+
|
| 13672 |
+
**Table: Meaning of type options for floating-point types** <a id="format.type.float">[format.type.float]</a>
|
| 13673 |
+
|
| 13674 |
+
| Type | Meaning |
|
| 13675 |
+
| ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 13676 |
+
| `a` | If precision is specified, equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::hex, precision) \end{codeblock} where `precision` is the specified formatting precision; equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::hex) \end{codeblock} otherwise. |
|
| 13677 |
+
| % `A` | The same as `a`, except that it uses uppercase letters for digits above 9 and `P` to indicate the exponent. |
|
| 13678 |
+
| % `e` | Equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::scientific, precision) \end{codeblock} where `precision` is the specified formatting precision, or `6` if precision is not specified. |
|
| 13679 |
+
| % `E` | The same as `e`, except that it uses `E` to indicate exponent. |
|
| 13680 |
+
| % `f`, `F` | Equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::fixed, precision) \end{codeblock} where `precision` is the specified formatting precision, or `6` if precision is not specified. |
|
| 13681 |
+
| % `g` | Equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::general, precision) \end{codeblock} where `precision` is the specified formatting precision, or `6` if precision is not specified. |
|
| 13682 |
+
| % `G` | The same as `g`, except that it uses `E` to indicate exponent. |
|
| 13683 |
+
| % none | If precision is specified, equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::general, precision) \end{codeblock} where `precision` is the specified formatting precision; equivalent to \begin{codeblock} to_chars(first, last, value) \end{codeblock} otherwise. |
|
| 13684 |
+
|
| 13685 |
+
|
| 13686 |
+
The available pointer presentation types and their mapping to `to_chars`
|
| 13687 |
+
are specified in [[format.type.ptr]].
|
| 13688 |
+
|
| 13689 |
+
[*Note 10*: Pointer presentation types also apply to
|
| 13690 |
+
`nullptr_t`. — *end note*]
|
| 13691 |
+
|
| 13692 |
+
**Table: Meaning of type options for pointer types** <a id="format.type.ptr">[format.type.ptr]</a>
|
| 13693 |
+
|
| 13694 |
+
| Type | Meaning |
|
| 13695 |
+
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 13696 |
+
| none, `p` | If `uintptr_t` is defined, \begin{codeblock} to_chars(first, last, reinterpret_cast<uintptr_t>(value), 16) \end{codeblock} with the prefix `0x` added to the output; otherwise, implementation-defined. |
|
| 13697 |
+
|
| 13698 |
+
|
| 13699 |
+
### Error reporting <a id="format.err.report">[[format.err.report]]</a>
|
| 13700 |
+
|
| 13701 |
+
Formatting functions throw `format_error` if an argument `fmt` is passed
|
| 13702 |
+
that is not a format string for `args`. They propagate exceptions thrown
|
| 13703 |
+
by operations of `formatter` specializations and iterators. Failure to
|
| 13704 |
+
allocate storage is reported by throwing an exception as described in
|
| 13705 |
+
[[res.on.exception.handling]].
|
| 13706 |
+
|
| 13707 |
+
### Formatting functions <a id="format.functions">[[format.functions]]</a>
|
| 13708 |
+
|
| 13709 |
+
In the description of the functions, operator `+` is used for some of
|
| 13710 |
+
the iterator categories for which it does not have to be defined. In
|
| 13711 |
+
these cases the semantics of `a + n` are the same as in
|
| 13712 |
+
[[algorithms.requirements]].
|
| 13713 |
+
|
| 13714 |
+
``` cpp
|
| 13715 |
+
template<class... Args>
|
| 13716 |
+
string format(string_view fmt, const Args&... args);
|
| 13717 |
+
```
|
| 13718 |
+
|
| 13719 |
+
*Effects:* Equivalent to:
|
| 13720 |
+
|
| 13721 |
+
``` cpp
|
| 13722 |
+
return vformat(fmt, make_format_args(args...));
|
| 13723 |
+
```
|
| 13724 |
+
|
| 13725 |
+
``` cpp
|
| 13726 |
+
template<class... Args>
|
| 13727 |
+
wstring format(wstring_view fmt, const Args&... args);
|
| 13728 |
+
```
|
| 13729 |
+
|
| 13730 |
+
*Effects:* Equivalent to:
|
| 13731 |
+
|
| 13732 |
+
``` cpp
|
| 13733 |
+
return vformat(fmt, make_wformat_args(args...));
|
| 13734 |
+
```
|
| 13735 |
+
|
| 13736 |
+
``` cpp
|
| 13737 |
+
template<class... Args>
|
| 13738 |
+
string format(const locale& loc, string_view fmt, const Args&... args);
|
| 13739 |
+
```
|
| 13740 |
+
|
| 13741 |
+
*Effects:* Equivalent to:
|
| 13742 |
+
|
| 13743 |
+
``` cpp
|
| 13744 |
+
return vformat(loc, fmt, make_format_args(args...));
|
| 13745 |
+
```
|
| 13746 |
+
|
| 13747 |
+
``` cpp
|
| 13748 |
+
template<class... Args>
|
| 13749 |
+
wstring format(const locale& loc, wstring_view fmt, const Args&... args);
|
| 13750 |
+
```
|
| 13751 |
+
|
| 13752 |
+
*Effects:* Equivalent to:
|
| 13753 |
+
|
| 13754 |
+
``` cpp
|
| 13755 |
+
return vformat(loc, fmt, make_wformat_args(args...));
|
| 13756 |
+
```
|
| 13757 |
+
|
| 13758 |
+
``` cpp
|
| 13759 |
+
string vformat(string_view fmt, format_args args);
|
| 13760 |
+
wstring vformat(wstring_view fmt, wformat_args args);
|
| 13761 |
+
string vformat(const locale& loc, string_view fmt, format_args args);
|
| 13762 |
+
wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
|
| 13763 |
+
```
|
| 13764 |
+
|
| 13765 |
+
*Returns:* A string object holding the character representation of
|
| 13766 |
+
formatting arguments provided by `args` formatted according to
|
| 13767 |
+
specifications given in `fmt`. If present, `loc` is used for
|
| 13768 |
+
locale-specific formatting.
|
| 13769 |
+
|
| 13770 |
+
*Throws:* As specified in [[format.err.report]].
|
| 13771 |
+
|
| 13772 |
+
``` cpp
|
| 13773 |
+
template<class Out, class... Args>
|
| 13774 |
+
Out format_to(Out out, string_view fmt, const Args&... args);
|
| 13775 |
+
template<class Out, class... Args>
|
| 13776 |
+
Out format_to(Out out, wstring_view fmt, const Args&... args);
|
| 13777 |
+
```
|
| 13778 |
+
|
| 13779 |
+
*Effects:* Equivalent to:
|
| 13780 |
+
|
| 13781 |
+
``` cpp
|
| 13782 |
+
using context = basic_format_context<Out, decltype(fmt)::value_type>;
|
| 13783 |
+
return vformat_to(out, fmt, make_format_args<context>(args...));
|
| 13784 |
+
```
|
| 13785 |
+
|
| 13786 |
+
``` cpp
|
| 13787 |
+
template<class Out, class... Args>
|
| 13788 |
+
Out format_to(Out out, const locale& loc, string_view fmt, const Args&... args);
|
| 13789 |
+
template<class Out, class... Args>
|
| 13790 |
+
Out format_to(Out out, const locale& loc, wstring_view fmt, const Args&... args);
|
| 13791 |
+
```
|
| 13792 |
+
|
| 13793 |
+
*Effects:* Equivalent to:
|
| 13794 |
+
|
| 13795 |
+
``` cpp
|
| 13796 |
+
using context = basic_format_context<Out, decltype(fmt)::value_type>;
|
| 13797 |
+
return vformat_to(out, loc, fmt, make_format_args<context>(args...));
|
| 13798 |
+
```
|
| 13799 |
+
|
| 13800 |
+
``` cpp
|
| 13801 |
+
template<class Out>
|
| 13802 |
+
Out vformat_to(Out out, string_view fmt,
|
| 13803 |
+
format_args_t<type_identity_t<Out>, char> args);
|
| 13804 |
+
template<class Out>
|
| 13805 |
+
Out vformat_to(Out out, wstring_view fmt,
|
| 13806 |
+
format_args_t<type_identity_t<Out>, wchar_t> args);
|
| 13807 |
+
template<class Out>
|
| 13808 |
+
Out vformat_to(Out out, const locale& loc, string_view fmt,
|
| 13809 |
+
format_args_t<type_identity_t<Out>, char> args);
|
| 13810 |
+
template<class Out>
|
| 13811 |
+
Out vformat_to(Out out, const locale& loc, wstring_view fmt,
|
| 13812 |
+
format_args_t<type_identity_t<Out>, wchar_t> args);
|
| 13813 |
+
```
|
| 13814 |
+
|
| 13815 |
+
Let `charT` be `decltype(fmt)::value_type`.
|
| 13816 |
+
|
| 13817 |
+
*Constraints:* `Out` satisfies `output_iterator<const charT&>`.
|
| 13818 |
+
|
| 13819 |
+
*Preconditions:* `Out` models `output_iterator<const charT&>`.
|
| 13820 |
+
|
| 13821 |
+
*Effects:* Places the character representation of formatting the
|
| 13822 |
+
arguments provided by `args`, formatted according to the specifications
|
| 13823 |
+
given in `fmt`, into the range \[`out`, `out + N`), where `N` is
|
| 13824 |
+
`formatted_size(fmt, args...)` for the functions without a `loc`
|
| 13825 |
+
parameter and `formatted_size(loc, fmt, args...)` for the functions with
|
| 13826 |
+
a `loc` parameter. If present, `loc` is used for locale-specific
|
| 13827 |
+
formatting.
|
| 13828 |
+
|
| 13829 |
+
*Returns:* `out + N`.
|
| 13830 |
+
|
| 13831 |
+
*Throws:* As specified in [[format.err.report]].
|
| 13832 |
+
|
| 13833 |
+
``` cpp
|
| 13834 |
+
template<class Out, class... Args>
|
| 13835 |
+
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
| 13836 |
+
string_view fmt, const Args&... args);
|
| 13837 |
+
template<class Out, class... Args>
|
| 13838 |
+
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
| 13839 |
+
wstring_view fmt, const Args&... args);
|
| 13840 |
+
template<class Out, class... Args>
|
| 13841 |
+
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
| 13842 |
+
const locale& loc, string_view fmt,
|
| 13843 |
+
const Args&... args);
|
| 13844 |
+
template<class Out, class... Args>
|
| 13845 |
+
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
| 13846 |
+
const locale& loc, wstring_view fmt,
|
| 13847 |
+
const Args&... args);
|
| 13848 |
+
```
|
| 13849 |
+
|
| 13850 |
+
Let
|
| 13851 |
+
|
| 13852 |
+
- `charT` be `decltype(fmt)::value_type`,
|
| 13853 |
+
- `N` be `formatted_size(fmt, args...)` for the functions without a
|
| 13854 |
+
`loc` parameter and `formatted_size(loc, fmt, args...)` for the
|
| 13855 |
+
functions with a `loc` parameter, and
|
| 13856 |
+
- `M` be `clamp(n, 0, N)`.
|
| 13857 |
+
|
| 13858 |
+
*Constraints:* `Out` satisfies `output_iterator<const charT&>`.
|
| 13859 |
+
|
| 13860 |
+
*Preconditions:* `Out` models `output_iterator<const charT&>`, and
|
| 13861 |
+
`formatter<``Tᵢ``, charT>` meets the
|
| 13862 |
+
requirements [[formatter.requirements]] for each `Tᵢ` in `Args`.
|
| 13863 |
+
|
| 13864 |
+
*Effects:* Places the first `M` characters of the character
|
| 13865 |
+
representation of formatting the arguments provided by `args`, formatted
|
| 13866 |
+
according to the specifications given in `fmt`, into the range \[`out`,
|
| 13867 |
+
`out + M`). If present, `loc` is used for locale-specific formatting.
|
| 13868 |
+
|
| 13869 |
+
*Returns:* `{out + M, N}`.
|
| 13870 |
+
|
| 13871 |
+
*Throws:* As specified in [[format.err.report]].
|
| 13872 |
+
|
| 13873 |
+
``` cpp
|
| 13874 |
+
template<class... Args>
|
| 13875 |
+
size_t formatted_size(string_view fmt, const Args&... args);
|
| 13876 |
+
template<class... Args>
|
| 13877 |
+
size_t formatted_size(wstring_view fmt, const Args&... args);
|
| 13878 |
+
template<class... Args>
|
| 13879 |
+
size_t formatted_size(const locale& loc, string_view fmt, const Args&... args);
|
| 13880 |
+
template<class... Args>
|
| 13881 |
+
size_t formatted_size(const locale& loc, wstring_view fmt, const Args&... args);
|
| 13882 |
+
```
|
| 13883 |
+
|
| 13884 |
+
Let `charT` be `decltype(fmt)::value_type`.
|
| 13885 |
+
|
| 13886 |
+
*Preconditions:* `formatter<``Tᵢ``, charT>` meets the
|
| 13887 |
+
requirements [[formatter.requirements]] for each `Tᵢ` in `Args`.
|
| 13888 |
+
|
| 13889 |
+
*Returns:* The number of characters in the character representation of
|
| 13890 |
+
formatting arguments `args` formatted according to specifications given
|
| 13891 |
+
in `fmt`. If present, `loc` is used for locale-specific formatting.
|
| 13892 |
+
|
| 13893 |
+
*Throws:* As specified in [[format.err.report]].
|
| 13894 |
+
|
| 13895 |
+
### Formatter <a id="format.formatter">[[format.formatter]]</a>
|
| 13896 |
+
|
| 13897 |
+
#### Formatter requirements <a id="formatter.requirements">[[formatter.requirements]]</a>
|
| 13898 |
+
|
| 13899 |
+
A type `F` meets the requirements if:
|
| 13900 |
+
|
| 13901 |
+
- it meets the
|
| 13902 |
+
- *Cpp17DefaultConstructible* ([[cpp17.defaultconstructible]]),
|
| 13903 |
+
- *Cpp17CopyConstructible* ([[cpp17.copyconstructible]]),
|
| 13904 |
+
- *Cpp17CopyAssignable* ([[cpp17.copyassignable]]), and
|
| 13905 |
+
- *Cpp17Destructible* ([[cpp17.destructible]])
|
| 13906 |
+
|
| 13907 |
+
requirements,
|
| 13908 |
+
- it is swappable [[swappable.requirements]] for lvalues, and
|
| 13909 |
+
- the expressions shown in [[formatter]] are valid and have the
|
| 13910 |
+
indicated semantics.
|
| 13911 |
+
|
| 13912 |
+
Given character type `charT`, output iterator type `Out`, and formatting
|
| 13913 |
+
argument type `T`, in [[formatter]]:
|
| 13914 |
+
|
| 13915 |
+
- `f` is a value of type `F`,
|
| 13916 |
+
- `u` is an lvalue of type `T`,
|
| 13917 |
+
- `t` is a value of a type convertible to (possibly const) `T`,
|
| 13918 |
+
- `PC` is `basic_format_parse_context<charT>`,
|
| 13919 |
+
- `FC` is `basic_format_context<Out, charT>`,
|
| 13920 |
+
- `pc` is an lvalue of type `PC`, and
|
| 13921 |
+
- `fc` is an lvalue of type `FC`.
|
| 13922 |
+
|
| 13923 |
+
`pc.begin()` points to the beginning of the *format-spec*
|
| 13924 |
+
[[format.string]] of the replacement field being formatted in the format
|
| 13925 |
+
string. If *format-spec* is empty then either `pc.begin() == pc.end()`
|
| 13926 |
+
or `*pc.begin() == '}'`.
|
| 13927 |
+
|
| 13928 |
+
[*Note 1*: This allows formatters to emit meaningful error
|
| 13929 |
+
messages. — *end note*]
|
| 13930 |
+
|
| 13931 |
+
#### Formatter specializations <a id="format.formatter.spec">[[format.formatter.spec]]</a>
|
| 13932 |
+
|
| 13933 |
+
The functions defined in [[format.functions]] use specializations of the
|
| 13934 |
+
class template `formatter` to format individual arguments.
|
| 13935 |
+
|
| 13936 |
+
Let `charT` be either `char` or `wchar_t`. Each specialization of
|
| 13937 |
+
`formatter` is either enabled or disabled, as described below.
|
| 13938 |
+
|
| 13939 |
+
[*Note 1*: Enabled specializations meet the requirements, and disabled
|
| 13940 |
+
specializations do not. — *end note*]
|
| 13941 |
+
|
| 13942 |
+
Each header that declares the template `formatter` provides the
|
| 13943 |
+
following enabled specializations:
|
| 13944 |
+
|
| 13945 |
+
- The specializations
|
| 13946 |
+
``` cpp
|
| 13947 |
+
template<> struct formatter<char, char>;
|
| 13948 |
+
template<> struct formatter<char, wchar_t>;
|
| 13949 |
+
template<> struct formatter<wchar_t, wchar_t>;
|
| 13950 |
+
```
|
| 13951 |
+
- For each `charT`, the string type specializations
|
| 13952 |
+
``` cpp
|
| 13953 |
+
template<> struct formatter<charT*, charT>;
|
| 13954 |
+
template<> struct formatter<const charT*, charT>;
|
| 13955 |
+
template<size_t N> struct formatter<const charT[N], charT>;
|
| 13956 |
+
template<class traits, class Allocator>
|
| 13957 |
+
struct formatter<basic_string<charT, traits, Allocator>, charT>;
|
| 13958 |
+
template<class traits>
|
| 13959 |
+
struct formatter<basic_string_view<charT, traits>, charT>;
|
| 13960 |
+
```
|
| 13961 |
+
- For each `charT`, for each cv-unqualified arithmetic type
|
| 13962 |
+
`ArithmeticT` other than `char`, `wchar_t`, `char8_t`, `char16_t`, or
|
| 13963 |
+
`char32_t`, a specialization
|
| 13964 |
+
``` cpp
|
| 13965 |
+
template<> struct formatter<ArithmeticT, charT>;
|
| 13966 |
+
```
|
| 13967 |
+
- For each `charT`, the pointer type specializations
|
| 13968 |
+
``` cpp
|
| 13969 |
+
template<> struct formatter<nullptr_t, charT>;
|
| 13970 |
+
template<> struct formatter<void*, charT>;
|
| 13971 |
+
template<> struct formatter<const void*, charT>;
|
| 13972 |
+
```
|
| 13973 |
+
|
| 13974 |
+
The `parse` member functions of these formatters interpret the format
|
| 13975 |
+
specification as a *std-format-spec* as described in
|
| 13976 |
+
[[format.string.std]].
|
| 13977 |
+
|
| 13978 |
+
[*Note 2*: Specializations such as `formatter<wchar_t, char>` and
|
| 13979 |
+
`formatter<const char*, wchar_t>` that would require implicit multibyte
|
| 13980 |
+
/ wide string or character conversion are disabled. — *end note*]
|
| 13981 |
+
|
| 13982 |
+
For any types `T` and `charT` for which neither the library nor the user
|
| 13983 |
+
provides an explicit or partial specialization of the class template
|
| 13984 |
+
`formatter`, `formatter<T, charT>` is disabled.
|
| 13985 |
+
|
| 13986 |
+
If the library provides an explicit or partial specialization of
|
| 13987 |
+
`formatter<T, charT>`, that specialization is enabled except as noted
|
| 13988 |
+
otherwise.
|
| 13989 |
+
|
| 13990 |
+
If `F` is a disabled specialization of `formatter`, these values are
|
| 13991 |
+
`false`:
|
| 13992 |
+
|
| 13993 |
+
- `is_default_constructible_v<F>`,
|
| 13994 |
+
- `is_copy_constructible_v<F>`,
|
| 13995 |
+
- `is_move_constructible_v<F>`,
|
| 13996 |
+
- `is_copy_assignable_v<F>`, and
|
| 13997 |
+
- `is_move_assignable_v<F>`.
|
| 13998 |
+
|
| 13999 |
+
An enabled specialization `formatter<T, charT>` meets the requirements
|
| 14000 |
+
[[formatter.requirements]].
|
| 14001 |
+
|
| 14002 |
+
[*Example 1*:
|
| 14003 |
+
|
| 14004 |
+
``` cpp
|
| 14005 |
+
#include <format>
|
| 14006 |
+
|
| 14007 |
+
enum color { red, green, blue };
|
| 14008 |
+
const char* color_names[] = { "red", "green", "blue" };
|
| 14009 |
+
|
| 14010 |
+
template<> struct std::formatter<color> : std::formatter<const char*> {
|
| 14011 |
+
auto format(color c, format_context& ctx) {
|
| 14012 |
+
return formatter<const char*>::format(color_names[c], ctx);
|
| 14013 |
+
}
|
| 14014 |
+
};
|
| 14015 |
+
|
| 14016 |
+
struct err {};
|
| 14017 |
+
|
| 14018 |
+
std::string s0 = std::format("{}", 42); // OK, library-provided formatter
|
| 14019 |
+
std::string s1 = std::format("{}", L"foo"); // error: disabled formatter
|
| 14020 |
+
std::string s2 = std::format("{}", red); // OK, user-provided formatter
|
| 14021 |
+
std::string s3 = std::format("{}", err{}); // error: disabled formatter
|
| 14022 |
+
```
|
| 14023 |
+
|
| 14024 |
+
— *end example*]
|
| 14025 |
+
|
| 14026 |
+
#### Class template `basic_format_parse_context` <a id="format.parse.ctx">[[format.parse.ctx]]</a>
|
| 14027 |
+
|
| 14028 |
+
``` cpp
|
| 14029 |
+
namespace std {
|
| 14030 |
+
template<class charT>
|
| 14031 |
+
class basic_format_parse_context {
|
| 14032 |
+
public:
|
| 14033 |
+
using char_type = charT;
|
| 14034 |
+
using const_iterator = typename basic_string_view<charT>::const_iterator;
|
| 14035 |
+
using iterator = const_iterator;
|
| 14036 |
+
|
| 14037 |
+
private:
|
| 14038 |
+
iterator begin_; // exposition only
|
| 14039 |
+
iterator end_; // exposition only
|
| 14040 |
+
enum indexing { unknown, manual, automatic }; // exposition only
|
| 14041 |
+
indexing indexing_; // exposition only
|
| 14042 |
+
size_t next_arg_id_; // exposition only
|
| 14043 |
+
size_t num_args_; // exposition only
|
| 14044 |
+
|
| 14045 |
+
public:
|
| 14046 |
+
constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt,
|
| 14047 |
+
size_t num_args = 0) noexcept;
|
| 14048 |
+
basic_format_parse_context(const basic_format_parse_context&) = delete;
|
| 14049 |
+
basic_format_parse_context& operator=(const basic_format_parse_context&) = delete;
|
| 14050 |
+
|
| 14051 |
+
constexpr const_iterator begin() const noexcept;
|
| 14052 |
+
constexpr const_iterator end() const noexcept;
|
| 14053 |
+
constexpr void advance_to(const_iterator it);
|
| 14054 |
+
|
| 14055 |
+
constexpr size_t next_arg_id();
|
| 14056 |
+
constexpr void check_arg_id(size_t id);
|
| 14057 |
+
};
|
| 14058 |
+
}
|
| 14059 |
+
```
|
| 14060 |
+
|
| 14061 |
+
An instance of `basic_format_parse_context` holds the format string
|
| 14062 |
+
parsing state consisting of the format string range being parsed and the
|
| 14063 |
+
argument counter for automatic indexing.
|
| 14064 |
+
|
| 14065 |
+
``` cpp
|
| 14066 |
+
constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt,
|
| 14067 |
+
size_t num_args = 0) noexcept;
|
| 14068 |
+
```
|
| 14069 |
+
|
| 14070 |
+
*Effects:* Initializes `begin_` with `fmt.begin()`, `end_` with
|
| 14071 |
+
`fmt.end()`, `indexing_` with `unknown`, `next_arg_id_` with `0`, and
|
| 14072 |
+
`num_args_` with `num_args`.
|
| 14073 |
+
|
| 14074 |
+
``` cpp
|
| 14075 |
+
constexpr const_iterator begin() const noexcept;
|
| 14076 |
+
```
|
| 14077 |
+
|
| 14078 |
+
*Returns:* `begin_`.
|
| 14079 |
+
|
| 14080 |
+
``` cpp
|
| 14081 |
+
constexpr const_iterator end() const noexcept;
|
| 14082 |
+
```
|
| 14083 |
+
|
| 14084 |
+
*Returns:* `end_`.
|
| 14085 |
+
|
| 14086 |
+
``` cpp
|
| 14087 |
+
constexpr void advance_to(const_iterator it);
|
| 14088 |
+
```
|
| 14089 |
+
|
| 14090 |
+
*Preconditions:* `end()` is reachable from `it`.
|
| 14091 |
+
|
| 14092 |
+
*Effects:* Equivalent to: `begin_ = it;`
|
| 14093 |
+
|
| 14094 |
+
``` cpp
|
| 14095 |
+
constexpr size_t next_arg_id();
|
| 14096 |
+
```
|
| 14097 |
+
|
| 14098 |
+
*Effects:* If `indexing_ != manual`, equivalent to:
|
| 14099 |
+
|
| 14100 |
+
``` cpp
|
| 14101 |
+
if (indexing_ == unknown)
|
| 14102 |
+
indexing_ = automatic;
|
| 14103 |
+
return next_arg_id_++;
|
| 14104 |
+
```
|
| 14105 |
+
|
| 14106 |
+
*Throws:* `format_error` if `indexing_ == manual` which indicates mixing
|
| 14107 |
+
of automatic and manual argument indexing.
|
| 14108 |
+
|
| 14109 |
+
``` cpp
|
| 14110 |
+
constexpr void check_arg_id(size_t id);
|
| 14111 |
+
```
|
| 14112 |
+
|
| 14113 |
+
*Effects:* If `indexing_ != automatic`, equivalent to:
|
| 14114 |
+
|
| 14115 |
+
``` cpp
|
| 14116 |
+
if (indexing_ == unknown)
|
| 14117 |
+
indexing_ = manual;
|
| 14118 |
+
```
|
| 14119 |
+
|
| 14120 |
+
*Throws:* `format_error` if `indexing_ == automatic` which indicates
|
| 14121 |
+
mixing of automatic and manual argument indexing.
|
| 14122 |
+
|
| 14123 |
+
*Remarks:* Call expressions where `id >= num_args_` are not core
|
| 14124 |
+
constant expressions [[expr.const]].
|
| 14125 |
+
|
| 14126 |
+
#### Class template `basic_format_context` <a id="format.context">[[format.context]]</a>
|
| 14127 |
+
|
| 14128 |
+
``` cpp
|
| 14129 |
+
namespace std {
|
| 14130 |
+
template<class Out, class charT>
|
| 14131 |
+
class basic_format_context {
|
| 14132 |
+
basic_format_args<basic_format_context> args_; // exposition only
|
| 14133 |
+
Out out_; // exposition only
|
| 14134 |
+
|
| 14135 |
+
public:
|
| 14136 |
+
using iterator = Out;
|
| 14137 |
+
using char_type = charT;
|
| 14138 |
+
template<class T> using formatter_type = formatter<T, charT>;
|
| 14139 |
+
|
| 14140 |
+
basic_format_arg<basic_format_context> arg(size_t id) const;
|
| 14141 |
+
std::locale locale();
|
| 14142 |
+
|
| 14143 |
+
iterator out();
|
| 14144 |
+
void advance_to(iterator it);
|
| 14145 |
+
};
|
| 14146 |
+
}
|
| 14147 |
+
```
|
| 14148 |
+
|
| 14149 |
+
An instance of `basic_format_context` holds formatting state consisting
|
| 14150 |
+
of the formatting arguments and the output iterator.
|
| 14151 |
+
|
| 14152 |
+
`Out` shall model `output_iterator<const charT&>`.
|
| 14153 |
+
|
| 14154 |
+
`format_context` is an alias for a specialization of
|
| 14155 |
+
`basic_format_context` with an output iterator that appends to `string`,
|
| 14156 |
+
such as `back_insert_iterator<string>`. Similarly, `wformat_context` is
|
| 14157 |
+
an alias for a specialization of `basic_format_context` with an output
|
| 14158 |
+
iterator that appends to `wstring`.
|
| 14159 |
+
|
| 14160 |
+
[*Note 1*: For a given type `charT`, implementations are encouraged to
|
| 14161 |
+
provide a single instantiation of `basic_format_context` for appending
|
| 14162 |
+
to `basic_string<charT>`, `vector<charT>`, or any other container with
|
| 14163 |
+
contiguous storage by wrapping those in temporary objects with a uniform
|
| 14164 |
+
interface (such as a `span<charT>`) and polymorphic
|
| 14165 |
+
reallocation. — *end note*]
|
| 14166 |
+
|
| 14167 |
+
``` cpp
|
| 14168 |
+
basic_format_arg<basic_format_context> arg(size_t id) const;
|
| 14169 |
+
```
|
| 14170 |
+
|
| 14171 |
+
*Returns:* `args_.get(id)`.
|
| 14172 |
+
|
| 14173 |
+
``` cpp
|
| 14174 |
+
std::locale locale();
|
| 14175 |
+
```
|
| 14176 |
+
|
| 14177 |
+
*Returns:* The locale passed to the formatting function if the latter
|
| 14178 |
+
takes one, and `std::locale()` otherwise.
|
| 14179 |
+
|
| 14180 |
+
``` cpp
|
| 14181 |
+
iterator out();
|
| 14182 |
+
```
|
| 14183 |
+
|
| 14184 |
+
*Returns:* `out_`.
|
| 14185 |
+
|
| 14186 |
+
``` cpp
|
| 14187 |
+
void advance_to(iterator it);
|
| 14188 |
+
```
|
| 14189 |
+
|
| 14190 |
+
*Effects:* Equivalent to: `out_ = it;`
|
| 14191 |
+
|
| 14192 |
+
[*Example 1*:
|
| 14193 |
+
|
| 14194 |
+
``` cpp
|
| 14195 |
+
struct S { int value; };
|
| 14196 |
+
|
| 14197 |
+
template<> struct std::formatter<S> {
|
| 14198 |
+
size_t width_arg_id = 0;
|
| 14199 |
+
|
| 14200 |
+
// Parses a width argument id in the format { digit }.
|
| 14201 |
+
constexpr auto parse(format_parse_context& ctx) {
|
| 14202 |
+
auto iter = ctx.begin();
|
| 14203 |
+
auto get_char = [&]() { return iter != ctx.end() ? *iter : 0; };
|
| 14204 |
+
if (get_char() != '{')
|
| 14205 |
+
return iter;
|
| 14206 |
+
++iter;
|
| 14207 |
+
char c = get_char();
|
| 14208 |
+
if (!isdigit(c) || (++iter, get_char()) != '}')
|
| 14209 |
+
throw format_error("invalid format");
|
| 14210 |
+
width_arg_id = c - '0';
|
| 14211 |
+
ctx.check_arg_id(width_arg_id);
|
| 14212 |
+
return ++iter;
|
| 14213 |
+
}
|
| 14214 |
+
|
| 14215 |
+
// Formats an S with width given by the argument width_arg_id.
|
| 14216 |
+
auto format(S s, format_context& ctx) {
|
| 14217 |
+
int width = visit_format_arg([](auto value) -> int {
|
| 14218 |
+
if constexpr (!is_integral_v<decltype(value)>)
|
| 14219 |
+
throw format_error("width is not integral");
|
| 14220 |
+
else if (value < 0 || value > numeric_limits<int>::max())
|
| 14221 |
+
throw format_error("invalid width");
|
| 14222 |
+
else
|
| 14223 |
+
return value;
|
| 14224 |
+
}, ctx.arg(width_arg_id));
|
| 14225 |
+
return format_to(ctx.out(), "{0:x<{1}}", s.value, width);
|
| 14226 |
+
}
|
| 14227 |
+
};
|
| 14228 |
+
|
| 14229 |
+
std::string s = std::format("{0:{1}}", S{42}, 10); // value of s is "xxxxxxxx42"
|
| 14230 |
+
```
|
| 14231 |
+
|
| 14232 |
+
— *end example*]
|
| 14233 |
+
|
| 14234 |
+
### Arguments <a id="format.arguments">[[format.arguments]]</a>
|
| 14235 |
+
|
| 14236 |
+
#### Class template `basic_format_arg` <a id="format.arg">[[format.arg]]</a>
|
| 14237 |
+
|
| 14238 |
+
``` cpp
|
| 14239 |
+
namespace std {
|
| 14240 |
+
template<class Context>
|
| 14241 |
+
class basic_format_arg {
|
| 14242 |
+
public:
|
| 14243 |
+
class handle;
|
| 14244 |
+
|
| 14245 |
+
private:
|
| 14246 |
+
using char_type = typename Context::char_type; // exposition only
|
| 14247 |
+
|
| 14248 |
+
variant<monostate, bool, char_type,
|
| 14249 |
+
int, unsigned int, long long int, unsigned long long int,
|
| 14250 |
+
float, double, long double,
|
| 14251 |
+
const char_type*, basic_string_view<char_type>,
|
| 14252 |
+
const void*, handle> value; // exposition only
|
| 14253 |
+
|
| 14254 |
+
template<class T> explicit basic_format_arg(const T& v) noexcept; // exposition only
|
| 14255 |
+
explicit basic_format_arg(float n) noexcept; // exposition only
|
| 14256 |
+
explicit basic_format_arg(double n) noexcept; // exposition only
|
| 14257 |
+
explicit basic_format_arg(long double n) noexcept; // exposition only
|
| 14258 |
+
explicit basic_format_arg(const char_type* s); // exposition only
|
| 14259 |
+
|
| 14260 |
+
template<class traits>
|
| 14261 |
+
explicit basic_format_arg(
|
| 14262 |
+
basic_string_view<char_type, traits> s) noexcept; // exposition only
|
| 14263 |
+
|
| 14264 |
+
template<class traits, class Allocator>
|
| 14265 |
+
explicit basic_format_arg(
|
| 14266 |
+
const basic_string<char_type, traits, Allocator>& s) noexcept; // exposition only
|
| 14267 |
+
|
| 14268 |
+
explicit basic_format_arg(nullptr_t) noexcept; // exposition only
|
| 14269 |
+
|
| 14270 |
+
template<class T>
|
| 14271 |
+
explicit basic_format_arg(const T* p) noexcept; // exposition only
|
| 14272 |
+
|
| 14273 |
+
public:
|
| 14274 |
+
basic_format_arg() noexcept;
|
| 14275 |
+
|
| 14276 |
+
explicit operator bool() const noexcept;
|
| 14277 |
+
};
|
| 14278 |
+
}
|
| 14279 |
+
```
|
| 14280 |
+
|
| 14281 |
+
An instance of `basic_format_arg` provides access to a formatting
|
| 14282 |
+
argument for user-defined formatters.
|
| 14283 |
+
|
| 14284 |
+
The behavior of a program that adds specializations of
|
| 14285 |
+
`basic_format_arg` is undefined.
|
| 14286 |
+
|
| 14287 |
+
``` cpp
|
| 14288 |
+
basic_format_arg() noexcept;
|
| 14289 |
+
```
|
| 14290 |
+
|
| 14291 |
+
*Ensures:* `!(*this)`.
|
| 14292 |
+
|
| 14293 |
+
``` cpp
|
| 14294 |
+
template<class T> explicit basic_format_arg(const T& v) noexcept;
|
| 14295 |
+
```
|
| 14296 |
+
|
| 14297 |
+
*Constraints:* The template specialization
|
| 14298 |
+
|
| 14299 |
+
``` cpp
|
| 14300 |
+
typename Context::template formatter_type<T>
|
| 14301 |
+
```
|
| 14302 |
+
|
| 14303 |
+
meets the requirements [[formatter.requirements]]. The extent to which
|
| 14304 |
+
an implementation determines that the specialization meets the
|
| 14305 |
+
requirements is unspecified, except that as a minimum the expression
|
| 14306 |
+
|
| 14307 |
+
``` cpp
|
| 14308 |
+
typename Context::template formatter_type<T>()
|
| 14309 |
+
.format(declval<const T&>(), declval<Context&>())
|
| 14310 |
+
```
|
| 14311 |
+
|
| 14312 |
+
shall be well-formed when treated as an unevaluated operand.
|
| 14313 |
+
|
| 14314 |
+
*Effects:*
|
| 14315 |
+
|
| 14316 |
+
- if `T` is `bool` or `char_type`, initializes `value` with `v`;
|
| 14317 |
+
- otherwise, if `T` is `char` and `char_type` is `wchar_t`, initializes
|
| 14318 |
+
`value` with `static_cast<wchar_t>(v)`;
|
| 14319 |
+
- otherwise, if `T` is a signed integer type [[basic.fundamental]] and
|
| 14320 |
+
`sizeof(T) <= sizeof(int)`, initializes `value` with
|
| 14321 |
+
`static_cast<int>(v)`;
|
| 14322 |
+
- otherwise, if `T` is an unsigned integer type and
|
| 14323 |
+
`sizeof(T) <= sizeof(unsigned int)`, initializes `value` with
|
| 14324 |
+
`static_cast<unsigned int>(v)`;
|
| 14325 |
+
- otherwise, if `T` is a signed integer type and
|
| 14326 |
+
`sizeof(T) <= sizeof(long long int)`, initializes `value` with
|
| 14327 |
+
`static_cast<long long int>(v)`;
|
| 14328 |
+
- otherwise, if `T` is an unsigned integer type and
|
| 14329 |
+
`sizeof(T) <= sizeof(unsigned long long int)`, initializes `value`
|
| 14330 |
+
with `static_cast<unsigned long long int>(v)`;
|
| 14331 |
+
- otherwise, initializes `value` with `handle(v)`.
|
| 14332 |
+
|
| 14333 |
+
``` cpp
|
| 14334 |
+
explicit basic_format_arg(float n) noexcept;
|
| 14335 |
+
explicit basic_format_arg(double n) noexcept;
|
| 14336 |
+
explicit basic_format_arg(long double n) noexcept;
|
| 14337 |
+
```
|
| 14338 |
+
|
| 14339 |
+
*Effects:* Initializes `value` with `n`.
|
| 14340 |
+
|
| 14341 |
+
``` cpp
|
| 14342 |
+
explicit basic_format_arg(const char_type* s);
|
| 14343 |
+
```
|
| 14344 |
+
|
| 14345 |
+
*Preconditions:* `s` points to a NTCTS [[defns.ntcts]].
|
| 14346 |
+
|
| 14347 |
+
*Effects:* Initializes `value` with `s`.
|
| 14348 |
+
|
| 14349 |
+
``` cpp
|
| 14350 |
+
template<class traits>
|
| 14351 |
+
explicit basic_format_arg(basic_string_view<char_type, traits> s) noexcept;
|
| 14352 |
+
```
|
| 14353 |
+
|
| 14354 |
+
*Effects:* Initializes `value` with `s`.
|
| 14355 |
+
|
| 14356 |
+
``` cpp
|
| 14357 |
+
template<class traits, class Allocator>
|
| 14358 |
+
explicit basic_format_arg(
|
| 14359 |
+
const basic_string<char_type, traits, Allocator>& s) noexcept;
|
| 14360 |
+
```
|
| 14361 |
+
|
| 14362 |
+
*Effects:* Initializes `value` with
|
| 14363 |
+
`basic_string_view<char_type>(s.data(), s.size())`.
|
| 14364 |
+
|
| 14365 |
+
``` cpp
|
| 14366 |
+
explicit basic_format_arg(nullptr_t) noexcept;
|
| 14367 |
+
```
|
| 14368 |
+
|
| 14369 |
+
*Effects:* Initializes `value` with `static_cast<const void*>(nullptr)`.
|
| 14370 |
+
|
| 14371 |
+
``` cpp
|
| 14372 |
+
template<class T> explicit basic_format_arg(const T* p) noexcept;
|
| 14373 |
+
```
|
| 14374 |
+
|
| 14375 |
+
*Constraints:* `is_void_v<T>` is `true`.
|
| 14376 |
+
|
| 14377 |
+
*Effects:* Initializes `value` with `p`.
|
| 14378 |
+
|
| 14379 |
+
[*Note 1*: Constructing `basic_format_arg` from a pointer to a member
|
| 14380 |
+
is ill-formed unless the user provides an enabled specialization of
|
| 14381 |
+
`formatter` for that pointer to member type. — *end note*]
|
| 14382 |
+
|
| 14383 |
+
``` cpp
|
| 14384 |
+
explicit operator bool() const noexcept;
|
| 14385 |
+
```
|
| 14386 |
+
|
| 14387 |
+
*Returns:* `!holds_alternative<monostate>(value)`.
|
| 14388 |
+
|
| 14389 |
+
The class `handle` allows formatting an object of a user-defined type.
|
| 14390 |
+
|
| 14391 |
+
``` cpp
|
| 14392 |
+
namespace std {
|
| 14393 |
+
template<class Context>
|
| 14394 |
+
class basic_format_arg<Context>::handle {
|
| 14395 |
+
const void* ptr_; // exposition only
|
| 14396 |
+
void (*format_)(basic_format_parse_context<char_type>&,
|
| 14397 |
+
Context&, const void*); // exposition only
|
| 14398 |
+
|
| 14399 |
+
template<class T> explicit handle(const T& val) noexcept; // exposition only
|
| 14400 |
+
|
| 14401 |
+
friend class basic_format_arg<Context>; // exposition only
|
| 14402 |
+
|
| 14403 |
+
public:
|
| 14404 |
+
void format(basic_format_parse_context<char_type>&, Context& ctx) const;
|
| 14405 |
+
};
|
| 14406 |
+
}
|
| 14407 |
+
```
|
| 14408 |
+
|
| 14409 |
+
``` cpp
|
| 14410 |
+
template<class T> explicit handle(const T& val) noexcept;
|
| 14411 |
+
```
|
| 14412 |
+
|
| 14413 |
+
*Effects:* Initializes `ptr_` with `addressof(val)` and `format_` with
|
| 14414 |
+
|
| 14415 |
+
``` cpp
|
| 14416 |
+
[](basic_format_parse_context<char_type>& parse_ctx,
|
| 14417 |
+
Context& format_ctx, const void* ptr) {
|
| 14418 |
+
typename Context::template formatter_type<T> f;
|
| 14419 |
+
parse_ctx.advance_to(f.parse(parse_ctx));
|
| 14420 |
+
format_ctx.advance_to(f.format(*static_cast<const T*>(ptr), format_ctx));
|
| 14421 |
+
}
|
| 14422 |
+
```
|
| 14423 |
+
|
| 14424 |
+
``` cpp
|
| 14425 |
+
void format(basic_format_parse_context<char_type>& parse_ctx, Context& format_ctx) const;
|
| 14426 |
+
```
|
| 14427 |
+
|
| 14428 |
+
*Effects:* Equivalent to: `format_(parse_ctx, format_ctx, ptr_);`
|
| 14429 |
+
|
| 14430 |
+
``` cpp
|
| 14431 |
+
template<class Visitor, class Context>
|
| 14432 |
+
see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
|
| 14433 |
+
```
|
| 14434 |
+
|
| 14435 |
+
*Effects:* Equivalent to:
|
| 14436 |
+
`return visit(forward<Visitor>(vis), arg.value);`
|
| 14437 |
+
|
| 14438 |
+
#### Class template *`format-arg-store`* <a id="format.arg.store">[[format.arg.store]]</a>
|
| 14439 |
+
|
| 14440 |
+
``` cpp
|
| 14441 |
+
namespace std {
|
| 14442 |
+
template<class Context, class... Args>
|
| 14443 |
+
struct format-arg-store { // exposition only
|
| 14444 |
+
array<basic_format_arg<Context>, sizeof...(Args)> args;
|
| 14445 |
+
};
|
| 14446 |
+
}
|
| 14447 |
+
```
|
| 14448 |
+
|
| 14449 |
+
An instance of *`format-arg-store`* stores formatting arguments.
|
| 14450 |
+
|
| 14451 |
+
``` cpp
|
| 14452 |
+
template<class Context = format_context, class... Args>
|
| 14453 |
+
format-arg-store<Context, Args...> make_format_args(const Args&... args);
|
| 14454 |
+
```
|
| 14455 |
+
|
| 14456 |
+
*Preconditions:* The type
|
| 14457 |
+
`typename Context::template formatter_type<``Tᵢ``>` meets the
|
| 14458 |
+
requirements [[formatter.requirements]] for each `Tᵢ` in `Args`.
|
| 14459 |
+
|
| 14460 |
+
*Returns:* `{basic_format_arg<Context>(args)...}`.
|
| 14461 |
+
|
| 14462 |
+
``` cpp
|
| 14463 |
+
template<class... Args>
|
| 14464 |
+
format-arg-store<wformat_context, Args...> make_wformat_args(const Args&... args);
|
| 14465 |
+
```
|
| 14466 |
+
|
| 14467 |
+
*Effects:* Equivalent to:
|
| 14468 |
+
`return make_format_args<wformat_context>(args...);`
|
| 14469 |
+
|
| 14470 |
+
#### Class template `basic_format_args` <a id="format.args">[[format.args]]</a>
|
| 14471 |
+
|
| 14472 |
+
``` cpp
|
| 14473 |
+
namespace std {
|
| 14474 |
+
template<class Context>
|
| 14475 |
+
class basic_format_args {
|
| 14476 |
+
size_t size_; // exposition only
|
| 14477 |
+
const basic_format_arg<Context>* data_; // exposition only
|
| 14478 |
+
|
| 14479 |
+
public:
|
| 14480 |
+
basic_format_args() noexcept;
|
| 14481 |
+
|
| 14482 |
+
template<class... Args>
|
| 14483 |
+
basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
|
| 14484 |
+
|
| 14485 |
+
basic_format_arg<Context> get(size_t i) const noexcept;
|
| 14486 |
+
};
|
| 14487 |
+
}
|
| 14488 |
+
```
|
| 14489 |
+
|
| 14490 |
+
An instance of `basic_format_args` provides access to formatting
|
| 14491 |
+
arguments.
|
| 14492 |
+
|
| 14493 |
+
``` cpp
|
| 14494 |
+
basic_format_args() noexcept;
|
| 14495 |
+
```
|
| 14496 |
+
|
| 14497 |
+
*Effects:* Initializes `size_` with `0`.
|
| 14498 |
+
|
| 14499 |
+
``` cpp
|
| 14500 |
+
template<class... Args>
|
| 14501 |
+
basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
|
| 14502 |
+
```
|
| 14503 |
+
|
| 14504 |
+
*Effects:* Initializes `size_` with `sizeof...(Args)` and `data_` with
|
| 14505 |
+
`store.args.data()`.
|
| 14506 |
+
|
| 14507 |
+
``` cpp
|
| 14508 |
+
basic_format_arg<Context> get(size_t i) const noexcept;
|
| 14509 |
+
```
|
| 14510 |
+
|
| 14511 |
+
*Returns:* `i < size_ ? data_[i] : basic_format_arg<Context>()`.
|
| 14512 |
+
|
| 14513 |
+
[*Note 1*: Implementations are encouraged to optimize the
|
| 14514 |
+
representation of `basic_format_args` for small number of formatting
|
| 14515 |
+
arguments by storing indices of type alternatives separately from values
|
| 14516 |
+
and packing the former. — *end note*]
|
| 14517 |
+
|
| 14518 |
+
### Class `format_error` <a id="format.error">[[format.error]]</a>
|
| 14519 |
+
|
| 14520 |
+
``` cpp
|
| 14521 |
+
namespace std {
|
| 14522 |
+
class format_error : public runtime_error {
|
| 14523 |
+
public:
|
| 14524 |
+
explicit format_error(const string& what_arg);
|
| 14525 |
+
explicit format_error(const char* what_arg);
|
| 14526 |
+
};
|
| 14527 |
+
}
|
| 14528 |
+
```
|
| 14529 |
+
|
| 14530 |
+
The class `format_error` defines the type of objects thrown as
|
| 14531 |
+
exceptions to report errors from the formatting library.
|
| 14532 |
+
|
| 14533 |
+
``` cpp
|
| 14534 |
+
format_error(const string& what_arg);
|
| 14535 |
+
```
|
| 14536 |
+
|
| 14537 |
+
*Ensures:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 14538 |
+
|
| 14539 |
+
``` cpp
|
| 14540 |
+
format_error(const char* what_arg);
|
| 14541 |
+
```
|
| 14542 |
+
|
| 14543 |
+
*Ensures:* `strcmp(what(), what_arg) == 0`.
|
| 14544 |
+
|
| 14545 |
<!-- Link reference definitions -->
|
| 14546 |
[alg.sorting]: algorithms.md#alg.sorting
|
| 14547 |
[algorithms]: algorithms.md#algorithms
|
| 14548 |
[algorithms.general]: algorithms.md#algorithms.general
|
| 14549 |
+
[algorithms.requirements]: algorithms.md#algorithms.requirements
|
| 14550 |
[allocator.adaptor]: #allocator.adaptor
|
| 14551 |
[allocator.adaptor.cnstr]: #allocator.adaptor.cnstr
|
| 14552 |
[allocator.adaptor.members]: #allocator.adaptor.members
|
| 14553 |
[allocator.adaptor.syn]: #allocator.adaptor.syn
|
| 14554 |
[allocator.adaptor.types]: #allocator.adaptor.types
|
| 14555 |
[allocator.globals]: #allocator.globals
|
| 14556 |
[allocator.members]: #allocator.members
|
|
|
|
| 14557 |
[allocator.requirements.completeness]: library.md#allocator.requirements.completeness
|
| 14558 |
[allocator.tag]: #allocator.tag
|
| 14559 |
[allocator.traits]: #allocator.traits
|
| 14560 |
[allocator.traits.members]: #allocator.traits.members
|
| 14561 |
[allocator.traits.types]: #allocator.traits.types
|
| 14562 |
[allocator.uses]: #allocator.uses
|
| 14563 |
[allocator.uses.construction]: #allocator.uses.construction
|
| 14564 |
[allocator.uses.trait]: #allocator.uses.trait
|
| 14565 |
[any]: #any
|
| 14566 |
[any.assign]: #any.assign
|
| 14567 |
+
[any.bad.any.cast]: #any.bad.any.cast
|
| 14568 |
[any.class]: #any.class
|
| 14569 |
[any.cons]: #any.cons
|
| 14570 |
[any.modifiers]: #any.modifiers
|
| 14571 |
[any.nonmembers]: #any.nonmembers
|
| 14572 |
[any.observers]: #any.observers
|
|
|
|
| 14578 |
[arithmetic.operations.multiplies]: #arithmetic.operations.multiplies
|
| 14579 |
[arithmetic.operations.negate]: #arithmetic.operations.negate
|
| 14580 |
[arithmetic.operations.plus]: #arithmetic.operations.plus
|
| 14581 |
[array]: containers.md#array
|
| 14582 |
[associative]: containers.md#associative
|
|
|
|
|
|
|
| 14583 |
[basic.align]: basic.md#basic.align
|
| 14584 |
[basic.compound]: basic.md#basic.compound
|
| 14585 |
[basic.def.odr]: basic.md#basic.def.odr
|
| 14586 |
[basic.fundamental]: basic.md#basic.fundamental
|
| 14587 |
[basic.life]: basic.md#basic.life
|
| 14588 |
+
[basic.stc.dynamic.allocation]: basic.md#basic.stc.dynamic.allocation
|
| 14589 |
[basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
|
| 14590 |
[basic.types]: basic.md#basic.types
|
| 14591 |
[bitmask.types]: library.md#bitmask.types
|
| 14592 |
[bitset]: #bitset
|
| 14593 |
[bitset.cons]: #bitset.cons
|
|
|
|
| 14599 |
[bitwise.operations.and]: #bitwise.operations.and
|
| 14600 |
[bitwise.operations.not]: #bitwise.operations.not
|
| 14601 |
[bitwise.operations.or]: #bitwise.operations.or
|
| 14602 |
[bitwise.operations.xor]: #bitwise.operations.xor
|
| 14603 |
[c.malloc]: #c.malloc
|
| 14604 |
+
[charconv]: #charconv
|
| 14605 |
+
[charconv.from.chars]: #charconv.from.chars
|
| 14606 |
+
[charconv.syn]: #charconv.syn
|
| 14607 |
+
[charconv.to.chars]: #charconv.to.chars
|
| 14608 |
+
[class.copy.ctor]: class.md#class.copy.ctor
|
| 14609 |
+
[class.mem]: class.md#class.mem
|
| 14610 |
[comparisons]: #comparisons
|
| 14611 |
+
[comparisons.equal.to]: #comparisons.equal.to
|
| 14612 |
[comparisons.greater]: #comparisons.greater
|
| 14613 |
+
[comparisons.greater.equal]: #comparisons.greater.equal
|
| 14614 |
[comparisons.less]: #comparisons.less
|
| 14615 |
+
[comparisons.less.equal]: #comparisons.less.equal
|
| 14616 |
+
[comparisons.not.equal.to]: #comparisons.not.equal.to
|
| 14617 |
+
[comparisons.three.way]: #comparisons.three.way
|
| 14618 |
+
[concepts.equality]: concepts.md#concepts.equality
|
| 14619 |
+
[conv.array]: expr.md#conv.array
|
| 14620 |
+
[conv.func]: expr.md#conv.func
|
| 14621 |
+
[conv.lval]: expr.md#conv.lval
|
| 14622 |
+
[conv.qual]: expr.md#conv.qual
|
| 14623 |
+
[conv.rank]: basic.md#conv.rank
|
| 14624 |
+
[cpp17.allocator]: #cpp17.allocator
|
| 14625 |
+
[cpp17.copyassignable]: #cpp17.copyassignable
|
| 14626 |
+
[cpp17.copyconstructible]: #cpp17.copyconstructible
|
| 14627 |
+
[cpp17.defaultconstructible]: #cpp17.defaultconstructible
|
| 14628 |
+
[cpp17.destructible]: #cpp17.destructible
|
| 14629 |
+
[cpp17.hash]: #cpp17.hash
|
| 14630 |
+
[cpp17.moveassignable]: #cpp17.moveassignable
|
| 14631 |
+
[cpp17.moveconstructible]: #cpp17.moveconstructible
|
| 14632 |
+
[cpp17.nullablepointer]: #cpp17.nullablepointer
|
| 14633 |
[dcl.array]: dcl.md#dcl.array
|
| 14634 |
[dcl.constexpr]: dcl.md#dcl.constexpr
|
| 14635 |
[dcl.ref]: dcl.md#dcl.ref
|
| 14636 |
[declval]: #declval
|
| 14637 |
[default.allocator]: #default.allocator
|
| 14638 |
[defns.const.subexpr]: library.md#defns.const.subexpr
|
| 14639 |
+
[defns.expression-equivalent]: library.md#defns.expression-equivalent
|
| 14640 |
+
[defns.ntcts]: library.md#defns.ntcts
|
| 14641 |
+
[defns.order.ptr]: #defns.order.ptr
|
| 14642 |
[defns.referenceable]: library.md#defns.referenceable
|
| 14643 |
[execpol]: #execpol
|
| 14644 |
[execpol.general]: #execpol.general
|
| 14645 |
[execpol.objects]: #execpol.objects
|
| 14646 |
[execpol.par]: #execpol.par
|
| 14647 |
[execpol.parunseq]: #execpol.parunseq
|
| 14648 |
[execpol.seq]: #execpol.seq
|
| 14649 |
[execpol.type]: #execpol.type
|
| 14650 |
+
[execpol.unseq]: #execpol.unseq
|
| 14651 |
[execution.syn]: #execution.syn
|
|
|
|
| 14652 |
[expr.add]: expr.md#expr.add
|
| 14653 |
[expr.alignof]: expr.md#expr.alignof
|
| 14654 |
[expr.bit.and]: expr.md#expr.bit.and
|
| 14655 |
[expr.call]: expr.md#expr.call
|
| 14656 |
+
[expr.const]: expr.md#expr.const
|
| 14657 |
[expr.eq]: expr.md#expr.eq
|
| 14658 |
[expr.log.and]: expr.md#expr.log.and
|
| 14659 |
[expr.log.or]: expr.md#expr.log.or
|
| 14660 |
[expr.mul]: expr.md#expr.mul
|
| 14661 |
[expr.or]: expr.md#expr.or
|
| 14662 |
+
[expr.prop]: expr.md#expr.prop
|
| 14663 |
[expr.rel]: expr.md#expr.rel
|
| 14664 |
[expr.unary.op]: expr.md#expr.unary.op
|
| 14665 |
[expr.xor]: expr.md#expr.xor
|
| 14666 |
+
[format]: #format
|
| 14667 |
+
[format.align]: #format.align
|
| 14668 |
+
[format.arg]: #format.arg
|
| 14669 |
+
[format.arg.store]: #format.arg.store
|
| 14670 |
+
[format.args]: #format.args
|
| 14671 |
+
[format.arguments]: #format.arguments
|
| 14672 |
+
[format.context]: #format.context
|
| 14673 |
+
[format.err.report]: #format.err.report
|
| 14674 |
+
[format.error]: #format.error
|
| 14675 |
+
[format.formatter]: #format.formatter
|
| 14676 |
+
[format.formatter.spec]: #format.formatter.spec
|
| 14677 |
+
[format.functions]: #format.functions
|
| 14678 |
+
[format.parse.ctx]: #format.parse.ctx
|
| 14679 |
+
[format.sign]: #format.sign
|
| 14680 |
+
[format.string]: #format.string
|
| 14681 |
+
[format.string.general]: #format.string.general
|
| 14682 |
+
[format.string.std]: #format.string.std
|
| 14683 |
+
[format.syn]: #format.syn
|
| 14684 |
+
[format.type.bool]: #format.type.bool
|
| 14685 |
+
[format.type.char]: #format.type.char
|
| 14686 |
+
[format.type.float]: #format.type.float
|
| 14687 |
+
[format.type.int]: #format.type.int
|
| 14688 |
+
[format.type.ptr]: #format.type.ptr
|
| 14689 |
+
[format.type.string]: #format.type.string
|
| 14690 |
+
[formatter]: #formatter
|
| 14691 |
+
[formatter.requirements]: #formatter.requirements
|
| 14692 |
[forward]: #forward
|
|
|
|
| 14693 |
[func.bind]: #func.bind
|
| 14694 |
[func.bind.bind]: #func.bind.bind
|
| 14695 |
+
[func.bind.front]: #func.bind.front
|
| 14696 |
[func.bind.isbind]: #func.bind.isbind
|
| 14697 |
[func.bind.isplace]: #func.bind.isplace
|
| 14698 |
[func.bind.place]: #func.bind.place
|
| 14699 |
[func.def]: #func.def
|
| 14700 |
+
[func.identity]: #func.identity
|
| 14701 |
[func.invoke]: #func.invoke
|
| 14702 |
[func.memfn]: #func.memfn
|
| 14703 |
+
[func.not.fn]: #func.not.fn
|
| 14704 |
[func.require]: #func.require
|
| 14705 |
[func.search]: #func.search
|
| 14706 |
[func.search.bm]: #func.search.bm
|
| 14707 |
[func.search.bmh]: #func.search.bmh
|
| 14708 |
[func.search.default]: #func.search.default
|
| 14709 |
[func.wrap]: #func.wrap
|
| 14710 |
[func.wrap.badcall]: #func.wrap.badcall
|
|
|
|
| 14711 |
[func.wrap.func]: #func.wrap.func
|
| 14712 |
[func.wrap.func.alg]: #func.wrap.func.alg
|
| 14713 |
[func.wrap.func.cap]: #func.wrap.func.cap
|
| 14714 |
[func.wrap.func.con]: #func.wrap.func.con
|
| 14715 |
[func.wrap.func.inv]: #func.wrap.func.inv
|
| 14716 |
[func.wrap.func.mod]: #func.wrap.func.mod
|
| 14717 |
[func.wrap.func.nullptr]: #func.wrap.func.nullptr
|
| 14718 |
[func.wrap.func.targ]: #func.wrap.func.targ
|
| 14719 |
[function.objects]: #function.objects
|
| 14720 |
[functional.syn]: #functional.syn
|
| 14721 |
+
[intro.multithread]: basic.md#intro.multithread
|
| 14722 |
+
[intro.object]: basic.md#intro.object
|
|
|
|
| 14723 |
[intseq]: #intseq
|
| 14724 |
[intseq.general]: #intseq.general
|
| 14725 |
[intseq.intseq]: #intseq.intseq
|
| 14726 |
[intseq.make]: #intseq.make
|
| 14727 |
[invalid.argument]: diagnostics.md#invalid.argument
|
| 14728 |
[iostate.flags]: input.md#iostate.flags
|
| 14729 |
[istream.formatted]: input.md#istream.formatted
|
|
|
|
| 14730 |
[logical.operations]: #logical.operations
|
| 14731 |
[logical.operations.and]: #logical.operations.and
|
| 14732 |
[logical.operations.not]: #logical.operations.not
|
| 14733 |
[logical.operations.or]: #logical.operations.or
|
| 14734 |
[mem.poly.allocator.class]: #mem.poly.allocator.class
|
|
|
|
| 14752 |
[mem.res.syn]: #mem.res.syn
|
| 14753 |
[memory]: #memory
|
| 14754 |
[memory.general]: #memory.general
|
| 14755 |
[memory.syn]: #memory.syn
|
| 14756 |
[meta]: #meta
|
| 14757 |
+
[meta.const.eval]: #meta.const.eval
|
| 14758 |
[meta.help]: #meta.help
|
| 14759 |
[meta.logical]: #meta.logical
|
| 14760 |
+
[meta.member]: #meta.member
|
| 14761 |
[meta.rel]: #meta.rel
|
| 14762 |
[meta.rqmts]: #meta.rqmts
|
| 14763 |
[meta.trans]: #meta.trans
|
| 14764 |
[meta.trans.arr]: #meta.trans.arr
|
| 14765 |
[meta.trans.cv]: #meta.trans.cv
|
|
|
|
| 14771 |
[meta.unary]: #meta.unary
|
| 14772 |
[meta.unary.cat]: #meta.unary.cat
|
| 14773 |
[meta.unary.comp]: #meta.unary.comp
|
| 14774 |
[meta.unary.prop]: #meta.unary.prop
|
| 14775 |
[meta.unary.prop.query]: #meta.unary.prop.query
|
|
|
|
| 14776 |
[namespace.std]: library.md#namespace.std
|
| 14777 |
+
[new.delete]: support.md#new.delete
|
|
|
|
|
|
|
|
|
|
| 14778 |
[optional]: #optional
|
| 14779 |
[optional.assign]: #optional.assign
|
| 14780 |
+
[optional.assign.copy]: #optional.assign.copy
|
| 14781 |
+
[optional.assign.copy.templ]: #optional.assign.copy.templ
|
| 14782 |
+
[optional.assign.move]: #optional.assign.move
|
| 14783 |
+
[optional.assign.move.templ]: #optional.assign.move.templ
|
| 14784 |
[optional.bad.access]: #optional.bad.access
|
| 14785 |
+
[optional.comp.with.t]: #optional.comp.with.t
|
| 14786 |
[optional.ctor]: #optional.ctor
|
| 14787 |
[optional.dtor]: #optional.dtor
|
| 14788 |
[optional.general]: #optional.general
|
| 14789 |
[optional.hash]: #optional.hash
|
| 14790 |
[optional.mod]: #optional.mod
|
|
|
|
| 14805 |
[pair.piecewise]: #pair.piecewise
|
| 14806 |
[pairs]: #pairs
|
| 14807 |
[pairs.general]: #pairs.general
|
| 14808 |
[pairs.pair]: #pairs.pair
|
| 14809 |
[pairs.spec]: #pairs.spec
|
| 14810 |
+
[pointer.conversion]: #pointer.conversion
|
| 14811 |
[pointer.traits]: #pointer.traits
|
| 14812 |
[pointer.traits.functions]: #pointer.traits.functions
|
| 14813 |
+
[pointer.traits.optmem]: #pointer.traits.optmem
|
| 14814 |
[pointer.traits.types]: #pointer.traits.types
|
| 14815 |
[ptr.align]: #ptr.align
|
| 14816 |
+
[range.cmp]: #range.cmp
|
| 14817 |
[ratio]: #ratio
|
| 14818 |
[ratio.arithmetic]: #ratio.arithmetic
|
| 14819 |
[ratio.comparison]: #ratio.comparison
|
| 14820 |
[ratio.general]: #ratio.general
|
| 14821 |
[ratio.ratio]: #ratio.ratio
|
|
|
|
| 14825 |
[refwrap.access]: #refwrap.access
|
| 14826 |
[refwrap.assign]: #refwrap.assign
|
| 14827 |
[refwrap.const]: #refwrap.const
|
| 14828 |
[refwrap.helpers]: #refwrap.helpers
|
| 14829 |
[refwrap.invoke]: #refwrap.invoke
|
| 14830 |
+
[res.on.exception.handling]: library.md#res.on.exception.handling
|
| 14831 |
+
[round.style]: support.md#round.style
|
| 14832 |
[scoped.adaptor.operators]: #scoped.adaptor.operators
|
| 14833 |
[smartptr]: #smartptr
|
| 14834 |
+
[special]: class.md#special
|
| 14835 |
[specialized.addressof]: #specialized.addressof
|
| 14836 |
+
[specialized.algorithms]: algorithms.md#specialized.algorithms
|
|
|
|
| 14837 |
[stmt.dcl]: stmt.md#stmt.dcl
|
| 14838 |
+
[stmt.return]: stmt.md#stmt.return
|
| 14839 |
+
[support.signal]: support.md#support.signal
|
| 14840 |
[swappable.requirements]: library.md#swappable.requirements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14841 |
[temp.deduct]: temp.md#temp.deduct
|
| 14842 |
+
[temp.param]: temp.md#temp.param
|
| 14843 |
+
[temp.type]: temp.md#temp.type
|
| 14844 |
[template.bitset]: #template.bitset
|
| 14845 |
+
[time.format]: time.md#time.format
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14846 |
[tuple]: #tuple
|
| 14847 |
[tuple.apply]: #tuple.apply
|
| 14848 |
[tuple.assign]: #tuple.assign
|
| 14849 |
[tuple.cnstr]: #tuple.cnstr
|
| 14850 |
[tuple.creation]: #tuple.creation
|
|
|
|
| 14860 |
[type.index]: #type.index
|
| 14861 |
[type.index.hash]: #type.index.hash
|
| 14862 |
[type.index.members]: #type.index.members
|
| 14863 |
[type.index.overview]: #type.index.overview
|
| 14864 |
[type.index.synopsis]: #type.index.synopsis
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14865 |
[unique.ptr]: #unique.ptr
|
| 14866 |
[unique.ptr.create]: #unique.ptr.create
|
| 14867 |
[unique.ptr.dltr]: #unique.ptr.dltr
|
| 14868 |
[unique.ptr.dltr.dflt]: #unique.ptr.dltr.dflt
|
| 14869 |
[unique.ptr.dltr.dflt1]: #unique.ptr.dltr.dflt1
|
| 14870 |
[unique.ptr.dltr.general]: #unique.ptr.dltr.general
|
| 14871 |
+
[unique.ptr.io]: #unique.ptr.io
|
| 14872 |
[unique.ptr.runtime]: #unique.ptr.runtime
|
| 14873 |
[unique.ptr.runtime.asgn]: #unique.ptr.runtime.asgn
|
| 14874 |
[unique.ptr.runtime.ctor]: #unique.ptr.runtime.ctor
|
| 14875 |
[unique.ptr.runtime.modifiers]: #unique.ptr.runtime.modifiers
|
| 14876 |
[unique.ptr.runtime.observers]: #unique.ptr.runtime.observers
|
|
|
|
| 14882 |
[unique.ptr.single.observers]: #unique.ptr.single.observers
|
| 14883 |
[unique.ptr.special]: #unique.ptr.special
|
| 14884 |
[unord]: containers.md#unord
|
| 14885 |
[unord.hash]: #unord.hash
|
| 14886 |
[util.dynamic.safety]: #util.dynamic.safety
|
|
|
|
| 14887 |
[util.smartptr.enab]: #util.smartptr.enab
|
| 14888 |
[util.smartptr.getdeleter]: #util.smartptr.getdeleter
|
| 14889 |
[util.smartptr.hash]: #util.smartptr.hash
|
| 14890 |
[util.smartptr.ownerless]: #util.smartptr.ownerless
|
| 14891 |
[util.smartptr.shared]: #util.smartptr.shared
|
| 14892 |
[util.smartptr.shared.assign]: #util.smartptr.shared.assign
|
|
|
|
| 14893 |
[util.smartptr.shared.cast]: #util.smartptr.shared.cast
|
| 14894 |
[util.smartptr.shared.cmp]: #util.smartptr.shared.cmp
|
| 14895 |
[util.smartptr.shared.const]: #util.smartptr.shared.const
|
| 14896 |
[util.smartptr.shared.create]: #util.smartptr.shared.create
|
| 14897 |
[util.smartptr.shared.dest]: #util.smartptr.shared.dest
|
|
|
|
| 14907 |
[util.smartptr.weak.mod]: #util.smartptr.weak.mod
|
| 14908 |
[util.smartptr.weak.obs]: #util.smartptr.weak.obs
|
| 14909 |
[util.smartptr.weak.spec]: #util.smartptr.weak.spec
|
| 14910 |
[utilities]: #utilities
|
| 14911 |
[utilities.general]: #utilities.general
|
| 14912 |
+
[utilities.summary]: #utilities.summary
|
| 14913 |
[utility]: #utility
|
| 14914 |
+
[utility.as.const]: #utility.as.const
|
| 14915 |
[utility.exchange]: #utility.exchange
|
| 14916 |
+
[utility.intcmp]: #utility.intcmp
|
| 14917 |
[utility.swap]: #utility.swap
|
| 14918 |
[utility.syn]: #utility.syn
|
|
|
|
| 14919 |
[variant]: #variant
|
| 14920 |
[variant.assign]: #variant.assign
|
| 14921 |
[variant.bad.access]: #variant.bad.access
|
| 14922 |
[variant.ctor]: #variant.ctor
|
| 14923 |
[variant.dtor]: #variant.dtor
|
|
|
|
| 14931 |
[variant.relops]: #variant.relops
|
| 14932 |
[variant.specalg]: #variant.specalg
|
| 14933 |
[variant.status]: #variant.status
|
| 14934 |
[variant.swap]: #variant.swap
|
| 14935 |
[variant.syn]: #variant.syn
|
|
|
|
| 14936 |
[variant.variant]: #variant.variant
|
| 14937 |
[variant.visit]: #variant.visit
|
| 14938 |
|
| 14939 |
[^1]: `pointer_safety::preferred` might be returned to indicate that a
|
| 14940 |
leak detector is running so that the program can avoid spurious leak
|
| 14941 |
reports.
|
| 14942 |
|
| 14943 |
[^2]: Such a type is a function pointer or a class type which has a
|
| 14944 |
member `operator()` or a class type which has a conversion to a
|
| 14945 |
pointer to function.
|
|
|
|
|
|
|
|
|
|
|
|