193 lines
5.4 KiB
Markdown
193 lines
5.4 KiB
Markdown
[valarray.members]
|
||
|
||
# 29 Numerics library [[numerics]](./#numerics)
|
||
|
||
## 29.6 Numeric arrays [[numarray]](numarray#valarray.members)
|
||
|
||
### 29.6.2 Class template valarray [[template.valarray]](template.valarray#valarray.members)
|
||
|
||
#### 29.6.2.8 Member functions [valarray.members]
|
||
|
||
[ð](#lib:swap,valarray)
|
||
|
||
`void swap(valarray& v) noexcept;
|
||
`
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7933)
|
||
|
||
*Effects*: *this obtains the value ofv[.](#1.sentence-1)
|
||
|
||
v obtains the value of *this[.](#1.sentence-2)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7938)
|
||
|
||
*Complexity*: Constant[.](#2.sentence-1)
|
||
|
||
[ð](#lib:size,valarray)
|
||
|
||
`size_t size() const;
|
||
`
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7949)
|
||
|
||
*Returns*: The number of elements in the array[.](#3.sentence-1)
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7953)
|
||
|
||
*Complexity*: Constant time[.](#4.sentence-1)
|
||
|
||
[ð](#lib:sum,valarray)
|
||
|
||
`T sum() const;
|
||
`
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7964)
|
||
|
||
*Mandates*: operator+= can be applied to operands of type T[.](#5.sentence-1)
|
||
|
||
[6](#6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7968)
|
||
|
||
*Preconditions*: size() > 0 is true[.](#6.sentence-1)
|
||
|
||
[7](#7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7972)
|
||
|
||
*Returns*: The sum of all the elements of the array[.](#7.sentence-1)
|
||
|
||
If the array has length 1, returns the value of element 0[.](#7.sentence-2)
|
||
|
||
Otherwise, the returned value is calculated by applyingoperator+= to a copy of an element of the array and
|
||
all other elements of the array in an unspecified order[.](#7.sentence-3)
|
||
|
||
[ð](#lib:min,valarray)
|
||
|
||
`T min() const;
|
||
`
|
||
|
||
[8](#8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7988)
|
||
|
||
*Preconditions*: size() > 0 is true[.](#8.sentence-1)
|
||
|
||
[9](#9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7992)
|
||
|
||
*Returns*: The minimum value contained in *this[.](#9.sentence-1)
|
||
|
||
For an array of length 1, the value of element 0 is returned[.](#9.sentence-2)
|
||
|
||
For all other array
|
||
lengths, the determination is made usingoperator<[.](#9.sentence-3)
|
||
|
||
[ð](#lib:max,valarray)
|
||
|
||
`T max() const;
|
||
`
|
||
|
||
[10](#10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8007)
|
||
|
||
*Preconditions*: size() > 0 is true[.](#10.sentence-1)
|
||
|
||
[11](#11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8011)
|
||
|
||
*Returns*: The maximum value contained in *this[.](#11.sentence-1)
|
||
|
||
For an array of length 1, the value of element 0 is returned[.](#11.sentence-2)
|
||
|
||
For all other array
|
||
lengths, the determination is made usingoperator<[.](#11.sentence-3)
|
||
|
||
[ð](#lib:shift,valarray)
|
||
|
||
`valarray shift(int n) const;
|
||
`
|
||
|
||
[12](#12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8026)
|
||
|
||
*Returns*: A valarray of length size(), each of whose elements*I* is(*this)[*I* + n] if *I* + n is non-negative and less thansize(), otherwise T()[.](#12.sentence-1)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
If element zero is taken as the leftmost element,
|
||
a positive value of n shifts the elements left n places, with zero fill[.](#12.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[13](#13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8040)
|
||
|
||
[*Example [1](#example-1)*:
|
||
|
||
If the argument has the value â2,
|
||
the first two elements of the result will be [value-initialized](dcl.init#def:value-initialization "9.5 Initializers [dcl.init]"); the third element of the result will be assigned the value
|
||
of the first element of *this; etc[.](#13.sentence-1)
|
||
|
||
â *end example*]
|
||
|
||
[ð](#lib:cshift,valarray)
|
||
|
||
`valarray cshift(int n) const;
|
||
`
|
||
|
||
[14](#14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8054)
|
||
|
||
*Returns*: A valarray of length size() that is a circular shift of *this[.](#14.sentence-1)
|
||
|
||
If element zero is taken as
|
||
the leftmost element, a non-negative value of n shifts
|
||
the elements circularly left n places and a negative
|
||
value of n shifts the elements circularly right ân places[.](#14.sentence-2)
|
||
|
||
[ð](#lib:apply,valarray)
|
||
|
||
`valarray apply(T func(T)) const;
|
||
valarray apply(T func(const T&)) const;
|
||
`
|
||
|
||
[15](#15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8070)
|
||
|
||
*Returns*: A valarray whose length is size()[.](#15.sentence-1)
|
||
|
||
Each element of the returned array is assigned
|
||
the value returned by applying the argument function to the
|
||
corresponding element of *this[.](#15.sentence-2)
|
||
|
||
[ð](#lib:resize,valarray)
|
||
|
||
`void resize(size_t sz, T c = T());
|
||
`
|
||
|
||
[16](#16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8084)
|
||
|
||
*Effects*: Changes the length of the *this array to sz and then assigns to each element the value of the second argument[.](#16.sentence-1)
|
||
|
||
Resizing invalidates all pointers and references to elements in the array[.](#16.sentence-2)
|