From Jason Turner

[utility]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpgubbf461/{from.md → to.md} +78 -29
tmp/tmpgubbf461/{from.md → to.md} RENAMED
@@ -23,63 +23,98 @@ namespace std {
23
 
24
  // [utility.swap], swap:
25
  template<class T> void swap(T& a, T& b) noexcept(see below);
26
  template <class T, size_t N> void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
27
 
 
 
 
28
  // [forward], forward/move:
29
- template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept;
30
- template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept;
31
- template <class T> typename remove_reference<T>::type&& move(T&&) noexcept;
32
- template <class T> typename conditional<
 
 
 
 
33
  !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
34
- const T&, T&&>::type move_if_noexcept(T& x) noexcept;
35
 
36
  // [declval], declval:
37
  template <class T>
38
- typename add_rvalue_reference<T>::type declval() noexcept; // as unevaluated operand
39
 
40
  // [pairs], pairs:
41
  template <class T1, class T2> struct pair;
42
 
43
  // [pairs.spec], pair specialized algorithms:
44
  template <class T1, class T2>
45
- bool operator==(const pair<T1,T2>&, const pair<T1,T2>&);
46
  template <class T1, class T2>
47
- bool operator< (const pair<T1,T2>&, const pair<T1,T2>&);
48
  template <class T1, class T2>
49
- bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&);
50
  template <class T1, class T2>
51
- bool operator> (const pair<T1,T2>&, const pair<T1,T2>&);
52
  template <class T1, class T2>
53
- bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&);
54
  template <class T1, class T2>
55
- bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&);
56
  template <class T1, class T2>
57
  void swap(pair<T1,T2>& x, pair<T1,T2>& y) noexcept(noexcept(x.swap(y)));
58
  template <class T1, class T2>
59
- see below make_pair(T1&&, T2&&);
60
 
61
  // [pair.astuple], tuple-like access to pair:
62
  template <class T> class tuple_size;
63
  template <size_t I, class T> class tuple_element;
64
 
65
- template <class T1, class T2> struct tuple_size<std::pair<T1, T2> >;
66
- template <class T1, class T2> struct tuple_element<0, std::pair<T1, T2> >;
67
- template <class T1, class T2> struct tuple_element<1, std::pair<T1, T2> >;
68
 
69
  template<size_t I, class T1, class T2>
70
- typename tuple_element<I, std::pair<T1, T2> >::type& get(std::pair<T1, T2>&) noexcept;
 
71
  template<size_t I, class T1, class T2>
72
- typename tuple_element<I, std::pair<T1, T2> >::type&& get(std::pair<T1, T2>&&) noexcept;
 
73
  template<size_t I, class T1, class T2>
74
- const typename tuple_element<I, std::pair<T1, T2> >::type&
75
- get(const std::pair<T1, T2>&) noexcept;
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  // [pair.piecewise], pair piecewise construction
78
  struct piecewise_construct_t { };
79
- constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
80
  template <class... Types> class tuple; // defined in <tuple>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
82
  ```
83
 
84
  ### Operators <a id="operators">[[operators]]</a>
85
 
@@ -155,24 +190,38 @@ template<class T, size_t N>
155
  *Requires:* `a[i]` shall be swappable with ([[swappable.requirements]])
156
  `b[i]` for all `i` in the range \[`0`, `N`).
157
 
158
  *Effects:* `swap_ranges(a, a + N, b)`
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  ### forward/move helpers <a id="forward">[[forward]]</a>
161
 
162
  The library provides templated helper functions to simplify applying
163
  move semantics to an lvalue and to simplify the implementation of
164
  forwarding functions.
165
 
166
  ``` cpp
167
- template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept;
168
- template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept;
169
  ```
170
 
171
  *Returns:* `static_cast<T&&>(t)`.
172
 
173
- if the second form is instantiated with an lvalue reference type, the
174
  program is ill-formed.
175
 
176
  ``` cpp
177
  template <class T, class A1, class A2>
