- tmp/tmpmp_tdj4b/{from.md → to.md} +353 -78
tmp/tmpmp_tdj4b/{from.md → to.md}
RENAMED
|
@@ -1,55 +1,76 @@
|
|
| 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 |
-
|
| 7 |
-
|
| 8 |
-
The header `<utility>` defines several types and function templates that
|
| 9 |
-
are described in this Clause. It also defines the template `pair` and
|
| 10 |
-
various function templates that operate on `pair` objects.
|
| 11 |
|
| 12 |
``` cpp
|
| 13 |
-
#include <initializer_list>
|
| 14 |
|
| 15 |
namespace std {
|
| 16 |
-
// [operators], operators
|
| 17 |
namespace rel_ops {
|
| 18 |
template<class T> bool operator!=(const T&, const T&);
|
| 19 |
template<class T> bool operator> (const T&, const T&);
|
| 20 |
template<class T> bool operator<=(const T&, const T&);
|
| 21 |
template<class T> bool operator>=(const T&, const T&);
|
| 22 |
}
|
| 23 |
|
| 24 |
-
// [utility.swap], swap
|
| 25 |
-
template<class T>
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
// [utility.exchange], exchange
|
| 29 |
-
template <class T, class U=
|
|
|
|
| 30 |
|
| 31 |
-
// [forward], forward/move
|
| 32 |
template <class T>
|
| 33 |
constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 34 |
template <class T>
|
| 35 |
constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
|
| 36 |
template <class T>
|
| 37 |
constexpr remove_reference_t<T>&& move(T&&) noexcept;
|
| 38 |
template <class T>
|
| 39 |
constexpr conditional_t<
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
-
// [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
template <class T>
|
| 45 |
add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
|
|
|
| 46 |
|
| 47 |
-
// [
|
| 48 |
-
template
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
template <class T1, class T2>
|
| 52 |
constexpr bool operator==(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 53 |
template <class T1, class T2>
|
| 54 |
constexpr bool operator< (const pair<T1, T2>&, const pair<T1, T2>&);
|
| 55 |
template <class T1, class T2>
|
|
@@ -58,66 +79,137 @@ namespace std {
|
|
| 58 |
constexpr bool operator> (const pair<T1, T2>&, const pair<T1, T2>&);
|
| 59 |
template <class T1, class T2>
|
| 60 |
constexpr bool operator>=(const pair<T1, T2>&, const pair<T1, T2>&);
|
| 61 |
template <class T1, class T2>
|
| 62 |
constexpr bool operator<=(const pair<T1, T2>&, const pair<T1, T2>&);
|
|
|
|
| 63 |
template <class T1, class T2>
|
| 64 |
void swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
|
|
|
|
| 65 |
template <class T1, class T2>
|
| 66 |
constexpr see below make_pair(T1&&, T2&&);
|
| 67 |
|
| 68 |
-
// [pair.astuple], tuple-like access to pair
|
| 69 |
template <class T> class tuple_size;
|
| 70 |
template <size_t I, class T> class tuple_element;
|
| 71 |
|
| 72 |
template <class T1, class T2> struct tuple_size<pair<T1, T2>>;
|
| 73 |
template <class T1, class T2> struct tuple_element<0, pair<T1, T2>>;
|
| 74 |
template <class T1, class T2> struct tuple_element<1, pair<T1, T2>>;
|
| 75 |
|
| 76 |
template<size_t I, class T1, class T2>
|
| 77 |
-
constexpr tuple_element_t<I, pair<T1, T2>>&
|
| 78 |
-
get(pair<T1, T2>&) noexcept;
|
| 79 |
template<size_t I, class T1, class T2>
|
| 80 |
-
constexpr tuple_element_t<I, pair<T1, T2>>&&
|
| 81 |
-
get(pair<T1, T2>&&) noexcept;
|
| 82 |
template<size_t I, class T1, class T2>
|
| 83 |
-
constexpr const tuple_element_t<I, pair<T1, T2>>&
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
// [pair.piecewise], pair piecewise construction
|
| 99 |
-
struct piecewise_construct_t {
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
|
| 110 |
-
using make_integer_sequence = integer_sequence<T, see below>;
|
| 111 |
-
template<size_t N>
|
| 112 |
-
using make_index_sequence = make_integer_sequence<size_t, N>;
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
}
|
| 117 |
```
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
### Operators <a id="operators">[[operators]]</a>
|
| 120 |
|
| 121 |
To avoid redundant definitions of `operator!=` out of `operator==` and
|
| 122 |
operators `>`, `<=`, and `>=` out of `operator<`, the library provides
|
| 123 |
the following:
|
|
@@ -125,76 +217,82 @@ the following:
|
|
| 125 |
``` cpp
|
| 126 |
template <class T> bool operator!=(const T& x, const T& y);
|
| 127 |
```
|
| 128 |
|
| 129 |
*Requires:* Type `T` is `EqualityComparable`
|
| 130 |
-
(Table [[equalitycomparable]]).
|
| 131 |
|
| 132 |
*Returns:* `!(x == y)`.
|
| 133 |
|
| 134 |
``` cpp
|
| 135 |
template <class T> bool operator>(const T& x, const T& y);
|
| 136 |
```
|
| 137 |
|
| 138 |
*Requires:* Type `T` is `LessThanComparable`
|
| 139 |
-
(Table [[lessthancomparable]]).
|
| 140 |
|
| 141 |
*Returns:* `y < x`.
|
| 142 |
|
| 143 |
``` cpp
|
| 144 |
template <class T> bool operator<=(const T& x, const T& y);
|
| 145 |
```
|
| 146 |
|
| 147 |
*Requires:* Type `T` is `LessThanComparable`
|
| 148 |
-
(Table [[lessthancomparable]]).
|
| 149 |
|
| 150 |
*Returns:* `!(y < x)`.
|
| 151 |
|
| 152 |
``` cpp
|
| 153 |
template <class T> bool operator>=(const T& x, const T& y);
|
| 154 |
```
|
| 155 |
|
| 156 |
*Requires:* Type `T` is `LessThanComparable`
|
| 157 |
-
(Table [[lessthancomparable]]).
|
| 158 |
|
| 159 |
*Returns:* `!(x < y)`.
|
| 160 |
|
| 161 |
In this library, whenever a declaration is provided for an `operator!=`,
|
| 162 |
`operator>`, `operator>=`, or `operator<=`, and requirements and
|
| 163 |
semantics are not explicitly provided, the requirements and semantics
|
| 164 |
are as specified in this Clause.
|
| 165 |
|
| 166 |
-
### swap <a id="utility.swap">[[utility.swap]]</a>
|
| 167 |
|
| 168 |
``` cpp
|
| 169 |
-
template<class T>
|
|
|
|
| 170 |
```
|
| 171 |
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
``` cpp
|
| 175 |
-
|
| 176 |
-
is_nothrow_move_assignable<T>::value
|
| 177 |
```
|
| 178 |
|
| 179 |
*Requires:* Type `T` shall be `MoveConstructible`
|
| 180 |
-
(Table [[moveconstructible]]) and `MoveAssignable`
|
| 181 |
-
(Table [[moveassignable]]).
|
| 182 |
|
| 183 |
*Effects:* Exchanges values stored in two locations.
|
| 184 |
|
| 185 |
``` cpp
|
| 186 |
template <class T, size_t N>
|
| 187 |
-
void swap(T (&a)[N], T (&b)[N]) noexcept(
|
| 188 |
```
|
| 189 |
|
|
|
|
|
|
|
|
|
|
| 190 |
*Requires:* `a[i]` shall be swappable with ([[swappable.requirements]])
|
| 191 |
`b[i]` for all `i` in the range \[`0`, `N`).
|
| 192 |
|
| 193 |
-
*Effects:* `swap_ranges(a, a + N, b)`
|
| 194 |
|
| 195 |
-
### exchange <a id="utility.exchange">[[utility.exchange]]</a>
|
| 196 |
|
| 197 |
``` cpp
|
| 198 |
template <class T, class U = T> T exchange(T& obj, U&& new_val);
|
| 199 |
```
|
| 200 |
|
|
@@ -204,25 +302,28 @@ template <class T, class U=T> T exchange(T& obj, U&& new_val);
|
|
| 204 |
T old_val = std::move(obj);
|
| 205 |
obj = std::forward<U>(new_val);
|
| 206 |
return old_val;
|
| 207 |
```
|
| 208 |
|
| 209 |
-
###
|
| 210 |
|
| 211 |
The library provides templated helper functions to simplify applying
|
| 212 |
move semantics to an lvalue and to simplify the implementation of
|
| 213 |
-
forwarding functions.
|
|
|
|
| 214 |
|
| 215 |
``` cpp
|
| 216 |
template <class T> constexpr T&& forward(remove_reference_t<T>& t) noexcept;
|
| 217 |
template <class T> constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
|
| 218 |
```
|
| 219 |
|
| 220 |
*Returns:* `static_cast<T&&>(t)`.
|
| 221 |
|
| 222 |
-
If the second form is instantiated with an lvalue reference
|
| 223 |
-
program is ill-formed.
|
|
|
|
|
|
|
| 224 |
|
| 225 |
``` cpp
|
| 226 |
template <class T, class A1, class A2>
|
| 227 |
shared_ptr<T> factory(A1&& a1, A2&& a2) {
|
| 228 |
return shared_ptr<T>(new T(std::forward<A1>(a1), std::forward<A2>(a2)));
|
|
@@ -243,16 +344,20 @@ In the first call to `factory`, `A1` is deduced as `int`, so 2 is
|
|
| 243 |
forwarded to `A`’s constructor as an rvalue. In the second call to
|
| 244 |
`factory`, `A1` is deduced as `int&`, so `i` is forwarded to `A`’s
|
| 245 |
constructor as an lvalue. In both cases, `A2` is deduced as `double`, so
|
| 246 |
1.414 is forwarded to `A`’s constructor as an rvalue.
|
| 247 |
|
|
|
|
|
|
|
| 248 |
``` cpp
|
| 249 |
template <class T> constexpr remove_reference_t<T>&& move(T&& t) noexcept;
|
| 250 |
```
|
| 251 |
|
| 252 |
*Returns:* `static_cast<remove_reference_t<T>&&>(t)`.
|
| 253 |
|
|
|
|
|
|
|
| 254 |
``` cpp
|
| 255 |
template <class T, class A1>
|
| 256 |
shared_ptr<T> factory(A1&& a1) {
|
| 257 |
return shared_ptr<T>(new T(std::forward<A1>(a1)));
|
| 258 |
}
|
|
@@ -275,40 +380,210 @@ forwarded as a non-const lvalue. This binds to the constructor
|
|
| 275 |
`A(const A&)`, which copies the value from `a`. In the second call to
|
| 276 |
`factory`, because of the call `std::move(a)`, `A1` is deduced as `A`,
|
| 277 |
so `a` is forwarded as an rvalue. This binds to the constructor
|
| 278 |
`A(A&&)`, which moves the value from `a`.
|
| 279 |
|
|
|
|
|
|
|
| 280 |
``` cpp
|
| 281 |
template <class T> constexpr conditional_t<
|
| 282 |
-
|
| 283 |
-
|
| 284 |
```
|
| 285 |
|
| 286 |
-
*Returns:* `std::move(x)`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
### Function template `declval` <a id="declval">[[declval]]</a>
|
| 289 |
|
| 290 |
The library provides the function template `declval` to simplify the
|
| 291 |
definition of expressions which occur as unevaluated operands (Clause
|
| 292 |
[[expr]]).
|
| 293 |
|
| 294 |
``` cpp
|
| 295 |
-
template <class T>
|
| 296 |
-
add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
| 297 |
```
|
| 298 |
|
| 299 |
*Remarks:* If this function is odr-used ([[basic.def.odr]]), the
|
| 300 |
program is ill-formed.
|
| 301 |
|
| 302 |
*Remarks:* The template parameter `T` of `declval` may be an incomplete
|
| 303 |
type.
|
| 304 |
|
|
|
|
|
|
|
| 305 |
``` cpp
|
| 306 |
-
template <class To, class From>
|
| 307 |
-
decltype(static_cast<To>(declval<From>())) convert(From&&);
|
| 308 |
```
|
| 309 |
|
| 310 |
declares a function template `convert` which only participates in
|
| 311 |
overloading if the type `From` can be explicitly converted to type `To`.
|
| 312 |
-
For another example see class template
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
|
|
|
|
| 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 <initializer_list> // see [initializer_list.syn]
|
| 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>
|
| 34 |
constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
|
| 35 |
template <class T>
|
| 36 |
constexpr remove_reference_t<T>&& move(T&&) noexcept;
|
| 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.as_const], as_const
|
| 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 |
|
| 59 |
+
template<class T, T N>
|
| 60 |
+
using make_integer_sequence = integer_sequence<T, see below>;
|
| 61 |
+
template<size_t N>
|
| 62 |
+
using make_index_sequence = make_integer_sequence<size_t, N>;
|
| 63 |
+
|
| 64 |
+
template<class... T>
|
| 65 |
+
using index_sequence_for = make_index_sequence<sizeof...(T)>;
|
| 66 |
+
|
| 67 |
+
// [pairs], class template pair
|
| 68 |
+
template <class T1, class T2>
|
| 69 |
+
struct pair;
|
| 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 bool operator< (const pair<T1, T2>&, const pair<T1, T2>&);
|
| 76 |
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 <class T> class tuple_size;
|
| 93 |
template <size_t I, class T> class tuple_element;
|
| 94 |
|
| 95 |
template <class T1, class T2> struct tuple_size<pair<T1, T2>>;
|
| 96 |
template <class T1, class T2> struct tuple_element<0, pair<T1, T2>>;
|
| 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;
|
|
|
|
| 103 |
template<size_t I, class T1, class T2>
|
| 104 |
+
constexpr const tuple_element_t<I, pair<T1, T2>>& get(const pair<T1, T2>&) noexcept;
|
| 105 |
+
template<size_t I, class T1, class T2>
|
| 106 |
+
constexpr const tuple_element_t<I, pair<T1, T2>>&& get(const pair<T1, T2>&&) noexcept;
|
| 107 |
+
template <class T1, class T2>
|
| 108 |
+
constexpr T1& get(pair<T1, T2>& p) noexcept;
|
| 109 |
+
template <class T1, class T2>
|
| 110 |
+
constexpr const T1& get(const pair<T1, T2>& p) noexcept;
|
| 111 |
+
template <class T1, class T2>
|
| 112 |
+
constexpr T1&& get(pair<T1, T2>&& p) noexcept;
|
| 113 |
+
template <class T1, class T2>
|
| 114 |
+
constexpr const T1&& get(const pair<T1, T2>&& p) noexcept;
|
| 115 |
+
template <class T2, class T1>
|
| 116 |
+
constexpr T2& get(pair<T1, T2>& p) noexcept;
|
| 117 |
+
template <class T2, class T1>
|
| 118 |
+
constexpr const T2& get(const pair<T1, T2>& p) noexcept;
|
| 119 |
+
template <class T2, class T1>
|
| 120 |
+
constexpr T2&& get(pair<T1, T2>&& p) noexcept;
|
| 121 |
+
template <class T2, class T1>
|
| 122 |
+
constexpr const T2&& get(const pair<T1, T2>&& p) noexcept;
|
| 123 |
|
| 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 <class... Types> class tuple; // defined in <tuple> ([tuple.syn])
|
| 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:
|
|
|
|
| 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 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 266 |
+
unless `is_move_constructible_v<T>` is `true` and
|
| 267 |
+
`is_move_assignable_v<T>` is `true`. The expression inside `noexcept` is
|
| 268 |
+
equivalent to:
|
| 269 |
|
| 270 |
``` cpp
|
| 271 |
+
is_nothrow_move_constructible_v<T> && is_nothrow_move_assignable_v<T>
|
|
|
|
| 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 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 286 |
+
unless `is_swappable_v<T>` is `true`.
|
| 287 |
+
|
| 288 |
*Requires:* `a[i]` shall be swappable with ([[swappable.requirements]])
|
| 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 <class T, class U = T> T exchange(T& obj, U&& new_val);
|
| 297 |
```
|
| 298 |
|
|
|
|
| 302 |
T old_val = std::move(obj);
|
| 303 |
obj = std::forward<U>(new_val);
|
| 304 |
return old_val;
|
| 305 |
```
|
| 306 |
|
| 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 ([[csignal.syn]]).
|
| 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) {
|
| 329 |
return shared_ptr<T>(new T(std::forward<A1>(a1), std::forward<A2>(a2)));
|
|
|
|
| 344 |
forwarded to `A`’s constructor as an rvalue. In the second call to
|
| 345 |
`factory`, `A1` is deduced as `int&`, so `i` is forwarded to `A`’s
|
| 346 |
constructor as an lvalue. In both cases, `A2` is deduced as `double`, so
|
| 347 |
1.414 is forwarded to `A`’s constructor as an rvalue.
|
| 348 |
|
| 349 |
+
— *end example*]
|
| 350 |
+
|
| 351 |
``` cpp
|
| 352 |
template <class T> constexpr remove_reference_t<T>&& move(T&& t) noexcept;
|
| 353 |
```
|
| 354 |
|
| 355 |
*Returns:* `static_cast<remove_reference_t<T>&&>(t)`.
|
| 356 |
|
| 357 |
+
[*Example 2*:
|
| 358 |
+
|
| 359 |
``` cpp
|
| 360 |
template <class T, class A1>
|
| 361 |
shared_ptr<T> factory(A1&& a1) {
|
| 362 |
return shared_ptr<T>(new T(std::forward<A1>(a1)));
|
| 363 |
}
|
|
|
|
| 380 |
`A(const A&)`, which copies the value from `a`. In the second call to
|
| 381 |
`factory`, because of the call `std::move(a)`, `A1` is deduced as `A`,
|
| 382 |
so `a` is forwarded as an rvalue. This binds to the constructor
|
| 383 |
`A(A&&)`, which moves the value from `a`.
|
| 384 |
|
| 385 |
+
— *end example*]
|
| 386 |
+
|
| 387 |
``` cpp
|
| 388 |
template <class T> constexpr conditional_t<
|
| 389 |
+
!is_nothrow_move_constructible_v<T> && is_copy_constructible_v<T>, const T&, T&&>
|
| 390 |
+
move_if_noexcept(T& x) noexcept;
|
| 391 |
```
|
| 392 |
|
| 393 |
+
*Returns:* `std::move(x)`.
|
| 394 |
+
|
| 395 |
+
### Function template `as_const` <a id="utility.as_const">[[utility.as_const]]</a>
|
| 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 (Clause
|
| 407 |
[[expr]]).
|
| 408 |
|
| 409 |
``` cpp
|
| 410 |
+
template <class T> add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
|
|
|
|
| 411 |
```
|
| 412 |
|
| 413 |
*Remarks:* If this function is odr-used ([[basic.def.odr]]), the
|
| 414 |
program is ill-formed.
|
| 415 |
|
| 416 |
*Remarks:* The template parameter `T` of `declval` may be an incomplete
|
| 417 |
type.
|
| 418 |
|
| 419 |
+
[*Example 1*:
|
| 420 |
+
|
| 421 |
``` cpp
|
| 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 |
+
### Primitive numeric output conversion <a id="utility.to.chars">[[utility.to.chars]]</a>
|
| 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 |
+
to_chars_result to_chars(char* first, char* last, see below value, int base = 10);
|
| 462 |
+
```
|
| 463 |
+
|
| 464 |
+
*Requires:* `base` has a value between 2 and 36 (inclusive).
|
| 465 |
+
|
| 466 |
+
*Effects:* The value of `value` is converted to a string of digits in
|
| 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 |
+
to_chars_result to_chars(char* first, char* last, float value);
|
| 478 |
+
to_chars_result to_chars(char* first, char* last, double value);
|
| 479 |
+
to_chars_result to_chars(char* first, char* last, long double value);
|
| 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 |
+
to_chars_result to_chars(char* first, char* last, float value, chars_format fmt);
|
| 491 |
+
to_chars_result to_chars(char* first, char* last, double value, chars_format fmt);
|
| 492 |
+
to_chars_result to_chars(char* first, char* last, long double value, chars_format fmt);
|
| 493 |
+
```
|
| 494 |
+
|
| 495 |
+
*Requires:* `fmt` has the value of one of the enumerators of
|
| 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 |
+
to_chars_result to_chars(char* first, char* last, float value,
|
| 505 |
+
chars_format fmt, int precision);
|
| 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 |
+
*Requires:* `fmt` has the value of one of the enumerators of
|
| 513 |
+
`chars_format`.
|
| 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 |
+
### Primitive numeric input conversion <a id="utility.from.chars">[[utility.from.chars]]</a>
|
| 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 |
+
from_chars_result from_chars(const char* first, const char* last,
|
| 540 |
+
see below& value, int base = 10);
|
| 541 |
+
```
|
| 542 |
+
|
| 543 |
+
*Requires:* `base` has a value between 2 and 36 (inclusive).
|
| 544 |
+
|
| 545 |
+
*Effects:* The pattern is the expected form of the subject sequence in
|
| 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 |
+
*Throws:* Nothing.
|
| 552 |
+
|
| 553 |
+
*Remarks:* The implementation shall provide overloads for all signed and
|
| 554 |
+
unsigned integer types and `char` as the referenced type of the
|
| 555 |
+
parameter `value`.
|
| 556 |
+
|
| 557 |
+
``` cpp
|
| 558 |
+
from_chars_result from_chars(const char* first, const char* last, float& value,
|
| 559 |
+
chars_format fmt = chars_format::general);
|
| 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 |
+
*Requires:* `fmt` has the value of one of the enumerators of
|
| 567 |
+
`chars_format`.
|
| 568 |
+
|
| 569 |
+
*Effects:* The pattern is the expected form of the subject sequence in
|
| 570 |
+
the `"C"` locale, as described for `strtod`, except that
|
| 571 |
+
|
| 572 |
+
- the only sign that may appear is a minus sign;
|
| 573 |
+
- if `fmt` has `chars_format::scientific` set but not
|
| 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 |
+
In any case, the resulting `value` is one of at most two floating-point
|
| 584 |
+
values closest to the value of the string matching the pattern.
|
| 585 |
+
|
| 586 |
+
*Throws:* Nothing.
|
| 587 |
+
|
| 588 |
+
ISO C 7.22.1.3, ISO C 7.22.1.4.
|
| 589 |
|