Files
cppdraft_translate/cppdraft/valarray/members.md
2025-10-25 03:02:53 +03:00

5.4 KiB
Raw Blame History

[valarray.members]

29 Numerics library [numerics]

29.6 Numeric arrays [numarray]

29.6.2 Class template valarray [template.valarray]

29.6.2.8 Member functions [valarray.members]

🔗

void swap(valarray& v) noexcept;

1

#

Effects: *this obtains the value ofv.

v obtains the value of *this.

2

#

Complexity: Constant.

🔗

size_t size() const;

3

#

Returns: The number of elements in the array.

4

#

Complexity: Constant time.

🔗

T sum() const;

5

#

Mandates: operator+= can be applied to operands of type T.

6

#

Preconditions: size() > 0 is true.

7

#

Returns: The sum of all the elements of the array.

If the array has length 1, returns the value of element 0.

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.

🔗

T min() const;

8

#

Preconditions: size() > 0 is true.

9

#

Returns: The minimum value contained in *this.

For an array of length 1, the value of element 0 is returned.

For all other array lengths, the determination is made usingoperator<.

🔗

T max() const;

10

#

Preconditions: size() > 0 is true.

11

#

Returns: The maximum value contained in *this.

For an array of length 1, the value of element 0 is returned.

For all other array lengths, the determination is made usingoperator<.

🔗

valarray shift(int n) const;

12

#

Returns: A valarray of length size(), each of whose elementsI is(*this)[I + n] if I + n is non-negative and less thansize(), otherwise T().

[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.

— end note]

13

#

[Example 1:

If the argument has the value −2, the first two elements of the result will be value-initialized; the third element of the result will be assigned the value of the first element of *this; etc.

— end example]

🔗

valarray cshift(int n) const;

14

#

Returns: A valarray of length size() that is a circular shift of *this.

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.

🔗

valarray apply(T func(T)) const; valarray apply(T func(const T&)) const;

15

#

Returns: A valarray whose length is size().

Each element of the returned array is assigned the value returned by applying the argument function to the corresponding element of *this.

🔗

void resize(size_t sz, T c = T());

16

#

Effects: Changes the length of the *this array to sz and then assigns to each element the value of the second argument.

Resizing invalidates all pointers and references to elements in the array.