178
  shared_ptr<T> factory(A1&& a1, A2&& a2) {
@@ -195,14 +244,14 @@ forwarded to `A`’s constructor as an rvalue. In the second call to
195
  `factory`, `A1` is deduced as `int&`, so `i` is forwarded to `A`’s
196
  constructor as an lvalue. In both cases, `A2` is deduced as `double`, so
197
  1.414 is forwarded to `A`’s constructor as an rvalue.
198
 
199
  ``` cpp
200
- template <class T> typename remove_reference<T>::type&& move(T&& t) noexcept;
201
  ```
202
 
203
- *Returns:* `static_cast<typename remove_reference<T>::type&&>(t)`.
204
 
205
  ``` cpp
206
  template <class T, class A1>
207
  shared_ptr<T> factory(A1&& a1) {
208
  return shared_ptr<T>(new T(std::forward<A1>(a1)));
@@ -227,13 +276,13 @@ forwarded as a non-const lvalue. This binds to the constructor
227
  `factory`, because of the call `std::move(a)`, `A1` is deduced as `A`,
228
  so `a` is forwarded as an rvalue. This binds to the constructor
229
  `A(A&&)`, which moves the value from `a`.
230
 
231
  ``` cpp
232
- template <class T> typename conditional<
233
  !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
234
- const T&, T&&>::type move_if_noexcept(T& x) noexcept;
235
  ```
236
 
237
  *Returns:* `std::move(x)`
238
 
239
  ### Function template `declval` <a id="declval">[[declval]]</a>
@@ -242,11 +291,11 @@ The library provides the function template `declval` to simplify the
242
  definition of expressions which occur as unevaluated operands (Clause 
243
  [[expr]]).
244
 
245
  ``` cpp
246
  template <class T>
247
- typename add_rvalue_reference<T>::type declval() noexcept; // as unevaluated operand
248
  ```
249
 
250
  *Remarks:* If this function is odr-used ([[basic.def.odr]]), the
251
  program is ill-formed.
252
 
 
23
 
24
  // [utility.swap], swap:
25
  template<class T> void swap(T& a, T& b) noexcept(see below);
26
  template <class T, size_t N> void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
27
 
28
+ // [utility.exchange], exchange:
29
+ template <class T, class U=T> T exchange(T& obj, U&& new_val);
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
  !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
41
+ const T&, T&&> move_if_noexcept(T& x) noexcept;
42
 
43
  // [declval], declval:
44
  template <class T>
45
+ add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
46
 
47
  // [pairs], pairs:
48
  template <class T1, class T2> struct pair;
49
 
50
  // [pairs.spec], pair specialized algorithms:
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>
56
+ constexpr bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&);
57
  template <class T1, class T2>
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
+ get(const pair<T1, T2>&) noexcept;
85
+ template <class T, class U>
86
+ constexpr T& get(pair<T, U>& p) noexcept;
87
+ template <class T, class U>
88
+ constexpr const T& get(const pair<T, U>& p) noexcept;
89
+ template <class T, class U>
90
+ constexpr T&& get(pair<T, U>&& p) noexcept;
91
+ template <class T, class U>
92
+ constexpr T& get(pair<U, T>& p) noexcept;
93
+ template <class T, class U>
94
+ constexpr const T& get(const pair<U, T>& p) noexcept;
95
+ template <class T, class U>
96
+ constexpr T&& get(pair<U, T>&& p) noexcept;
97
 
98
  // [pair.piecewise], pair piecewise construction
99
  struct piecewise_construct_t { };
100
+ constexpr piecewise_construct_t piecewise_construct{};
101
  template <class... Types> class tuple; // defined in <tuple>
102
+
103
+
104
+ // [intseq], Compile-time integer sequences
105
+ template<class T, T...> struct integer_sequence;
106
+ template<size_t... I>
107
+ using index_sequence = integer_sequence<size_t, I...>;
108
+
109
+ template<class T, T N>
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
+ template<class... T>
115
+ using index_sequence_for = make_index_sequence<sizeof...(T)>;
116
  }
117
  ```
118
 
119
  ### Operators <a id="operators">[[operators]]</a>
120
 
 
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
+
201
+ *Effects:* Equivalent to:
202
+
203
+ ``` cpp
204
+ T old_val = std::move(obj);
205
+ obj = std::forward<U>(new_val);
206
+ return old_val;
207
+ ```
208
+
209
  ### forward/move helpers <a id="forward">[[forward]]</a>
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 type, the
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) {
 
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)));
 
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
  !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
283
+ const T&, T&&> move_if_noexcept(T& x) noexcept;
284
  ```
285
 
286
  *Returns:* `std::move(x)`
287
 
288
  ### Function template `declval` <a id="declval">[[declval]]</a>
 
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