From Jason Turner

[template.valarray]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp6m104vf0/{from.md → to.md} +265 -204
tmp/tmp6m104vf0/{from.md → to.md} RENAMED
@@ -4,13 +4,13 @@
4
 
5
  ``` cpp
6
  namespace std {
7
  template<class T> class valarray {
8
  public:
9
- typedef T value_type;
10
 
11
- // [valarray.cons] construct/destroy:
12
  valarray();
13
  explicit valarray(size_t);
14
  valarray(const T&, size_t);
15
  valarray(const T*, size_t);
16
  valarray(const valarray&);
@@ -20,149 +20,151 @@ namespace std {
20
  valarray(const mask_array<T>&);
21
  valarray(const indirect_array<T>&);
22
  valarray(initializer_list<T>);
23
  ~valarray();
24
 
25
- // [valarray.assign] assignment:
26
- valarray<T>& operator=(const valarray<T>&);
27
- valarray<T>& operator=(valarray<T>&&) noexcept;
28
  valarray& operator=(initializer_list<T>);
29
- valarray<T>& operator=(const T&);
30
- valarray<T>& operator=(const slice_array<T>&);
31
- valarray<T>& operator=(const gslice_array<T>&);
32
- valarray<T>& operator=(const mask_array<T>&);
33
- valarray<T>& operator=(const indirect_array<T>&);
34
 
35
- // [valarray.access] element access:
36
  const T& operator[](size_t) const;
37
  T& operator[](size_t);
38
 
39
- // [valarray.sub] subset operations:
40
- valarray<T> operator[](slice) const;
41
  slice_array<T> operator[](slice);
42
- valarray<T> operator[](const gslice&) const;
43
  gslice_array<T> operator[](const gslice&);
44
- valarray<T> operator[](const valarray<bool>&) const;
45
  mask_array<T> operator[](const valarray<bool>&);
46
- valarray<T> operator[](const valarray<size_t>&) const;
47
  indirect_array<T> operator[](const valarray<size_t>&);
48
 
49
- // [valarray.unary] unary operators:
50
- valarray<T> operator+() const;
51
- valarray<T> operator-() const;
52
- valarray<T> operator~() const;
53
  valarray<bool> operator!() const;
54
 
55
- // [valarray.cassign] computed assignment:
56
- valarray<T>& operator*= (const T&);
57
- valarray<T>& operator/= (const T&);
58
- valarray<T>& operator%= (const T&);
59
- valarray<T>& operator+= (const T&);
60
- valarray<T>& operator-= (const T&);
61
- valarray<T>& operator^= (const T&);
62
- valarray<T>& operator&= (const T&);
63
- valarray<T>& operator|= (const T&);
64
- valarray<T>& operator<<=(const T&);
65
- valarray<T>& operator>>=(const T&);
66
 
67
- valarray<T>& operator*= (const valarray<T>&);
68
- valarray<T>& operator/= (const valarray<T>&);
69
- valarray<T>& operator%= (const valarray<T>&);
70
- valarray<T>& operator+= (const valarray<T>&);
71
- valarray<T>& operator-= (const valarray<T>&);
72
- valarray<T>& operator^= (const valarray<T>&);
73
- valarray<T>& operator|= (const valarray<T>&);
74
- valarray<T>& operator&= (const valarray<T>&);
75
- valarray<T>& operator<<=(const valarray<T>&);
76
- valarray<T>& operator>>=(const valarray<T>&);
77
 
78
- // [valarray.members] member functions:
79
  void swap(valarray&) noexcept;
80
 
81
  size_t size() const;
82
 
83
  T sum() const;
84
  T min() const;
85
  T max() const;
86
 
87
- valarray<T> shift (int) const;
88
- valarray<T> cshift(int) const;
89
- valarray<T> apply(T func(T)) const;
90
- valarray<T> apply(T func(const T&)) const;
91
  void resize(size_t sz, T c = T());
92
  };
 
 
93
  }
94
  ```
95
 
96
  The class template `valarray<T>` is a one-dimensional smart array, with
97
  elements numbered sequentially from zero. It is a representation of the
98
- mathematical concept of an ordered set of values. The illusion of higher
99
- dimensionality may be produced by the familiar idiom of computed
100
- indices, together with the powerful subsetting capabilities provided by
101
- the generalized subscript operators.[^8]
 
 
102
 
103
  An implementation is permitted to qualify any of the functions declared
104
  in `<valarray>` as `inline`.
105
 
106
  #### `valarray` constructors <a id="valarray.cons">[[valarray.cons]]</a>
107
 
108
  ``` cpp
109
  valarray();
110
  ```
111
 
112
- *Effects:* Constructs an object of class `valarray<T>`[^9] which has
113
- zero length.[^10]
114
 
115
  ``` cpp
116
- explicit valarray(size_t);
117
  ```
118
 
119
- The array created by this constructor has a length equal to the value of
120
- the argument. The elements of the array are
121
- value-initialized ([[dcl.init]]).
122
 
123
  ``` cpp
124
- valarray(const T&, size_t);
125
  ```
126
 
127
- The array created by this constructor has a length equal to the second
128
- argument. The elements of the array are initialized with the value of
129
- the first argument.
130
 
131
  ``` cpp
132
- valarray(const T*, size_t);
133
  ```
134
 
