From Jason Turner

[specialized.algorithms]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp5wvtq9r4/{from.md → to.md} +165 -25
tmp/tmp5wvtq9r4/{from.md → to.md} RENAMED
@@ -1,90 +1,230 @@
1
  ### Specialized algorithms <a id="specialized.algorithms">[[specialized.algorithms]]</a>
2
 
3
- All the iterators that are used as template parameters in the following
4
- algorithms are required to have their `operator*` return an object for
5
- which `operator&` is defined and returns a pointer to `T`. In the
6
- algorithm `uninitialized_copy`, the template parameter `InputIterator`
7
- is required to satisfy the requirements of an input iterator (
8
- [[input.iterators]]). In all of the following algorithms, the template
9
- parameter `ForwardIterator` is required to satisfy the requirements of a
10
- forward iterator ([[forward.iterators]]), and is required to have the
 
11
  property that no exceptions are thrown from increment, assignment,
12
- comparison, or indirection through valid iterators. In the following
13
- algorithms, if an exception is thrown there are no effects.
 
 
14
 
15
  #### `addressof` <a id="specialized.addressof">[[specialized.addressof]]</a>
16
 
17
  ``` cpp
18
- template <class T> T* addressof(T& r) noexcept;
19
  ```
20
 
21
  *Returns:* The actual address of the object or function referenced by
22
  `r`, even in the presence of an overloaded `operator&`.
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  #### `uninitialized_copy` <a id="uninitialized.copy">[[uninitialized.copy]]</a>
25
 
26
  ``` cpp
27
  template <class InputIterator, class ForwardIterator>
28
  ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
29
  ForwardIterator result);
30
  ```
31
 
32
- *Effects:*
33
 
34
  ``` cpp
35
- for (; first != last; ++result, ++first)
36
- ::new (static_cast<void*>(&*result))
37
  typename iterator_traits<ForwardIterator>::value_type(*first);
38
  ```
39
 
40
- *Returns:* `result`
41
 
42
  ``` cpp
43
  template <class InputIterator, class Size, class ForwardIterator>
44
  ForwardIterator uninitialized_copy_n(InputIterator first, Size n,
45
  ForwardIterator result);
46
  ```
47
 
48
- *Effects:*
49
 
50
  ``` cpp
51
- for ( ; n > 0; ++result, ++first, --n) {
52
- ::new (static_cast<void*>(&*result))
53
  typename iterator_traits<ForwardIterator>::value_type(*first);
54
  }
55
  ```
56
 
57
- *Returns:* `result`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  #### `uninitialized_fill` <a id="uninitialized.fill">[[uninitialized.fill]]</a>
60
 
61
  ``` cpp
62
  template <class ForwardIterator, class T>
63
  void uninitialized_fill(ForwardIterator first, ForwardIterator last,
64
  const T& x);
65
  ```
66
 
67
- *Effects:*
68
 
69
  ``` cpp
70
  for (; first != last; ++first)
71
- ::new (static_cast<void*>(&*first))
72
  typename iterator_traits<ForwardIterator>::value_type(x);
73
  ```
74
 
75
- #### `uninitialized_fill_n` <a id="uninitialized.fill.n">[[uninitialized.fill.n]]</a>
76
-
77
  ``` cpp
78
  template <class ForwardIterator, class Size, class T>
79
  ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
80
  ```
81
 
82
- *Effects:*
83
 
84
  ``` cpp
85
  for (; n--; ++first)
86
- ::new (static_cast<void*>(&*first))
87
  typename iterator_traits<ForwardIterator>::value_type(x);
88
  return first;
89
  ```
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ### Specialized algorithms <a id="specialized.algorithms">[[specialized.algorithms]]</a>
2
 
