From Jason Turner

[template.valarray]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmprxx1oxny/{from.md → to.md} +48 -49
tmp/tmprxx1oxny/{from.md → to.md} RENAMED
@@ -1,8 +1,8 @@
1
  ### Class template `valarray` <a id="template.valarray">[[template.valarray]]</a>
2
 
3
- #### Class template `valarray` overview <a id="template.valarray.overview">[[template.valarray.overview]]</a>
4
 
5
  ``` cpp
6
  namespace std {
7
  template<class T> class valarray {
8
  public:
@@ -102,14 +102,11 @@ 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
 
@@ -118,11 +115,11 @@ valarray();
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
 
@@ -131,12 +128,11 @@ 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
 
@@ -179,11 +175,11 @@ templates to a `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
 
@@ -191,11 +187,11 @@ valarray& operator=(const valarray& v);
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;
@@ -227,63 +223,64 @@ 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
279
  versions return this subset as a new `valarray` object. The non-const
280
  versions return a class template object which has reference semantics to
281
  the original array, working in conjunction with various overloads of
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
 
@@ -430,30 +427,29 @@ 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);
@@ -464,15 +460,18 @@ 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`.
@@ -491,24 +490,23 @@ 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;
513
  ```
514
 
@@ -527,33 +525,34 @@ size_t size() const;
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
 
@@ -568,13 +567,13 @@ is `(*this)[`*`I`*` + n]` if *`I`*` + n` is non-negative and less than
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
 
 
1
  ### Class template `valarray` <a id="template.valarray">[[template.valarray]]</a>
2
 
3
+ #### Overview <a id="template.valarray.overview">[[template.valarray.overview]]</a>
4
 
5
  ``` cpp
6
  namespace std {
7
  template<class T> class valarray {
8
  public:
 
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
+ #### Constructors <a id="valarray.cons">[[valarray.cons]]</a>
 
 
 
108
 
109
  ``` cpp
110
  valarray();
111
  ```
112
 
 
115
  ``` cpp
116
  explicit valarray(size_t n);
117
  ```
118
 
119
  *Effects:* Constructs a `valarray` that has length `n`. Each element of
120
+ the array is value-initialized [[dcl.init]].
121
 
122
  ``` cpp
123
  valarray(const T& v, size_t n);
124
  ```
125
 
 
128
 
129
  ``` cpp
130
  valarray(const T* p, size_t n);
131
  ```
132
 
133
+ *Preconditions:* \[`p`, `p + n`) is a valid range.
 
134
 
135
  *Effects:* Constructs a `valarray` that has length `n`. The values of
136
  the elements of the array are initialized with the first `n` values
137
  pointed to by the first argument.[^10]
138
 
 
175
  ```
176
 
177
  *Effects:* The destructor is applied to every element of `*this`; an
178
  implementation may return all allocated memory.
179
 
180
+ #### Assignment <a id="valarray.assign">[[valarray.assign]]</a>
181
 
182
  ``` cpp
183
  valarray& operator=(const valarray& v);
184
  ```
185
 
 
187
  the corresponding element of `v`. If the length of `v` is not equal to
188
  the length of `*this`, resizes `*this` to make the two arrays the same
189
  length, as if by calling `resize(v.size())`, before performing the
190
  assignment.
191
 
192
+ *Ensures:* `size() == v.size()`.
193
 
194
  *Returns:* `*this`.
195
 
196
  ``` cpp
197
  valarray& operator=(valarray&& v) noexcept;
 
223
  valarray& operator=(const gslice_array<T>&);
224
  valarray& operator=(const mask_array<T>&);
225
  valarray& operator=(const indirect_array<T>&);
226
  ```
227
 
228
+ *Preconditions:* The length of the array to which the argument refers
229
+ equals `size()`. The value of an element in the left-hand side of a
230
+ `valarray` assignment operator does not depend on the value of another
231
+ element in that left-hand side.
232
 
233
  These operators allow the results of a generalized subscripting
234
  operation to be assigned directly to a `valarray`.
235
 
236
+ #### Element access <a id="valarray.access">[[valarray.access]]</a>
237
 
238
  ``` cpp
239
  const T& operator[](size_t n) const;
240
  T& operator[](size_t n);
241
  ```
242
 
243
+ *Preconditions:* `n < size()` is `true`.
244
 
245
  *Returns:* A reference to the corresponding element of the array.
246
 
247
  [*Note 1*: The expression `(a[i] = q, a[i]) == q` evaluates to `true`
248
  for any non-constant `valarray<T> a`, any `T q`, and for any `size_t i`
249
  such that the value of `i` is less than the length of
250
  `a`. — *end note*]
251
 
252
+ *Remarks:* The expression `addressof(a[i+j]) == addressof(a[i]) + j`
253
+ evaluates to `true` for all `size_t i` and `size_t j` such that
254
+ `i+j < a.size()`.
255
 
256
+ The expression `addressof(a[i]) != addressof(b[j])` evaluates to `true`
257
+ for any two arrays `a` and `b` and for any `size_t i` and `size_t j`
258
+ such that `i < a.size()` and `j < b.size()`.
259
 
260
  [*Note 2*: This property indicates an absence of aliasing and may be
261
  used to advantage by optimizing compilers. Compilers may take advantage
262
  of inlining, constant propagation, loop fusion, tracking of pointers
263
  obtained from `operator new`, and other techniques to generate efficient
264
  `valarray`s. — *end note*]