135
- The array created by this constructor has a length equal to the second
136
- argument `n`. The values of the elements of the array are initialized
137
- with the first `n` values pointed to by the first argument.[^11] If the
138
- value of the second argument is greater than the number of values
139
- pointed to by the first argument, the behavior is undefined.
 
140
 
141
  ``` cpp
142
- valarray(const valarray<T>&);
143
  ```
144
 
145
- The array created by this constructor has the same length as the
146
- argument array. The elements are initialized with the values of the
147
- corresponding elements of the argument array.[^12]
148
 
149
  ``` cpp
150
- valarray(valarray<T>&& v) noexcept;
151
  ```
152
 
153
- The array created by this constructor has the same length as the
154
- argument array. The elements are initialized with the values of the
155
- corresponding elements of the argument array.
156
 
157
  *Complexity:* Constant.
158
 
159
  ``` cpp
160
  valarray(initializer_list<T> il);
161
  ```
162
 
163
- *Effects:* Same as `valarray(il.begin(), il.size())`.
164
 
165
  ``` cpp
166
  valarray(const slice_array<T>&);
167
  valarray(const gslice_array<T>&);
168
  valarray(const mask_array<T>&);
@@ -174,101 +176,103 @@ templates to a `valarray`.
174
 
175
  ``` cpp
176
  ~valarray();
177
  ```
178
 
179
- The destructor is applied to every element of `*this`; an implementation
180
- may return all allocated memory.
181
 
182
  #### `valarray` assignment <a id="valarray.assign">[[valarray.assign]]</a>
183
 
184
  ``` cpp
185
- valarray<T>& operator=(const valarray<T>& v);
186
  ```
187
 
188
- Each element of the `*this` array is assigned the value of the
189
- corresponding element of the argument array. If the length of `v` is not
190
- equal to the length of `*this` , resizes `*this` to make the two arrays
191
- the same length, as if by calling `resize(v.size())`, before performing
192
- the assignment.
193
 
194
- `size() == v.size()`.
 
 
195
 
196
  ``` cpp
197
- valarray<T>& operator=(valarray<T>&& v) noexcept;
198
  ```
199
 
200
  *Effects:* `*this` obtains the value of `v`. The value of `v` after the
201
  assignment is not specified.
202
 
 
 
203
  *Complexity:* Linear.
204
 
205
  ``` cpp
206
  valarray& operator=(initializer_list<T> il);
207
  ```
208
 
209
- *Effects:* `*this = valarray(il)`.
210
-
211
- *Returns:* `*this`.
212
 
213
  ``` cpp
214
- valarray<T>& operator=(const T&);
215
  ```
216
 
217
- The scalar assignment operator causes each element of the `*this` array
218
- to be assigned the value of the argument.
 
219
 
220
  ``` cpp
221
- valarray<T>& operator=(const slice_array<T>&);
222
- valarray<T>& operator=(const gslice_array<T>&);
223
- valarray<T>& operator=(const mask_array<T>&);
224
- valarray<T>& operator=(const indirect_array<T>&);
225
  ```
226
 
227
  *Requires:* The length of the array to which the argument refers equals
228
- `size()`.
 
 
229
 
230
  These operators allow the results of a generalized subscripting
231
  operation to be assigned directly to a `valarray`.
232
 
233
- If the value of an element in the left-hand side of a valarray
234
- assignment operator depends on the value of another element in that
235
- left-hand side, the resulting behavior is undefined.
236
-
237
  #### `valarray` element access <a id="valarray.access">[[valarray.access]]</a>
238
 
239
  ``` cpp
240
- const T& operator[](size_t) const;
241
- T& operator[](size_t);
242
  ```
243
 
244
- The subscript operator returns a reference to the corresponding element
245
- of the array.
246
 
247
- Thus, the expression `(a[i] = q, a[i]) == q` evaluates as true for any
248
- non-constant `valarray<T> a`, any `T q`, and for any `size_t i` such
249
- that the value of `i` is less than the length of `a`.
250
 
251
- The expression `&a[i+j] == &a[i] + j` evaluates as true for all
252
- `size_t i` and `size_t j` such that `i+j` is less than the length of the
253
- array `a`.
 
254
 
255
- Likewise, the expression `&a[i] != &b[j]` evaluates as `true` for any
256
- two arrays `a` and `b` and for any `size_t i` and `size_t j` such that
257
- `i` is less than the length of `a` and `j` is less than the length of
258
- `b`. This property indicates an absence of aliasing and may be used to
259
- advantage by optimizing compilers.[^13]
 
 
 
 
 
 
 
260
 
261
  The reference returned by the subscript operator for an array shall be
262
  valid until the member function
263
  `resize(size_t, T)` ([[valarray.members]]) is called for that array or
264
  until the lifetime of that array ends, whichever happens first.
265
 
266
- If the subscript operator is invoked with a `size_t` argument whose
267
- value is not less than the length of the array, the behavior is
268
- undefined.
269
-
270
  #### `valarray` subset operations <a id="valarray.sub">[[valarray.sub]]</a>
271
 
272
  The member `operator[]` is overloaded to provide several ways to select
273
  sequences of elements from among those controlled by `*this`. Each of
274
  these operations returns a subset of the array. The const-qualified
@@ -278,200 +282,231 @@ the original array, working in conjunction with various overloads of
278
  `operator=` and other assigning operators to allow selective replacement
279
  (slicing) of the controlled sequence. In each case the selected
280
  element(s) must exist.
281
 
282
  ``` cpp