3
+ Throughout this subclause, the names of template parameters are used to
4
+ express type requirements.
5
+
6
+ - If an algorithm’s template parameter is named `InputIterator`, the
7
+ template argument shall satisfy the requirements of an input
8
+ iterator ([[input.iterators]]).
9
+ - If an algorithm’s template parameter is named `ForwardIterator`, the
10
+ template argument shall satisfy the requirements of a forward
11
+ iterator ([[forward.iterators]]), and is required to have the
12
  property that no exceptions are thrown from increment, assignment,
13
+ comparison, or indirection through valid iterators.
14
+
15
+ Unless otherwise specified, if an exception is thrown in the following
16
+ algorithms there are no effects.
17
 
18
  #### `addressof` <a id="specialized.addressof">[[specialized.addressof]]</a>
19
 
20
  ``` cpp
21
+ template <class T> constexpr T* addressof(T& r) noexcept;
22
  ```
23
 
24
  *Returns:* The actual address of the object or function referenced by
25
  `r`, even in the presence of an overloaded `operator&`.
26
 
27
+ *Remarks:* An expression `addressof(E)` is a constant
28
+ subexpression ([[defns.const.subexpr]]) if `E` is an lvalue constant
29
+ subexpression.
30
+
31
+ #### `uninitialized_default_construct` <a id="uninitialized.construct.default">[[uninitialized.construct.default]]</a>
32
+
33
+ ``` cpp
34
+ template <class ForwardIterator>
35
+ void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
36
+ ```
37
+
38
+ *Effects:* Equivalent to:
39
+
40
+ ``` cpp
41
+ for (; first != last; ++first)
42
+ ::new (static_cast<void*>(addressof(*first)))
43
+ typename iterator_traits<ForwardIterator>::value_type;
44
+ ```
45
+
46
+ ``` cpp
47
+ template <class ForwardIterator, class Size>
48
+ ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
49
+ ```
50
+
51
+ *Effects:* Equivalent to:
52
+
53
+ ``` cpp
54
+ for (; n>0; (void)++first, --n)
55
+ ::new (static_cast<void*>(addressof(*first)))
56
+ typename iterator_traits<ForwardIterator>::value_type;
57
+ return first;
58
+ ```
59
+
60
+ #### `uninitialized_value_construct` <a id="uninitialized.construct.value">[[uninitialized.construct.value]]</a>
61
+
62
+ ``` cpp
63
+ template <class ForwardIterator>
64
+ void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
65
+ ```
66
+
67
+ *Effects:* Equivalent to:
68
+
69
+ ``` cpp
70
+ for (; first != last; ++first)
71
+ ::new (static_cast<void*>(addressof(*first)))
72
+ typename iterator_traits<ForwardIterator>::value_type();
73
+ ```
74
+
75
+ ``` cpp
76
+ template <class ForwardIterator, class Size>
77
+ ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
78
+ ```
79
+
80
+ *Effects:* Equivalent to:
81
+
82
+ ``` cpp
83
+ for (; n>0; (void)++first, --n)
84
+ ::new (static_cast<void*>(addressof(*first)))
85
+ typename iterator_traits<ForwardIterator>::value_type();
86
+ return first;
87
+ ```
88
+
89
  #### `uninitialized_copy` <a id="uninitialized.copy">[[uninitialized.copy]]</a>
90
 
91
  ``` cpp
92
  template <class InputIterator, class ForwardIterator>
93
  ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
94
  ForwardIterator result);
95
  ```
96
 
97
+ *Effects:* As if by:
98
 
99
  ``` cpp
100
+ for (; first != last; ++result, (void) ++first)
101
+ ::new (static_cast<void*>(addressof(*result)))
102
  typename iterator_traits<ForwardIterator>::value_type(*first);
103
  ```
104
 
105
+ *Returns:* `result`.
106
 
107
  ``` cpp
108
  template <class InputIterator, class Size, class ForwardIterator>
109
  ForwardIterator uninitialized_copy_n(InputIterator first, Size n,
110
  ForwardIterator result);
111
  ```
112
 
113
+ *Effects:* As if by:
114
 
