- tmp/tmph31zx98l/{from.md → to.md} +133 -294
tmp/tmph31zx98l/{from.md → to.md}
RENAMED
|
@@ -1,33 +1,26 @@
|
|
| 1 |
## Utility components <a id="utility">[[utility]]</a>
|
| 2 |
|
| 3 |
-
This subclause contains some basic function and class templates that are
|
| 4 |
-
used throughout the rest of the library.
|
| 5 |
-
|
| 6 |
### Header `<utility>` synopsis <a id="utility.syn">[[utility.syn]]</a>
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
``` cpp
|
| 9 |
-
#include <
|
|
|
|
| 10 |
|
| 11 |
namespace std {
|
| 12 |
-
// [operators], operators
|
| 13 |
-
namespace rel_ops {
|
| 14 |
-
template<class T> bool operator!=(const T&, const T&);
|
| 15 |
-
template<class T> bool operator> (const T&, const T&);
|
| 16 |
-
template<class T> bool operator<=(const T&, const T&);
|
| 17 |
-
template<class T> bool operator>=(const T&, const T&);
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
// [utility.swap], swap
|
| 21 |
template<class T>
|
| 22 |
-
void swap(T& a, T& b) noexcept(see below);
|
| 23 |
template<class T, size_t N>
|
| 24 |
-
void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v<T>);
|
| 25 |
|
| 26 |
// [utility.exchange], exchange
|
| 27 |
template<class T, class U = T>
|
| 28 |
-
T exchange(T& obj, U&& new_val);
|
| 29 |
|
| 30 |
// [forward], forward/move
|
| 31 |
template<class T>
|
| 32 |
constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 33 |
template<class T>
|
|
@@ -37,22 +30,42 @@ namespace std {
|
|
| 37 |
template<class T>
|
| 38 |
constexpr conditional_t<
|
| 39 |
!is_nothrow_move_constructible_v<T> && is_copy_constructible_v<T>, const T&, T&&>
|
| 40 |
move_if_noexcept(T& x) noexcept;
|
| 41 |
|
| 42 |
-
// [utility.
|
| 43 |
template<class T>
|
| 44 |
constexpr add_const_t<T>& as_const(T& t) noexcept;
|
| 45 |
template<class T>
|
| 46 |
void as_const(const T&&) = delete;
|
| 47 |
|
| 48 |
// [declval], declval
|
| 49 |
template<class T>
|
| 50 |
add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
%
|
| 52 |
|
| 53 |
-
// [intseq], Compile-time integer sequences
|
| 54 |
template<class T, T...>
|
| 55 |
struct integer_sequence;
|
| 56 |
template<size_t... I>
|
| 57 |
using index_sequence = integer_sequence<size_t, I...>;
|
| 58 |
|
|
@@ -70,33 +83,26 @@ namespace std {
|
|
| 70 |
|
| 71 |
// [pairs.spec], pair specialized algorithms
|
| 72 |
template<class T1, class T2>
|
| 73 |
constexpr bool operator==(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 74 |
template<class T1, class T2>
|
| 75 |
-
constexpr
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
template <class T1, class T2>
|
| 79 |
-
constexpr bool operator> (const pair<T1, T2>&, const pair<T1, T2>&);
|
| 80 |
-
template <class T1, class T2>
|
| 81 |
-
constexpr bool operator>=(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 82 |
-
template <class T1, class T2>
|
| 83 |
-
constexpr bool operator<=(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 84 |
|
| 85 |
template<class T1, class T2>
|
| 86 |
-
void swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
|
| 87 |
|
| 88 |
template<class T1, class T2>
|
| 89 |
constexpr see below make_pair(T1&&, T2&&);
|
| 90 |
|
| 91 |
// [pair.astuple], tuple-like access to pair
|
| 92 |
-
template
|
| 93 |
-
template
|
| 94 |
|
| 95 |
template<class T1, class T2> struct tuple_size<pair<T1, T2>>;
|
| 96 |
-
template
|
| 97 |
-
template <class T1, class T2> struct tuple_element<1, pair<T1, T2>>;
|
| 98 |
|
| 99 |
template<size_t I, class T1, class T2>
|
| 100 |
constexpr tuple_element_t<I, pair<T1, T2>>& get(pair<T1, T2>&) noexcept;
|
| 101 |
template<size_t I, class T1, class T2>
|
| 102 |
constexpr tuple_element_t<I, pair<T1, T2>>&& get(pair<T1, T2>&&) noexcept;
|
|
@@ -124,178 +130,79 @@ namespace std {
|
|
| 124 |
// [pair.piecewise], pair piecewise construction
|
| 125 |
struct piecewise_construct_t {
|
| 126 |
explicit piecewise_construct_t() = default;
|
| 127 |
};
|
| 128 |
inline constexpr piecewise_construct_t piecewise_construct{};
|
| 129 |
-
template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
-
// in-place construction
|
| 132 |
struct in_place_t {
|
| 133 |
explicit in_place_t() = default;
|
| 134 |
};
|
| 135 |
inline constexpr in_place_t in_place{};
|
|
|
|
| 136 |
template<class T>
|
| 137 |
struct in_place_type_t {
|
| 138 |
explicit in_place_type_t() = default;
|
| 139 |
};
|
| 140 |
template<class T> inline constexpr in_place_type_t<T> in_place_type{};
|
|
|
|
| 141 |
template<size_t I>
|
| 142 |
struct in_place_index_t {
|
| 143 |
explicit in_place_index_t() = default;
|
| 144 |
};
|
| 145 |
template<size_t I> inline constexpr in_place_index_t<I> in_place_index{};
|
| 146 |
-
|
| 147 |
-
{chars_format{chars_format{chars_format{chars_format
|
| 148 |
-
// floating-point format for primitive numerical conversion
|
| 149 |
-
enum class chars_format {
|
| 150 |
-
scientific = unspecified,
|
| 151 |
-
fixed = unspecified,
|
| 152 |
-
hex = unspecified,
|
| 153 |
-
general = fixed | scientific
|
| 154 |
-
};
|
| 155 |
-
|
| 156 |
-
{to_chars_result{to_chars_result}
|
| 157 |
-
|
| 158 |
-
// [utility.to.chars], primitive numerical output conversion
|
| 159 |
-
struct to_chars_result {
|
| 160 |
-
char* ptr;
|
| 161 |
-
error_code ec;
|
| 162 |
-
};
|
| 163 |
-
|
| 164 |
-
to_chars_result to_chars(char* first, char* last, see below value, int base = 10);
|
| 165 |
-
|
| 166 |
-
to_chars_result to_chars(char* first, char* last, float value);
|
| 167 |
-
to_chars_result to_chars(char* first, char* last, double value);
|
| 168 |
-
to_chars_result to_chars(char* first, char* last, long double value);
|
| 169 |
-
|
| 170 |
-
to_chars_result to_chars(char* first, char* last, float value,
|
| 171 |
-
chars_format fmt);
|
| 172 |
-
to_chars_result to_chars(char* first, char* last, double value,
|
| 173 |
-
chars_format fmt);
|
| 174 |
-
to_chars_result to_chars(char* first, char* last, long double value,
|
| 175 |
-
chars_format fmt);
|
| 176 |
-
|
| 177 |
-
to_chars_result to_chars(char* first, char* last, float value,
|
| 178 |
-
chars_format fmt, int precision);
|
| 179 |
-
to_chars_result to_chars(char* first, char* last, double value,
|
| 180 |
-
chars_format fmt, int precision);
|
| 181 |
-
to_chars_result to_chars(char* first, char* last, long double value,
|
| 182 |
-
chars_format fmt, int precision);
|
| 183 |
-
|
| 184 |
-
{from_chars_result{from_chars_result}
|
| 185 |
-
|
| 186 |
-
// [utility.from.chars], primitive numerical input conversion
|
| 187 |
-
struct from_chars_result {
|
| 188 |
-
const char* ptr;
|
| 189 |
-
error_code ec;
|
| 190 |
-
};
|
| 191 |
-
|
| 192 |
-
from_chars_result from_chars(const char* first, const char* last,
|
| 193 |
-
see below& value, int base = 10);
|
| 194 |
-
|
| 195 |
-
from_chars_result from_chars(const char* first, const char* last, float& value,
|
| 196 |
-
chars_format fmt = chars_format::general);
|
| 197 |
-
from_chars_result from_chars(const char* first, const char* last, double& value,
|
| 198 |
-
chars_format fmt = chars_format::general);
|
| 199 |
-
from_chars_result from_chars(const char* first, const char* last, long double& value,
|
| 200 |
-
chars_format fmt = chars_format::general);
|
| 201 |
}
|
| 202 |
```
|
| 203 |
|
| 204 |
-
The header `<utility>` defines several types and function templates that
|
| 205 |
-
are described in this Clause. It also defines the template `pair` and
|
| 206 |
-
various function templates that operate on `pair` objects.
|
| 207 |
-
|
| 208 |
-
The type `chars_format` is a bitmask type ([[bitmask.types]]) with
|
| 209 |
-
elements `scientific`, `fixed`, and `hex`.
|
| 210 |
-
|
| 211 |
-
### Operators <a id="operators">[[operators]]</a>
|
| 212 |
-
|
| 213 |
-
To avoid redundant definitions of `operator!=` out of `operator==` and
|
| 214 |
-
operators `>`, `<=`, and `>=` out of `operator<`, the library provides
|
| 215 |
-
the following:
|
| 216 |
-
|
| 217 |
-
``` cpp
|
| 218 |
-
template <class T> bool operator!=(const T& x, const T& y);
|
| 219 |
-
```
|
| 220 |
-
|
| 221 |
-
*Requires:* Type `T` is `EqualityComparable`
|
| 222 |
-
(Table [[tab:equalitycomparable]]).
|
| 223 |
-
|
| 224 |
-
*Returns:* `!(x == y)`.
|
| 225 |
-
|
| 226 |
-
``` cpp
|
| 227 |
-
template <class T> bool operator>(const T& x, const T& y);
|
| 228 |
-
```
|
| 229 |
-
|
| 230 |
-
*Requires:* Type `T` is `LessThanComparable`
|
| 231 |
-
(Table [[tab:lessthancomparable]]).
|
| 232 |
-
|
| 233 |
-
*Returns:* `y < x`.
|
| 234 |
-
|
| 235 |
-
``` cpp
|
| 236 |
-
template <class T> bool operator<=(const T& x, const T& y);
|
| 237 |
-
```
|
| 238 |
-
|
| 239 |
-
*Requires:* Type `T` is `LessThanComparable`
|
| 240 |
-
(Table [[tab:lessthancomparable]]).
|
| 241 |
-
|
| 242 |
-
*Returns:* `!(y < x)`.
|
| 243 |
-
|
| 244 |
-
``` cpp
|
| 245 |
-
template <class T> bool operator>=(const T& x, const T& y);
|
| 246 |
-
```
|
| 247 |
-
|
| 248 |
-
*Requires:* Type `T` is `LessThanComparable`
|
| 249 |
-
(Table [[tab:lessthancomparable]]).
|
| 250 |
-
|
| 251 |
-
*Returns:* `!(x < y)`.
|
| 252 |
-
|
| 253 |
-
In this library, whenever a declaration is provided for an `operator!=`,
|
| 254 |
-
`operator>`, `operator>=`, or `operator<=`, and requirements and
|
| 255 |
-
semantics are not explicitly provided, the requirements and semantics
|
| 256 |
-
are as specified in this Clause.
|
| 257 |
-
|
| 258 |
### `swap` <a id="utility.swap">[[utility.swap]]</a>
|
| 259 |
|
| 260 |
``` cpp
|
| 261 |
template<class T>
|
| 262 |
-
void swap(T& a, T& b) noexcept(see below);
|
| 263 |
```
|
| 264 |
|
| 265 |
-
*
|
| 266 |
-
|
| 267 |
-
`is_move_assignable_v<T>` is `true`. The expression inside `noexcept` is
|
| 268 |
-
equivalent to:
|
| 269 |
|
| 270 |
-
``
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
*Requires:* Type `T` shall be `MoveConstructible`
|
| 275 |
-
(Table [[tab:moveconstructible]]) and `MoveAssignable`
|
| 276 |
-
(Table [[tab:moveassignable]]).
|
| 277 |
|
| 278 |
*Effects:* Exchanges values stored in two locations.
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
``` cpp
|
| 281 |
template<class T, size_t N>
|
| 282 |
-
void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v<T>);
|
| 283 |
```
|
| 284 |
|
| 285 |
-
*
|
| 286 |
-
unless `is_swappable_v<T>` is `true`.
|
| 287 |
|
| 288 |
-
*
|
| 289 |
`b[i]` for all `i` in the range \[`0`, `N`).
|
| 290 |
|
| 291 |
*Effects:* As if by `swap_ranges(a, a + N, b)`.
|
| 292 |
|
| 293 |
### `exchange` <a id="utility.exchange">[[utility.exchange]]</a>
|
| 294 |
|
| 295 |
``` cpp
|
| 296 |
-
template
|
|
|
|
| 297 |
```
|
| 298 |
|
| 299 |
*Effects:* Equivalent to:
|
| 300 |
|
| 301 |
``` cpp
|
|
@@ -307,22 +214,22 @@ return old_val;
|
|
| 307 |
### Forward/move helpers <a id="forward">[[forward]]</a>
|
| 308 |
|
| 309 |
The library provides templated helper functions to simplify applying
|
| 310 |
move semantics to an lvalue and to simplify the implementation of
|
| 311 |
forwarding functions. All functions specified in this subclause are
|
| 312 |
-
signal-safe
|
| 313 |
|
| 314 |
``` cpp
|
| 315 |
template<class T> constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 316 |
template<class T> constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
|
| 317 |
```
|
| 318 |
|
|
|
|
|
|
|
|
|
|
| 319 |
*Returns:* `static_cast<T&&>(t)`.
|
| 320 |
|
| 321 |
-
*Remarks:* If the second form is instantiated with an lvalue reference
|
| 322 |
-
type, the program is ill-formed.
|
| 323 |
-
|
| 324 |
[*Example 1*:
|
| 325 |
|
| 326 |
``` cpp
|
| 327 |
template<class T, class A1, class A2>
|
| 328 |
shared_ptr<T> factory(A1&& a1, A2&& a2) {
|
|
@@ -390,30 +297,29 @@ template <class T> constexpr conditional_t<
|
|
| 390 |
move_if_noexcept(T& x) noexcept;
|
| 391 |
```
|
| 392 |
|
| 393 |
*Returns:* `std::move(x)`.
|
| 394 |
|
| 395 |
-
### Function template `as_const` <a id="utility.
|
| 396 |
|
| 397 |
``` cpp
|
| 398 |
template<class T> constexpr add_const_t<T>& as_const(T& t) noexcept;
|
| 399 |
```
|
| 400 |
|
| 401 |
*Returns:* `t`.
|
| 402 |
|
| 403 |
### Function template `declval` <a id="declval">[[declval]]</a>
|
| 404 |
|
| 405 |
The library provides the function template `declval` to simplify the
|
| 406 |
-
definition of expressions which occur as unevaluated operands
|
| 407 |
-
[[expr]]
|
| 408 |
|
| 409 |
``` cpp
|
| 410 |
template<class T> add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
| 411 |
```
|
| 412 |
|
| 413 |
-
*
|
| 414 |
-
program is ill-formed.
|
| 415 |
|
| 416 |
*Remarks:* The template parameter `T` of `declval` may be an incomplete
|
| 417 |
type.
|
| 418 |
|
| 419 |
[*Example 1*:
|
|
@@ -422,168 +328,101 @@ type.
|
|
| 422 |
template<class To, class From> decltype(static_cast<To>(declval<From>())) convert(From&&);
|
| 423 |
```
|
| 424 |
|
| 425 |
declares a function template `convert` which only participates in
|
| 426 |
overloading if the type `From` can be explicitly converted to type `To`.
|
| 427 |
-
For another example see class template `common_type`
|
| 428 |
-
[[meta.trans.other]]
|
| 429 |
|
| 430 |
— *end example*]
|
| 431 |
|
| 432 |
-
###
|
| 433 |
-
|
| 434 |
-
All functions named `to_chars` convert `value` into a character string
|
| 435 |
-
by successively filling the range \[`first`, `last`), where \[`first`,
|
| 436 |
-
`last`) is required to be a valid range. If the member `ec` of the
|
| 437 |
-
return value is such that the value, when converted to `bool`, is
|
| 438 |
-
`false`, the conversion was successful and the member `ptr` is the
|
| 439 |
-
one-past-the-end pointer of the characters written. Otherwise, the
|
| 440 |
-
member `ec` has the value `errc::value_too_large`, the member `ptr` has
|
| 441 |
-
the value `last`, and the contents of the range \[`first`, `last`) are
|
| 442 |
-
unspecified.
|
| 443 |
-
|
| 444 |
-
The functions that take a floating-point `value` but not a `precision`
|
| 445 |
-
parameter ensure that the string representation consists of the smallest
|
| 446 |
-
number of characters such that there is at least one digit before the
|
| 447 |
-
radix point (if present) and parsing the representation using the
|
| 448 |
-
corresponding `from_chars` function recovers `value` exactly.
|
| 449 |
-
|
| 450 |
-
[*Note 1*: This guarantee applies only if `to_chars` and `from_chars`
|
| 451 |
-
are executed on the same implementation. — *end note*]
|
| 452 |
-
|
| 453 |
-
The functions taking a `chars_format` parameter determine the conversion
|
| 454 |
-
specifier for `printf` as follows: The conversion specifier is `f` if
|
| 455 |
-
`fmt` is `chars_format::fixed`, `e` if `fmt` is
|
| 456 |
-
`chars_format::scientific`, `a` (without leading `"0x"` in the result)
|
| 457 |
-
if `fmt` is `chars_format::hex`, and `g` if `fmt` is
|
| 458 |
-
`chars_format::general`.
|
| 459 |
|
| 460 |
``` cpp
|
| 461 |
-
|
|
|
|
| 462 |
```
|
| 463 |
|
| 464 |
-
*
|
|
|
|
| 465 |
|
| 466 |
-
*Effects:*
|
| 467 |
-
the given base (with no redundant leading zeroes). Digits in the range
|
| 468 |
-
10..35 (inclusive) are represented as lowercase characters `a`..`z`. If
|
| 469 |
-
`value` is less than zero, the representation starts with a minus sign.
|
| 470 |
-
|
| 471 |
-
*Throws:* Nothing.
|
| 472 |
-
|
| 473 |
-
*Remarks:* The implementation shall provide overloads for all signed and
|
| 474 |
-
unsigned integer types and `char` as the type of the parameter `value`.
|
| 475 |
|
| 476 |
``` cpp
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
```
|
| 481 |
|
| 482 |
-
*Effects:* `value` is converted to a string in the style of `printf` in
|
| 483 |
-
the `"C"` locale. The conversion specifier is `f` or `e`, chosen
|
| 484 |
-
according to the requirement for a shortest representation (see above);
|
| 485 |
-
a tie is resolved in favor of `f`.
|
| 486 |
-
|
| 487 |
-
*Throws:* Nothing.
|
| 488 |
-
|
| 489 |
``` cpp
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
to_chars_result to_chars(char* first, char* last, long double value, chars_format fmt);
|
| 493 |
```
|
| 494 |
|
| 495 |
-
*
|
| 496 |
-
`chars_format`.
|
| 497 |
-
|
| 498 |
-
*Effects:* `value` is converted to a string in the style of `printf` in
|
| 499 |
-
the `"C"` locale.
|
| 500 |
-
|
| 501 |
-
*Throws:* Nothing.
|
| 502 |
|
| 503 |
``` cpp
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
to_chars_result to_chars(char* first, char* last, double value,
|
| 507 |
-
chars_format fmt, int precision);
|
| 508 |
-
to_chars_result to_chars(char* first, char* last, long double value,
|
| 509 |
-
chars_format fmt, int precision);
|
| 510 |
```
|
| 511 |
|
| 512 |
-
*
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
*Effects:* `value` is converted to a string in the style of `printf` in
|
| 516 |
-
the `"C"` locale with the given precision.
|
| 517 |
-
|
| 518 |
-
*Throws:* Nothing.
|
| 519 |
-
|
| 520 |
-
ISO C 7.21.6.1.
|
| 521 |
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
All functions named `from_chars` analyze the string \[`first`, `last`)
|
| 525 |
-
for a pattern, where \[`first`, `last`) is required to be a valid range.
|
| 526 |
-
If no characters match the pattern, `value` is unmodified, the member
|
| 527 |
-
`ptr` of the return value is `first` and the member `ec` is equal to
|
| 528 |
-
`errc::invalid_argument`. Otherwise, the characters matching the pattern
|
| 529 |
-
are interpreted as a representation of a value of the type of `value`.
|
| 530 |
-
The member `ptr` of the return value points to the first character not
|
| 531 |
-
matching the pattern, or has the value `last` if all characters match.
|
| 532 |
-
If the parsed value is not in the range representable by the type of
|
| 533 |
-
`value`, `value` is unmodified and the member `ec` of the return value
|
| 534 |
-
is equal to `errc::result_out_of_range`. Otherwise, `value` is set to
|
| 535 |
-
the parsed value and the member `ec` is set such that the conversion to
|
| 536 |
-
`bool` yields `false`.
|
| 537 |
|
| 538 |
``` cpp
|
| 539 |
-
|
| 540 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
```
|
| 542 |
|
| 543 |
-
|
|
|
|
|
|
|
|
|
|
| 544 |
|
| 545 |
-
*Effects:*
|
| 546 |
-
the `"C"` locale for the given nonzero base, as described for `strtol`,
|
| 547 |
-
except that no `"0x"` or `"0X"` prefix shall appear if the value of
|
| 548 |
-
`base` is 16, and except that a minus sign is the only sign that may
|
| 549 |
-
appear, and only if `value` has a signed type.
|
| 550 |
|
| 551 |
-
|
|
|
|
|
|
|
|
|
|
| 552 |
|
| 553 |
-
*
|
| 554 |
-
unsigned integer types and `char` as the referenced type of the
|
| 555 |
-
parameter `value`.
|
| 556 |
|
| 557 |
``` cpp
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
from_chars_result from_chars(const char* first, const char* last, double& value,
|
| 561 |
-
chars_format fmt = chars_format::general);
|
| 562 |
-
from_chars_result from_chars(const char* first, const char* last, long double& value,
|
| 563 |
-
chars_format fmt = chars_format::general);
|
| 564 |
```
|
| 565 |
|
| 566 |
-
*
|
| 567 |
-
`chars_format`.
|
| 568 |
|
| 569 |
-
|
| 570 |
-
|
|
|
|
|
|
|
| 571 |
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
`chars_format::fixed`, the otherwise optional exponent part shall
|
| 575 |
-
appear;
|
| 576 |
-
- if `fmt` has `chars_format::fixed` set but not
|
| 577 |
-
`chars_format::scientific`, the optional exponent part shall not
|
| 578 |
-
appear; and
|
| 579 |
-
- if `fmt` is `chars_format::hex`, the prefix `"0x"` or `"0X"` is
|
| 580 |
-
assumed. \[*Example 1*: The string `0x123` is parsed to have the value
|
| 581 |
-
`0` with remaining characters `x123`. — *end example*]
|
| 582 |
|
| 583 |
-
|
| 584 |
-
values closest to the value of the string matching the pattern.
|
| 585 |
|
| 586 |
-
|
|
|
|
|
|
|
|
|
|
| 587 |
|
| 588 |
-
|
|
|
|
|
|
|
| 589 |
|
|
|
|
| 1 |
## Utility components <a id="utility">[[utility]]</a>
|
| 2 |
|
|
|
|
|
|
|
|
|
|
| 3 |
### Header `<utility>` synopsis <a id="utility.syn">[[utility.syn]]</a>
|
| 4 |
|
| 5 |
+
The header `<utility>` contains some basic function and class templates
|
| 6 |
+
that are used throughout the rest of the library.
|
| 7 |
+
|
| 8 |
``` cpp
|
| 9 |
+
#include <compare> // see [compare.syn]
|
| 10 |
+
#include <initializer_list> // see [initializer.list.syn]
|
| 11 |
|
| 12 |
namespace std {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
// [utility.swap], swap
|
| 14 |
template<class T>
|
| 15 |
+
constexpr void swap(T& a, T& b) noexcept(see below);
|
| 16 |
template<class T, size_t N>
|
| 17 |
+
constexpr void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v<T>);
|
| 18 |
|
| 19 |
// [utility.exchange], exchange
|
| 20 |
template<class T, class U = T>
|
| 21 |
+
constexpr T exchange(T& obj, U&& new_val);
|
| 22 |
|
| 23 |
// [forward], forward/move
|
| 24 |
template<class T>
|
| 25 |
constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 26 |
template<class T>
|
|
|
|
| 30 |
template<class T>
|
| 31 |
constexpr conditional_t<
|
| 32 |
!is_nothrow_move_constructible_v<T> && is_copy_constructible_v<T>, const T&, T&&>
|
| 33 |
move_if_noexcept(T& x) noexcept;
|
| 34 |
|
| 35 |
+
// [utility.as.const], as_const
|
| 36 |
template<class T>
|
| 37 |
constexpr add_const_t<T>& as_const(T& t) noexcept;
|
| 38 |
template<class T>
|
| 39 |
void as_const(const T&&) = delete;
|
| 40 |
|
| 41 |
// [declval], declval
|
| 42 |
template<class T>
|
| 43 |
add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
| 44 |
+
|
| 45 |
+
// [utility.intcmp], integer comparison functions
|
| 46 |
+
template<class T, class U>
|
| 47 |
+
constexpr bool cmp_equal(T t, U u) noexcept;
|
| 48 |
+
template<class T, class U>
|
| 49 |
+
constexpr bool cmp_not_equal(T t, U u) noexcept;
|
| 50 |
+
|
| 51 |
+
template<class T, class U>
|
| 52 |
+
constexpr bool cmp_less(T t, U u) noexcept;
|
| 53 |
+
template<class T, class U>
|
| 54 |
+
constexpr bool cmp_greater(T t, U u) noexcept;
|
| 55 |
+
template<class T, class U>
|
| 56 |
+
constexpr bool cmp_less_equal(T t, U u) noexcept;
|
| 57 |
+
template<class T, class U>
|
| 58 |
+
constexpr bool cmp_greater_equal(T t, U u) noexcept;
|
| 59 |
+
|
| 60 |
+
template<class R, class T>
|
| 61 |
+
constexpr bool in_range(T t) noexcept;
|
| 62 |
+
|
| 63 |
+
// [intseq], compile-time integer sequences%
|
| 64 |
+
%
|
| 65 |
%
|
| 66 |
|
|
|
|
| 67 |
template<class T, T...>
|
| 68 |
struct integer_sequence;
|
| 69 |
template<size_t... I>
|
| 70 |
using index_sequence = integer_sequence<size_t, I...>;
|
| 71 |
|
|
|
|
| 83 |
|
| 84 |
// [pairs.spec], pair specialized algorithms
|
| 85 |
template<class T1, class T2>
|
| 86 |
constexpr bool operator==(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 87 |
template<class T1, class T2>
|
| 88 |
+
constexpr common_comparison_category_t<synth-three-way-result<T1>,
|
| 89 |
+
synth-three-way-result<T2>>
|
| 90 |
+
operator<=>(const pair<T1, T2>&, const pair<T1, T2>&);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
template<class T1, class T2>
|
| 93 |
+
constexpr void swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
|
| 94 |
|
| 95 |
template<class T1, class T2>
|
| 96 |
constexpr see below make_pair(T1&&, T2&&);
|
| 97 |
|
| 98 |
// [pair.astuple], tuple-like access to pair
|
| 99 |
+
template<class T> struct tuple_size;
|
| 100 |
+
template<size_t I, class T> struct tuple_element;
|
| 101 |
|
| 102 |
template<class T1, class T2> struct tuple_size<pair<T1, T2>>;
|
| 103 |
+
template<size_t I, class T1, class T2> struct tuple_element<I, pair<T1, T2>>;
|
|
|
|
| 104 |
|
| 105 |
template<size_t I, class T1, class T2>
|
| 106 |
constexpr tuple_element_t<I, pair<T1, T2>>& get(pair<T1, T2>&) noexcept;
|
| 107 |
template<size_t I, class T1, class T2>
|
| 108 |
constexpr tuple_element_t<I, pair<T1, T2>>&& get(pair<T1, T2>&&) noexcept;
|
|
|
|
| 130 |
// [pair.piecewise], pair piecewise construction
|
| 131 |
struct piecewise_construct_t {
|
| 132 |
explicit piecewise_construct_t() = default;
|
| 133 |
};
|
| 134 |
inline constexpr piecewise_construct_t piecewise_construct{};
|
| 135 |
+
template<class... Types> class tuple; // defined in <tuple>
|
| 136 |
+
|
| 137 |
+
// in-place construction%
|
| 138 |
+
%
|
| 139 |
+
%
|
| 140 |
+
%
|
| 141 |
+
%
|
| 142 |
+
%
|
| 143 |
|
|
|
|
| 144 |
struct in_place_t {
|
| 145 |
explicit in_place_t() = default;
|
| 146 |
};
|
| 147 |
inline constexpr in_place_t in_place{};
|
| 148 |
+
|
| 149 |
template<class T>
|
| 150 |
struct in_place_type_t {
|
| 151 |
explicit in_place_type_t() = default;
|
| 152 |
};
|
| 153 |
template<class T> inline constexpr in_place_type_t<T> in_place_type{};
|
| 154 |
+
|
| 155 |
template<size_t I>
|
| 156 |
struct in_place_index_t {
|
| 157 |
explicit in_place_index_t() = default;
|
| 158 |
};
|
| 159 |
template<size_t I> inline constexpr in_place_index_t<I> in_place_index{};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
}
|
| 161 |
```
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
### `swap` <a id="utility.swap">[[utility.swap]]</a>
|
| 164 |
|
| 165 |
``` cpp
|
| 166 |
template<class T>
|
| 167 |
+
constexpr void swap(T& a, T& b) noexcept(see below);
|
| 168 |
```
|
| 169 |
|
| 170 |
+
*Constraints:* `is_move_constructible_v<T>` is `true` and
|
| 171 |
+
`is_move_assignable_v<T>` is `true`.
|
|
|
|
|
|
|
| 172 |
|
| 173 |
+
*Preconditions:* Type `T` meets the *Cpp17MoveConstructible*
|
| 174 |
+
([[cpp17.moveconstructible]]) and *Cpp17MoveAssignable*
|
| 175 |
+
([[cpp17.moveassignable]]) requirements.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
*Effects:* Exchanges values stored in two locations.
|
| 178 |
|
| 179 |
+
*Remarks:* This function is a designated customization
|
| 180 |
+
point [[namespace.std]]. The expression inside `noexcept` is equivalent
|
| 181 |
+
to:
|
| 182 |
+
|
| 183 |
+
``` cpp
|
| 184 |
+
is_nothrow_move_constructible_v<T> && is_nothrow_move_assignable_v<T>
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
``` cpp
|
| 188 |
template<class T, size_t N>
|
| 189 |
+
constexpr void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v<T>);
|
| 190 |
```
|
| 191 |
|
| 192 |
+
*Constraints:* `is_swappable_v<T>` is `true`.
|
|
|
|
| 193 |
|
| 194 |
+
*Preconditions:* `a[i]` is swappable with [[swappable.requirements]]
|
| 195 |
`b[i]` for all `i` in the range \[`0`, `N`).
|
| 196 |
|
| 197 |
*Effects:* As if by `swap_ranges(a, a + N, b)`.
|
| 198 |
|
| 199 |
### `exchange` <a id="utility.exchange">[[utility.exchange]]</a>
|
| 200 |
|
| 201 |
``` cpp
|
| 202 |
+
template<class T, class U = T>
|
| 203 |
+
constexpr T exchange(T& obj, U&& new_val);
|
| 204 |
```
|
| 205 |
|
| 206 |
*Effects:* Equivalent to:
|
| 207 |
|
| 208 |
``` cpp
|
|
|
|
| 214 |
### Forward/move helpers <a id="forward">[[forward]]</a>
|
| 215 |
|
| 216 |
The library provides templated helper functions to simplify applying
|
| 217 |
move semantics to an lvalue and to simplify the implementation of
|
| 218 |
forwarding functions. All functions specified in this subclause are
|
| 219 |
+
signal-safe [[support.signal]].
|
| 220 |
|
| 221 |
``` cpp
|
| 222 |
template<class T> constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 223 |
template<class T> constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
|
| 224 |
```
|
| 225 |
|
| 226 |
+
*Mandates:* For the second overload, `is_lvalue_reference_v<T>` is
|
| 227 |
+
`false`.
|
| 228 |
+
|
| 229 |
*Returns:* `static_cast<T&&>(t)`.
|
| 230 |
|
|
|
|
|
|
|
|
|
|
| 231 |
[*Example 1*:
|
| 232 |
|
| 233 |
``` cpp
|
| 234 |
template<class T, class A1, class A2>
|
| 235 |
shared_ptr<T> factory(A1&& a1, A2&& a2) {
|
|
|
|
| 297 |
move_if_noexcept(T& x) noexcept;
|
| 298 |
```
|
| 299 |
|
| 300 |
*Returns:* `std::move(x)`.
|
| 301 |
|
| 302 |
+
### Function template `as_const` <a id="utility.as.const">[[utility.as.const]]</a>
|
| 303 |
|
| 304 |
``` cpp
|
| 305 |
template<class T> constexpr add_const_t<T>& as_const(T& t) noexcept;
|
| 306 |
```
|
| 307 |
|
| 308 |
*Returns:* `t`.
|
| 309 |
|
| 310 |
### Function template `declval` <a id="declval">[[declval]]</a>
|
| 311 |
|
| 312 |
The library provides the function template `declval` to simplify the
|
| 313 |
+
definition of expressions which occur as unevaluated operands
|
| 314 |
+
[[expr.prop]].
|
| 315 |
|
| 316 |
``` cpp
|
| 317 |
template<class T> add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
| 318 |
```
|
| 319 |
|
| 320 |
+
*Mandates:* This function is not odr-used [[basic.def.odr]].
|
|
|
|
| 321 |
|
| 322 |
*Remarks:* The template parameter `T` of `declval` may be an incomplete
|
| 323 |
type.
|
| 324 |
|
| 325 |
[*Example 1*:
|
|
|
|
| 328 |
template<class To, class From> decltype(static_cast<To>(declval<From>())) convert(From&&);
|
| 329 |
```
|
| 330 |
|
| 331 |
declares a function template `convert` which only participates in
|
| 332 |
overloading if the type `From` can be explicitly converted to type `To`.
|
| 333 |
+
For another example see class template `common_type`
|
| 334 |
+
[[meta.trans.other]].
|
| 335 |
|
| 336 |
— *end example*]
|
| 337 |
|
| 338 |
+
### Integer comparison functions <a id="utility.intcmp">[[utility.intcmp]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
``` cpp
|
| 341 |
+
template<class T, class U>
|
| 342 |
+
constexpr bool cmp_equal(T t, U u) noexcept;
|
| 343 |
```
|
| 344 |
|
| 345 |
+
*Mandates:* Both `T` and `U` are standard integer types or extended
|
| 346 |
+
integer types [[basic.fundamental]].
|
| 347 |
|
| 348 |
+
*Effects:* Equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
|
| 350 |
``` cpp
|
| 351 |
+
using UT = make_unsigned_t<T>;
|
| 352 |
+
using UU = make_unsigned_t<U>;
|
| 353 |
+
if constexpr (is_signed_v<T> == is_signed_v<U>)
|
| 354 |
+
return t == u;
|
| 355 |
+
else if constexpr (is_signed_v<T>)
|
| 356 |
+
return t < 0 ? false : UT(t) == u;
|
| 357 |
+
else
|
| 358 |
+
return u < 0 ? false : t == UU(u);
|
| 359 |
```
|
| 360 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
``` cpp
|
| 362 |
+
template<class T, class U>
|
| 363 |
+
constexpr bool cmp_not_equal(T t, U u) noexcept;
|
|
|
|
| 364 |
```
|
| 365 |
|
| 366 |
+
*Effects:* Equivalent to: `return !cmp_equal(t, u);`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
|
| 368 |
``` cpp
|
| 369 |
+
template<class T, class U>
|
| 370 |
+
constexpr bool cmp_less(T t, U u) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
```
|
| 372 |
|
| 373 |
+
*Mandates:* Both `T` and `U` are standard integer types or extended
|
| 374 |
+
integer types [[basic.fundamental]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
|
| 376 |
+
*Effects:* Equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
|
| 378 |
``` cpp
|
| 379 |
+
using UT = make_unsigned_t<T>;
|
| 380 |
+
using UU = make_unsigned_t<U>;
|
| 381 |
+
if constexpr (is_signed_v<T> == is_signed_v<U>)
|
| 382 |
+
return t < u;
|
| 383 |
+
else if constexpr (is_signed_v<T>)
|
| 384 |
+
return t < 0 ? true : UT(t) < u;
|
| 385 |
+
else
|
| 386 |
+
return u < 0 ? false : t < UU(u);
|
| 387 |
```
|
| 388 |
|
| 389 |
+
``` cpp
|
| 390 |
+
template<class T, class U>
|
| 391 |
+
constexpr bool cmp_greater(T t, U u) noexcept;
|
| 392 |
+
```
|
| 393 |
|
| 394 |
+
*Effects:* Equivalent to: `return cmp_less(u, t);`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
|
| 396 |
+
``` cpp
|
| 397 |
+
template<class T, class U>
|
| 398 |
+
constexpr bool cmp_less_equal(T t, U u) noexcept;
|
| 399 |
+
```
|
| 400 |
|
| 401 |
+
*Effects:* Equivalent to: `return !cmp_greater(t, u);`
|
|
|
|
|
|
|
| 402 |
|
| 403 |
``` cpp
|
| 404 |
+
template<class T, class U>
|
| 405 |
+
constexpr bool cmp_greater_equal(T t, U u) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
```
|
| 407 |
|
| 408 |
+
*Effects:* Equivalent to: `return !cmp_less(t, u);`
|
|
|
|
| 409 |
|
| 410 |
+
``` cpp
|
| 411 |
+
template<class R, class T>
|
| 412 |
+
constexpr bool in_range(T t) noexcept;
|
| 413 |
+
```
|
| 414 |
|
| 415 |
+
*Mandates:* Both `T` and `R` are standard integer types or extended
|
| 416 |
+
integer types [[basic.fundamental]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
|
| 418 |
+
*Effects:* Equivalent to:
|
|
|
|
| 419 |
|
| 420 |
+
``` cpp
|
| 421 |
+
return cmp_greater_equal(t, numeric_limits<R>::min()) &&
|
| 422 |
+
cmp_less_equal(t, numeric_limits<R>::max());
|
| 423 |
+
```
|
| 424 |
|
| 425 |
+
[*Note 1*: These function templates cannot be used to compare `byte`,
|
| 426 |
+
`char`, `char8_t`, `char16_t`, `char32_t`, `wchar_t`, and
|
| 427 |
+
`bool`. — *end note*]
|
| 428 |
|