283
- valarray<T> operator[](slice slicearr) const;
284
  ```
285
 
286
- *Returns:* An object of class `valarray<T>` containing those elements of
287
- the controlled sequence designated by `slicearr`.
 
 
288
 
289
  ``` cpp
290
  const valarray<char> v0("abcdefghijklmnop", 16);
291
  // v0[slice(2, 5, 3)] returns valarray<char>("cfilo", 5)
292
  ```
293
 
 
 
294
  ``` cpp
295
  slice_array<T> operator[](slice slicearr);
296
  ```
297
 
298
  *Returns:* An object that holds references to elements of the controlled
299
  sequence selected by `slicearr`.
300
 
 
 
301
  ``` cpp
302
  valarray<char> v0("abcdefghijklmnop", 16);
303
  valarray<char> v1("ABCDE", 5);
304
  v0[slice(2, 5, 3)] = v1;
305
  // v0 == valarray<char>("abAdeBghCjkDmnEp", 16);
306
  ```
307
 
 
 
308
  ``` cpp
309
- valarray<T> operator[](const gslice& gslicearr) const;
310
  ```
311
 
312
- *Returns:* An object of class `valarray<T>` containing those elements of
313
- the controlled sequence designated by `gslicearr`.
 
 
314
 
315
  ``` cpp
316
  const valarray<char> v0("abcdefghijklmnop", 16);
317
  const size_t lv[] = { 2, 3 };
318
  const size_t dv[] = { 7, 2 };
319
  const valarray<size_t> len(lv, 2), str(dv, 2);
320
  // v0[gslice(3, len, str)] returns
321
  // valarray<char>("dfhkmo", 6)
322
  ```
323
 
 
 
324
  ``` cpp
325
  gslice_array<T> operator[](const gslice& gslicearr);
326
  ```
327
 
328
  *Returns:* An object that holds references to elements of the controlled
329
  sequence selected by `gslicearr`.
330
 
 
 
331
  ``` cpp
332
  valarray<char> v0("abcdefghijklmnop", 16);
333
- valarray<char> v1("ABCDE", 5);
334
  const size_t lv[] = { 2, 3 };
335
  const size_t dv[] = { 7, 2 };
336
  const valarray<size_t> len(lv, 2), str(dv, 2);
337
  v0[gslice(3, len, str)] = v1;
338
  // v0 == valarray<char>("abcAeBgCijDlEnFp", 16)
339
  ```
340
 
 
 
341
  ``` cpp
342
- valarray<T> operator[](const valarray<bool>& boolarr) const;
343
  ```
344
 
345
- *Returns:* An object of class `valarray<T>` containing those elements of
346
- the controlled sequence designated by `boolarr`.
 
 
347
 
348
  ``` cpp
349
  const valarray<char> v0("abcdefghijklmnop", 16);
350
  const bool vb[] = { false, false, true, true, false, true };
351
  // v0[valarray<bool>(vb, 6)] returns
352
  // valarray<char>("cdf", 3)
353
  ```
354
 
 
 
355
  ``` cpp
356
  mask_array<T> operator[](const valarray<bool>& boolarr);
357
  ```
358
 
359
  *Returns:* An object that holds references to elements of the controlled
360
  sequence selected by `boolarr`.
361
 
 
 
362
  ``` cpp
363
  valarray<char> v0("abcdefghijklmnop", 16);
364
  valarray<char> v1("ABC", 3);
365
  const bool vb[] = { false, false, true, true, false, true };
366
  v0[valarray<bool>(vb, 6)] = v1;
367
  // v0 == valarray<char>("abABeCghijklmnop", 16)
368
  ```
369
 
 
 
370
  ``` cpp
371
- valarray<T> operator[](const valarray<size_t>& indarr) const;
372
  ```
373
 
374
- *Returns:* An object of class `valarray<T>` containing those elements of
375
- the controlled sequence designated by `indarr`.
 
 
376
 
377
  ``` cpp
378
  const valarray<char> v0("abcdefghijklmnop", 16);
379
  const size_t vi[] = { 7, 5, 2, 3, 8 };
380
  // v0[valarray<size_t>(vi, 5)] returns
381
  // valarray<char>("hfcdi", 5)
382
  ```
383
 
 
 
384
  ``` cpp
385
  indirect_array<T> operator[](const valarray<size_t>& indarr);
386
  ```
387
 
388
  *Returns:* An object that holds references to elements of the controlled
389
  sequence selected by `indarr`.
390
 
 
 
391
  ``` cpp
392
  valarray<char> v0("abcdefghijklmnop", 16);
393
  valarray<char> v1("ABCDE", 5);
394
  const size_t vi[] = { 7, 5, 2, 3, 8 };
395
  v0[valarray<size_t>(vi, 5)] = v1;
396
  // v0 == valarray<char>("abCDeBgAEjklmnop", 16)
397
  ```
398
 
 
 
399
  #### `valarray` unary operators <a id="valarray.unary">[[valarray.unary]]</a>
400
 
401
  ``` cpp
402
- valarray<T> operator+() const;
403
- valarray<T> operator-() const;
404
- valarray<T> operator~() const;
405
  valarray<bool> operator!() const;