265
 
266
  The reference returned by the subscript operator for an array shall be
267
+ valid until the member function `resize(size_t, T)` [[valarray.members]]
268
+ is called for that array or until the lifetime of that array ends,
269
+ whichever happens first.
270
 
271
+ #### Subset operations <a id="valarray.sub">[[valarray.sub]]</a>
272
 
273
  The member `operator[]` is overloaded to provide several ways to select
274
  sequences of elements from among those controlled by `*this`. Each of
275
  these operations returns a subset of the array. The const-qualified
276
  versions return this subset as a new `valarray` object. The non-const
277
  versions return a class template object which has reference semantics to
278
  the original array, working in conjunction with various overloads of
279
  `operator=` and other assigning operators to allow selective replacement
280
  (slicing) of the controlled sequence. In each case the selected
281
+ element(s) shall exist.
282
 
283
  ``` cpp
284
  valarray operator[](slice slicearr) const;
285
  ```
286
 
 
427
  // v0 == valarray<char>("abCDeBgAEjklmnop", 16)
428
  ```
429
 
430
  — *end example*]
431
 
432
+ #### Unary operators <a id="valarray.unary">[[valarray.unary]]</a>
433
 
434
  ``` cpp
435
  valarray operator+() const;
436
  valarray operator-() const;
437
  valarray operator~() const;
438
  valarray<bool> operator!() const;
439
  ```
440
 
441
+ *Mandates:* The indicated operator can be applied to operands of type
442
+ `T` and returns a value of type `T` (`bool` for `operator!`) or which
443
+ may be unambiguously implicitly converted to type `T` (`bool` for
444
+ `operator!`).
 
445
 
446
  *Returns:* A `valarray` whose length is `size()`. Each element of the
447
  returned array is initialized with the result of applying the indicated
448
  operator to the corresponding element of the array.
449
 
450
+ #### Compound assignment <a id="valarray.cassign">[[valarray.cassign]]</a>
451
 
452
  ``` cpp
453
  valarray& operator*= (const valarray& v);
454
  valarray& operator/= (const valarray& v);
455
  valarray& operator%= (const valarray& v);
 
460
  valarray& operator|= (const valarray& v);
461
  valarray& operator<<=(const valarray& v);
462
  valarray& operator>>=(const valarray& v);
463
  ```
464
 
465
+ *Mandates:* The indicated operator can be applied to two operands of
466
+ type `T`.
467
+
468
+ *Preconditions:* `size() == v.size()` is `true`.
469
+
470
+ The value of an element in the left-hand side of a valarray compound
471
+ assignment operator does not depend on the value of another element in
472
+ that left hand side.
473
 
474
  *Effects:* Each of these operators performs the indicated operation on
475
  each of the elements of `*this` and the corresponding element of `v`.
476
 
477
  *Returns:* `*this`.
 
490
  valarray& operator|= (const T& v);
491
  valarray& operator<<=(const T& v);
492
  valarray& operator>>=(const T& v);
493
  ```
494
 
495
+ *Mandates:* The indicated operator can be applied to two operands of
496
+ type `T`.
 
497
 
498
  *Effects:* Each of these operators applies the indicated operation to
499
  each element of `*this` and `v`.
500
 
501
  *Returns:* `*this`
502
 
503
  *Remarks:* The appearance of an array on the left-hand side of a
504
  compound assignment does not invalidate references or pointers to the
505
  elements of the array.
506
 
507
+ #### Member functions <a id="valarray.members">[[valarray.members]]</a>
508
 
509
  ``` cpp
510
  void swap(valarray& v) noexcept;
511
  ```
512
 
 
525
 
526
  ``` cpp
527
  T sum() const;
528
  ```
529
 
530
+ *Mandates:* `operator+=` can be applied to operands of type `T`.
531
+
532
+ *Preconditions:* `size() > 0` is `true`.
533
 
534
  *Returns:* The sum of all the elements of the array. If the array has
535
  length 1, returns the value of element 0. Otherwise, the returned value
536
  is calculated by applying `operator+=` to a copy of an element of the
537
  array and all other elements of the array in an unspecified order.
538
 
539
  ``` cpp
540
  T min() const;
541
  ```
542
 
543
+ *Preconditions:* `size() > 0` is `true`.
544
 
545
  *Returns:* The minimum value contained in `*this`. For an array of
546
  length 1, the value of element 0 is returned. For all other array
547
  lengths, the determination is made using `operator<`.
548
 
549
  ``` cpp
550
  T max() const;
551
  ```
552
 
553
+ *Preconditions:* `size() > 0` is `true`.
554
 
555
  *Returns:* The maximum value contained in `*this`. For an array of
556
  length 1, the value of element 0 is returned. For all other array
557
  lengths, the determination is made using `operator<`.
558
 
 
567
  [*Note 1*: If element zero is taken as the leftmost element, a positive
568
  value of `n` shifts the elements left `n` places, with zero
569
  fill. — *end note*]
570
 
571
  [*Example 1*: If the argument has the value -2, the first two elements
572
+ of the result will be value-initialized [[dcl.init]]; the third element
573
+ of the result will be assigned the value of the first element of the
574
+ argument; etc. — *end example*]
575
 
576
  ``` cpp
577
  valarray cshift(int n) const;
578
  ```
579