115
  ``` cpp
116
+ for ( ; n > 0; ++result, (void) ++first, --n) {
117
+ ::new (static_cast<void*>(addressof(*result)))
118
  typename iterator_traits<ForwardIterator>::value_type(*first);
119
  }
120
  ```
121
 
122
+ *Returns:* `result`.
123
+
124
+ #### `uninitialized_move` <a id="uninitialized.move">[[uninitialized.move]]</a>
125
+
126
+ ``` cpp
127
+ template <class InputIterator, class ForwardIterator>
128
+ ForwardIterator uninitialized_move(InputIterator first, InputIterator last,
129
+ ForwardIterator result);
130
+ ```
131
+
132
+ *Effects:* Equivalent to:
133
+
134
+ ``` cpp
135
+ for (; first != last; (void)++result, ++first)
136
+ ::new (static_cast<void*>(addressof(*result)))
137
+ typename iterator_traits<ForwardIterator>::value_type(std::move(*first));
138
+ return result;
139
+ ```
140
+
141
+ *Remarks:* If an exception is thrown, some objects in the range
142
+ \[`first`, `last`) are left in a valid but unspecified state.
143
+
144
+ ``` cpp
145
+ template <class InputIterator, class Size, class ForwardIterator>
146
+ pair<InputIterator, ForwardIterator>
147
+ uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
148
+ ```
149
+
150
+ *Effects:* Equivalent to:
151
+
152
+ ``` cpp
153
+ for (; n > 0; ++result, (void) ++first, --n)
154
+ ::new (static_cast<void*>(addressof(*result)))
155
+ typename iterator_traits<ForwardIterator>::value_type(std::move(*first));
156
+ return {first,result};
157
+ ```
158
+
159
+ *Remarks:* If an exception is thrown, some objects in the range
160
+ \[`first`, `std::next(first,n)`) are left in a valid but unspecified
161
+ state.
162
 
163
  #### `uninitialized_fill` <a id="uninitialized.fill">[[uninitialized.fill]]</a>
164
 
165
  ``` cpp
166
  template <class ForwardIterator, class T>
167
  void uninitialized_fill(ForwardIterator first, ForwardIterator last,
168
  const T& x);
169
  ```
170
 
171
+ *Effects:* As if by:
172
 
173
  ``` cpp
174
  for (; first != last; ++first)
175
+ ::new (static_cast<void*>(addressof(*first)))
176
  typename iterator_traits<ForwardIterator>::value_type(x);
177
  ```
178
 
 
 
179
  ``` cpp
180
  template <class ForwardIterator, class Size, class T>
181
  ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
182
  ```
183
 
184
+ *Effects:* As if by:
185
 
186
  ``` cpp
187
  for (; n--; ++first)
188
+ ::new (static_cast<void*>(addressof(*first)))
189
  typename iterator_traits<ForwardIterator>::value_type(x);
190
  return first;
191
  ```
192
 
193
+ #### `destroy` <a id="specialized.destroy">[[specialized.destroy]]</a>
194
+
195
+ ``` cpp
196
+ template <class T>
197
+ void destroy_at(T* location);
198
+ ```
199
+
200
+ *Effects:* Equivalent to:
201
+
202
+ ``` cpp
203
+ location->~T();
204
+ ```
205
+
206
+ ``` cpp
207
+ template <class ForwardIterator>
208
+ void destroy(ForwardIterator first, ForwardIterator last);
209
+ ```
210
+
211
+ *Effects:* Equivalent to:
212
+
213
+ ``` cpp
214
+ for (; first!=last; ++first)
215
+ destroy_at(addressof(*first));
216
+ ```
217
+
218
+ ``` cpp
219
+ template <class ForwardIterator, class Size>
220
+ ForwardIterator destroy_n(ForwardIterator first, Size n);
221
+ ```
222
+
223
+ *Effects:* Equivalent to:
224
+
225
+ ``` cpp
226
+ for (; n > 0; (void)++first, --n)
227
+ destroy_at(addressof(*first));
228
+ return first;
229
+ ```
230
+