406
  ```
407
 
408
- Each of these operators may only be instantiated for a type `T` to which
409
- the indicated operator can be applied and for which the indicated
410
- operator returns a value which is of type `T` (`bool` for `operator!`)
411
- or which may be unambiguously implicitly converted to type `T` (`bool`
412
- for `operator!`).
413
 
414
- Each of these operators returns an array whose length is equal to the
415
- length of the array. Each element of the returned array is initialized
416
- with the result of applying the indicated operator to the corresponding
417
- element of the array.
418
 
419
- #### `valarray` computed assignment <a id="valarray.cassign">[[valarray.cassign]]</a>
420
 
421
  ``` cpp
422
- valarray<T>& operator*= (const valarray<T>&);
423
- valarray<T>& operator/= (const valarray<T>&);
424
- valarray<T>& operator%= (const valarray<T>&);
425
- valarray<T>& operator+= (const valarray<T>&);
426
- valarray<T>& operator-= (const valarray<T>&);
427
- valarray<T>& operator^= (const valarray<T>&);
428
- valarray<T>& operator&= (const valarray<T>&);
429
- valarray<T>& operator|= (const valarray<T>&);
430
- valarray<T>& operator<<=(const valarray<T>&);
431
- valarray<T>& operator>>=(const valarray<T>&);
432
  ```
433
 
434
- Each of these operators may only be instantiated for a type `T` to which
435
- the indicated operator can be applied. Each of these operators performs
436
- the indicated operation on each of its elements and the corresponding
437
- element of the argument array.
 
438
 
439
- The array is then returned by reference.
 
440
 
441
- If the array and the argument array do not have the same length, the
442
- behavior is undefined. The appearance of an array on the left-hand side
443
- of a computed assignment does `not` invalidate references or pointers.
444
 
445
- If the value of an element in the left-hand side of a valarray computed
446
- assignment operator depends on the value of another element in that left
447
- hand side, the resulting behavior is undefined.
448
 
449
  ``` cpp
450
- valarray<T>& operator*= (const T&);
451
- valarray<T>& operator/= (const T&);
452
- valarray<T>& operator%= (const T&);
453
- valarray<T>& operator+= (const T&);
454
- valarray<T>& operator-= (const T&);
455
- valarray<T>& operator^= (const T&);
456
- valarray<T>& operator&= (const T&);
457
- valarray<T>& operator|= (const T&);
458
- valarray<T>& operator<<=(const T&);
459
- valarray<T>& operator>>=(const T&);
460
  ```
461
 
462
- Each of these operators may only be instantiated for a type `T` to which
463
- the indicated operator can be applied.
 
464
 
465
- Each of these operators applies the indicated operation to each element
466
- of the array and the non-array argument.
467
 
468
- The array is then returned by reference.
469
 
470
- The appearance of an array on the left-hand side of a computed
471
- assignment does *not* invalidate references or pointers to the elements
472
- of the array.
473
 
474
  #### `valarray` member functions <a id="valarray.members">[[valarray.members]]</a>
475
 
476
  ``` cpp
477
  void swap(valarray& v) noexcept;
@@ -492,50 +527,76 @@ size_t size() const;
492
 
493
  ``` cpp
494
  T sum() const;
495
  ```
496
 
497
- This function may only be instantiated for a type `T` to which
498
- `operator+=` can be applied. This function returns the sum of all the
499
- elements of the array.
500
 
501
- If the array has length 0, the behavior is undefined. If the array has
502
- length 1, `sum()` returns the value of element 0. Otherwise, the
503
- returned value is calculated by applying `operator+=` to a copy of an
504
- element of the array and all other elements of the array in an
505
- unspecified order.
506
 
507
  ``` cpp
508
  T min() const;
509
  ```
510
 
511
- This function returns the minimum value contained in `*this`. The value
512
- returned for an array of length 0 is undefined. For an array of length
513
- 1, the value of element 0 is returned. For all other array lengths, the
514
- determination is made using `operator<`.
 
515
 
516
  ``` cpp
517
  T max() const;
518
  ```
519
 
520
- This function returns the maximum value contained in `*this`. The value
521
- returned for an array of length 0 is undefined. For an array of length
522
- 1, the value of element 0 is returned. For all other array lengths, the
523
- determination is made using `operator<`.
 
524
 
525
  ``` cpp
526
- valarray<T> shift(int n) const;
527
  ```
528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
  ``` cpp
530
- valarray<T> cshift(int n) const;
531
  ```
532
 
 
 
 
 
 
533
  ``` cpp
534
- valarray<T> apply(T func(T)) const;
535
- valarray<T> apply(T func(const T&)) const;
536
  ```
537
 
 
 
 
 
538
  ``` cpp
539
  void resize(size_t sz, T c = T());
540
  ```
541
 
 
 
 
 
 
4
 
5
  ``` cpp
6
  namespace std {
7
  template<class T> class valarray {
8
  public:
9
+ using value_type = T;
10
 
11
+ // [valarray.cons], construct/destroy
12
  valarray();
13
  explicit valarray(size_t);
14
  valarray(const T&, size_t);
15
  valarray(const T*, size_t);
16
  valarray(const valarray&);
 
20
  valarray(const mask_array<T>&);
21
  valarray(const indirect_array<T>&);
22
  valarray(initializer_list<T>);
23
  ~valarray();
24
 
25
+ // [valarray.assign], assignment
26
+ valarray& operator=(const valarray&);
27
+ valarray& operator=(valarray&&) noexcept;
28
  valarray& operator=(initializer_list<T>);
29
+ valarray& operator=(const T&);
30
+ valarray& operator=(const slice_array<T>&);
31
+ valarray& operator=(const gslice_array<T>&);
32
+ valarray& operator=(const mask_array<T>&);
33
+ valarray& operator=(const indirect_array<T>&);
34
 
35
+ // [valarray.access], element access
36
  const T& operator[](size_t) const;
37
  T& operator[](size_t);
38
 
39
+ // [valarray.sub], subset operations
40
+ valarray operator[](slice) const;
41
  slice_array<T> operator[](slice);
42
+ valarray operator[](const gslice&) const;
43
  gslice_array<T> operator[](const gslice&);
44
+ valarray operator[](const valarray<bool>&) const;
45
  mask_array<T> operator[](const valarray<bool>&);
46
+ valarray operator[](const valarray<size_t>&) const;
47
  indirect_array<T> operator[](const valarray<size_t>&);
48
 
49
+ // [valarray.unary], unary operators
50
+ valarray operator+() const;
51
+ valarray operator-() const;
52
+ valarray operator~() const;
53
  valarray<bool> operator!() const;
54
 
55
+ // [valarray.cassign], compound assignment
56
+ valarray& operator*= (const T&);
57
+ valarray& operator/= (const T&);
58
+ valarray& operator%= (const T&);
59
+ valarray& operator+= (const T&);
60
+ valarray& operator-= (const T&);
61
+ valarray& operator^= (const T&);
62
+ valarray& operator&= (const T&);
63
+ valarray& operator|= (const T&);
64
+ valarray& operator<<=(const T&);
65
+ valarray& operator>>=(const T&);
66
 
67
+ valarray& operator*= (const valarray&);
68
+ valarray& operator/= (const valarray&);
69
+ valarray& operator%= (const valarray&);
70
+ valarray& operator+= (const valarray&);
71
+ valarray& operator-= (const valarray&);
72
+ valarray& operator^= (const valarray&);
73
+ valarray& operator|= (const valarray&);
74
+ valarray& operator&= (const valarray&);
75
+ valarray& operator<<=(const valarray&);
76
+ valarray& operator>>=(const valarray&);
77
 
78
+ // [valarray.members], member functions
79
  void swap(valarray&) noexcept;
80
 
81
  size_t size() const;
82
 
83
  T sum() const;
84
  T min() const;
85
  T max() const;
86
 
87
+ valarray shift (int) const;
88
+ valarray cshift(int) const;
89
+ valarray apply(T func(T)) const;
90
+ valarray apply(T func(const T&)) const;
91
  void resize(size_t sz, T c = T());
92
  };
93
+
94
+ template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;
95
  }
96
  ```
97
 
98
  The class template `valarray<T>` is a one-dimensional smart array, with
99
  elements numbered sequentially from zero. It is a representation of the
100
+ mathematical concept of an ordered set of values. For convenience, an
101
+ object of type `valarray<T>` is referred to as an “array” throughout the
102
+ remainder of  [[numarray]]. The illusion of higher dimensionality may be
103
+ produced by the familiar idiom of computed indices, together with the
104
+ powerful subsetting capabilities provided by the generalized subscript
105
+ operators.[^8]
106
 
107
  An implementation is permitted to qualify any of the functions declared
108
  in `<valarray>` as `inline`.
109
 
110
  #### `valarray` constructors <a id="valarray.cons">[[valarray.cons]]</a>
111
 
112
  ``` cpp
113
  valarray();
114
  ```
115
 
116
+ *Effects:* Constructs a `valarray` that has zero length.[^9]
 
117
 
118
  ``` cpp
119
+ explicit valarray(size_t n);
120
  ```
121
 
122
+ *Effects:* Constructs a `valarray` that has length `n`. Each element of
123
+ the array is value-initialized ([[dcl.init]]).
 
124
 
125
  ``` cpp
126
+ valarray(const T& v, size_t n);
127
  ```
128
 
129
+ *Effects:* Constructs a `valarray` that has length `n`. Each element of
130
+ the array is initialized with `v`.
 
131
 
132
  ``` cpp
133
+ valarray(const T* p, size_t n);
134
  ```
135
 
136
+ *Requires:* `p` points to an array ([[dcl.array]]) of at least `n`
137
+ elements.
138
+
139
+ *Effects:* Constructs a `valarray` that has length `n`. The values of
140
+ the elements of the array are initialized with the first `n` values
141
+ pointed to by the first argument.[^10]
142
 
143
  ``` cpp
144
+ valarray(const valarray& v);
145
  ```
146
 
147
+ *Effects:* Constructs a `valarray` that has the same length as `v`. The
148
+ elements are initialized with the values of the corresponding elements
149
+ of `v`.[^11]
150
 
151
  ``` cpp
152
+ valarray(valarray&& v) noexcept;
153
  ```
154
 
155
+ *Effects:* Constructs a `valarray` that has the same length as `v`. The
156
+ elements are initialized with the values of the corresponding elements
157
+ of `v`.
158
 
159
  *Complexity:* Constant.
160
 
161
  ``` cpp
162
  valarray(initializer_list<T> il);
163
  ```
164
 
165
+ *Effects:* Equivalent to `valarray(il.begin(), il.size())`.
166
 
167
  ``` cpp
168
  valarray(const slice_array<T>&);
169
  valarray(const gslice_array<T>&);
170
  valarray(const mask_array<T>&);
 
176
 
177
  ``` cpp
178
  ~valarray();
179
  ```
180
 
181
+ *Effects:* The destructor is applied to every element of `*this`; an
182
+ implementation may return all allocated memory.
183
 
184
  #### `valarray` assignment <a id="valarray.assign">[[valarray.assign]]</a>
185
 
186
  ``` cpp
187
+ valarray& operator=(const valarray& v);
188
  ```
189
 
190
+ *Effects:* Each element of the `*this` array is assigned the value of
191
+ the corresponding element of `v`. If the length of `v` is not equal to
192
+ the length of `*this`, resizes `*this` to make the two arrays the same
193
+ length, as if by calling `resize(v.size())`, before performing the
194
+ assignment.
195
 
196
+ *Postconditions:* `size() == v.size()`.
197
+
198
+ *Returns:* `*this`.
199
 
200
  ``` cpp
201
+ valarray& operator=(valarray&& v) noexcept;
202
  ```
203
 
204
  *Effects:* `*this` obtains the value of `v`. The value of `v` after the
205
  assignment is not specified.
206
 
207
+ *Returns:* `*this`.
208
+
209
  *Complexity:* Linear.
210
 
211
  ``` cpp
212
  valarray& operator=(initializer_list<T> il);
213
  ```
214
 
215
+ *Effects:* Equivalent to: `return *this = valarray(il);`
 
 
216
 
217
  ``` cpp
218
+ valarray& operator=(const T& v);
219
  ```
220
 
221
+ *Effects:* Assigns `v` to each element of `*this`.
222
+
223
+ *Returns:* `*this`.
224
 
225
  ``` cpp
226
+ valarray& operator=(const slice_array<T>&);
227
+ valarray& operator=(const gslice_array<T>&);
228
+ valarray& operator=(const mask_array<T>&);
229
+ valarray& operator=(const indirect_array<T>&);
230
  ```
231
 
232
  *Requires:* The length of the array to which the argument refers equals
233
+ `size()`. The value of an element in the left-hand side of a `valarray`
234
+ assignment operator does not depend on the value of another element in
235
+ that left-hand side.
236
 
237
  These operators allow the results of a generalized subscripting
238
  operation to be assigned directly to a `valarray`.
239
 
 
 
 
 
240
  #### `valarray` element access <a id="valarray.access">[[valarray.access]]</a>
241
 
242
  ``` cpp
243
+ const T& operator[](size_t n) const;
244
+ T& operator[](size_t n);
245
  ```
246
 
247
+ *Requires:* `n < size()`.
 
248
 
249
+ *Returns:* A reference to the corresponding element of the array.
 
 
250
 
251
+ [*Note 1*: The expression `(a[i] = q, a[i]) == q` evaluates to `true`
252
+ for any non-constant `valarray<T> a`, any `T q`, and for any `size_t i`
253
+ such that the value of `i` is less than the length of
254
+ `a`. — *end note*]
255
 
256
+ *Remarks:* The expression `&a[i+j] == &a[i] + j` evaluates to `true` for
257
+ all `size_t i` and `size_t j` such that `i+j < a.size()`.
258
+
259
+ The expression `&a[i] != &b[j]` evaluates to `true` for any two arrays
260
+ `a` and `b` and for any `size_t i` and `size_t j` such that
261
+ `i < a.size()` and `j < b.size()`.
262
+
263
+ [*Note 2*: This property indicates an absence of aliasing and may be
264
+ used to advantage by optimizing compilers. Compilers may take advantage
265
+ of inlining, constant propagation, loop fusion, tracking of pointers
266
+ obtained from `operator new`, and other techniques to generate efficient
267
+ `valarray`s. — *end note*]
268
 
269
  The reference returned by the subscript operator for an array shall be
270
  valid until the member function
271
  `resize(size_t, T)` ([[valarray.members]]) is called for that array or
272
  until the lifetime of that array ends, whichever happens first.
273
 
 
 
 
 
274
  #### `valarray` subset operations <a id="valarray.sub">[[valarray.sub]]</a>
275
 
276
  The member `operator[]` is overloaded to provide several ways to select
277
  sequences of elements from among those controlled by `*this`. Each of
278
  these operations returns a subset of the array. The const-qualified
 
282
  `operator=` and other assigning operators to allow selective replacement
283
  (slicing) of the controlled sequence. In each case the selected
284
  element(s) must exist.
285
 
286
  ``` cpp
287
+ valarray operator[](slice slicearr) const;
288
  ```
289
 
290
+ *Returns:* A `valarray` containing those elements of the controlled
291
+ sequence designated by `slicearr`.
292
+
293
+ [*Example 1*:
294
 
295
  ``` cpp
296
  const valarray<char> v0("abcdefghijklmnop", 16);
297
  // v0[slice(2, 5, 3)] returns valarray<char>("cfilo", 5)
298
  ```
299
 
300
+ — *end example*]
301
+
302
  ``` cpp
303
  slice_array<T> operator[](slice slicearr);
304
  ```
305
 
306
  *Returns:* An object that holds references to elements of the controlled
307
  sequence selected by `slicearr`.
308
 
309
+ [*Example 2*:
310
+
311
  ``` cpp
312
  valarray<char> v0("abcdefghijklmnop", 16);
313
  valarray<char> v1("ABCDE", 5);
314
  v0[slice(2, 5, 3)] = v1;
315
  // v0 == valarray<char>("abAdeBghCjkDmnEp", 16);
316
  ```
317
 
318
+ — *end example*]
319
+
320
  ``` cpp
321
+ valarray operator[](const gslice& gslicearr) const;
322
  ```
323
 
324
+ *Returns:* A `valarray` containing those elements of the controlled
325
+ sequence designated by `gslicearr`.
326
+
327
+ [*Example 3*:
328
 
329
  ``` cpp
330
  const valarray<char> v0("abcdefghijklmnop", 16);
331
  const size_t lv[] = { 2, 3 };
332
  const size_t dv[] = { 7, 2 };
333
  const valarray<size_t> len(lv, 2), str(dv, 2);
334
  // v0[gslice(3, len, str)] returns
335
  // valarray<char>("dfhkmo", 6)
336
  ```
337
 
338
+ — *end example*]
339
+
340
  ``` cpp
341
  gslice_array<T> operator[](const gslice& gslicearr);
342
  ```
343
 
344
  *Returns:* An object that holds references to elements of the controlled
345
  sequence selected by `gslicearr`.
346
 
347
+ [*Example 4*:
348
+
349
  ``` cpp
350
  valarray<char> v0("abcdefghijklmnop", 16);
351
+ valarray<char> v1("ABCDEF", 6);
352
  const size_t lv[] = { 2, 3 };
353
  const size_t dv[] = { 7, 2 };
354
  const valarray<size_t> len(lv, 2), str(dv, 2);
355
  v0[gslice(3, len, str)] = v1;
356
  // v0 == valarray<char>("abcAeBgCijDlEnFp", 16)
357
  ```
358
 
359
+ — *end example*]
360
+
361
  ``` cpp
362
+ valarray operator[](const valarray<bool>& boolarr) const;
363
  ```
364
 
365
+ *Returns:* A `valarray` containing those elements of the controlled
366
+ sequence designated by `boolarr`.
367
+
368
+ [*Example 5*:
369
 
370
  ``` cpp
371
  const valarray<char> v0("abcdefghijklmnop", 16);
372
  const bool vb[] = { false, false, true, true, false, true };
373
  // v0[valarray<bool>(vb, 6)] returns
374
  // valarray<char>("cdf", 3)
375
  ```
376
 
377
+ — *end example*]
378
+
379
  ``` cpp
380
  mask_array<T> operator[](const valarray<bool>& boolarr);
381
  ```
382
 
383
  *Returns:* An object that holds references to elements of the controlled
384
  sequence selected by `boolarr`.
385
 
386
+ [*Example 6*:
387
+
388
  ``` cpp
389
  valarray<char> v0("abcdefghijklmnop", 16);
390
  valarray<char> v1("ABC", 3);
391
  const bool vb[] = { false, false, true, true, false, true };
392
  v0[valarray<bool>(vb, 6)] = v1;
393
  // v0 == valarray<char>("abABeCghijklmnop", 16)
394
  ```
395
 
396
+ — *end example*]
397
+
398
  ``` cpp
399
+ valarray operator[](const valarray<size_t>& indarr) const;
400
  ```
401
 
402
+ *Returns:* A `valarray` containing those elements of the controlled
403
+ sequence designated by `indarr`.
404
+
405
+ [*Example 7*:
406
 
407
  ``` cpp
408
  const valarray<char> v0("abcdefghijklmnop", 16);
409
  const size_t vi[] = { 7, 5, 2, 3, 8 };
410
  // v0[valarray<size_t>(vi, 5)] returns
411
  // valarray<char>("hfcdi", 5)
412
  ```
413
 
414
+ — *end example*]
415
+
416
  ``` cpp
417
  indirect_array<T> operator[](const valarray<size_t>& indarr);
418
  ```
419
 
420
  *Returns:* An object that holds references to elements of the controlled
421
  sequence selected by `indarr`.
422
 
423
+ [*Example 8*:
424
+
425
  ``` cpp
426
  valarray<char> v0("abcdefghijklmnop", 16);
427
  valarray<char> v1("ABCDE", 5);
428
  const size_t vi[] = { 7, 5, 2, 3, 8 };
429
  v0[valarray<size_t>(vi, 5)] = v1;
430
  // v0 == valarray<char>("abCDeBgAEjklmnop", 16)
431
  ```
432
 
433
+ — *end example*]
434
+
435
  #### `valarray` unary operators <a id="valarray.unary">[[valarray.unary]]</a>
436
 
437
  ``` cpp
438
+ valarray operator+() const;
439
+ valarray operator-() const;
440
+ valarray operator~() const;
441
  valarray<bool> operator!() const;
442
  ```
443
 
444
+ *Requires:* Each of these operators may only be instantiated for a type
445
+ `T` to which the indicated operator can be applied and for which the
446
+ indicated operator returns a value which is of type `T` (`bool` for
447
+ `operator!`) or which may be unambiguously implicitly converted to type
448
+ `T` (`bool` for `operator!`).
449
 
450
+ *Returns:* A `valarray` whose length is `size()`. Each element of the
451
+ returned array is initialized with the result of applying the indicated
452
+ operator to the corresponding element of the array.
 
453
 
454
+ #### `valarray` compound assignment <a id="valarray.cassign">[[valarray.cassign]]</a>
455
 
456
  ``` cpp
457
+ valarray& operator*= (const valarray& v);
458
+ valarray& operator/= (const valarray& v);
459
+ valarray& operator%= (const valarray& v);
460
+ valarray& operator+= (const valarray& v);
461
+ valarray& operator-= (const valarray& v);
462
+ valarray& operator^= (const valarray& v);
463
+ valarray& operator&= (const valarray& v);
464
+ valarray& operator|= (const valarray& v);
465
+ valarray& operator<<=(const valarray& v);
466
+ valarray& operator>>=(const valarray& v);
467
  ```
468
 
469
+ *Requires:* `size() == v.size()`. Each of these operators may only be
470
+ instantiated for a type `T` if the indicated operator can be applied to
471
+ two operands of type `T`. The value of an element in the left-hand side
472
+ of a valarray compound assignment operator does not depend on the value
473
+ of another element in that left hand side.
474
 
475
+ *Effects:* Each of these operators performs the indicated operation on
476
+ each of the elements of `*this` and the corresponding element of `v`.
477
 
478
+ *Returns:* `*this`.
 
 
479
 
480
+ *Remarks:* The appearance of an array on the left-hand side of a
481
+ compound assignment does not invalidate references or pointers.
 
482
 
483
  ``` cpp
484
+ valarray& operator*= (const T& v);
485
+ valarray& operator/= (const T& v);
486
+ valarray& operator%= (const T& v);
487
+ valarray& operator+= (const T& v);
488
+ valarray& operator-= (const T& v);
489
+ valarray& operator^= (const T& v);
490
+ valarray& operator&= (const T& v);
491
+ valarray& operator|= (const T& v);
492
+ valarray& operator<<=(const T& v);
493
+ valarray& operator>>=(const T& v);
494
  ```
495
 
496
+ *Requires:* Each of these operators may only be instantiated for a type
497
+ `T` if the indicated operator can be applied to two operands of type
498
+ `T`.
499
 
500
+ *Effects:* Each of these operators applies the indicated operation to
501
+ each element of `*this` and `v`.
502
 
503
+ *Returns:* `*this`
504
 
505
+ *Remarks:* The appearance of an array on the left-hand side of a
506
+ compound assignment does not invalidate references or pointers to the
507
+ elements of the array.
508
 
509
  #### `valarray` member functions <a id="valarray.members">[[valarray.members]]</a>
510
 
511
  ``` cpp
512
  void swap(valarray& v) noexcept;
 
527
 
528
  ``` cpp
529
  T sum() const;
530
  ```
531
 
532
+ *Requires:* `size() > 0`. This function may only be instantiated for a
533
+ type `T` to which `operator+=` can be applied.
 
534
 
535
+ *Returns:* The sum of all the elements of the array. If the array has
536
+ length 1, returns the value of element 0. Otherwise, the returned value
537
+ is calculated by applying `operator+=` to a copy of an element of the
538
+ array and all other elements of the array in an unspecified order.
 
539
 
540
  ``` cpp
541
  T min() const;
542
  ```
543
 
544
+ *Requires:* `size() > 0`
545
+
546
+ *Returns:* The minimum value contained in `*this`. For an array of
547
+ length 1, the value of element 0 is returned. For all other array
548
+ lengths, the determination is made using `operator<`.
549
 
550
  ``` cpp
551
  T max() const;
552
  ```
553
 
554
+ *Requires:* `size() > 0`.
555
+
556
+ *Returns:* The maximum value contained in `*this`. For an array of
557
+ length 1, the value of element 0 is returned. For all other array
558
+ lengths, the determination is made using `operator<`.
559
 
560
  ``` cpp
561
+ valarray shift(int n) const;
562
  ```
563
 
564
+ *Returns:* A `valarray` of length `size()`, each of whose elements *I*
565
+ is `(*this)[`*`I`*` + n]` if *`I`*` + n` is non-negative and less than
566
+ `size()`, otherwise `T()`.
567
+
568
+ [*Note 1*: If element zero is taken as the leftmost element, a positive
569
+ value of `n` shifts the elements left `n` places, with zero
570
+ fill. — *end note*]
571
+
572
+ [*Example 1*: If the argument has the value -2, the first two elements
573
+ of the result will be value-initialized ([[dcl.init]]); the third
574
+ element of the result will be assigned the value of the first element of
575
+ the argument; etc. — *end example*]
576
+
577
  ``` cpp
578
+ valarray cshift(int n) const;
579
  ```
580
 
581
+ *Returns:* A `valarray` of length `size()` that is a circular shift of
582
+ `*this`. If element zero is taken as the leftmost element, a
583
+ non-negative value of n shifts the elements circularly left n places and
584
+ a negative value of n shifts the elements circularly right -n places.
585
+
586
  ``` cpp
587
+ valarray apply(T func(T)) const;
588
+ valarray apply(T func(const T&)) const;
589
  ```
590
 
591
+ *Returns:* A `valarray` whose length is `size()`. Each element of the
592
+ returned array is assigned the value returned by applying the argument
593
+ function to the corresponding element of `*this`.
594
+
595
  ``` cpp
596
  void resize(size_t sz, T c = T());
597
  ```
598
 
599
+ *Effects:* Changes the length of the `*this` array to `sz` and then
600
+ assigns to each element the value of the second argument. Resizing
601
+ invalidates all pointers and references to elements in the array.
602
+