# valarray Class Template Reference

Inheritance diagram for valarray:

List of all members.

## Detailed Description

### template<class _Tp>
class std::valarray< _Tp >

A valarray is an array that provides constraints intended to allow for effective optimization of numeric array processing by reducing the aliasing that can result from pointer representations. It represents a one-dimensional array from which different multidimensional subsets can be accessed and modified.

Parameters:

  | Tp | Type of object in the array.

Definition at line 109 of file valarray.

## Public Types

- typedef _Tp value_type

## Public Member Functions

- _Expr< _RefFunClos< _ValArray,
  _Tp >, _Tp > apply (_Tp func(const _Tp &)) const
- _Expr< _ValFunClos< _ValArray,
  _Tp >, _Tp > apply (_Tp func(_Tp)) const
- valarray< _Tp > cshift (int) const
- _Tp max () const
- _Tp min () const
- template<class _Dom> valarray< _Tp > & operator &= (const _Expr< _Dom, _Tp > &)
- valarray< _Tp > & operator &= (const valarray< _Tp > &)
- valarray< _Tp > & operator &= (const _Tp &)
- template<class _Dom> valarray< _Tp > & operator *= (const _Expr< _Dom, _Tp > &)
- valarray< _Tp > & operator *= (const valarray< _Tp > &)
- valarray< _Tp > & operator *= (const _Tp &)
- _UnaryOp< __logical_not >::_Rt operator! () const
- template<class _Dom> valarray< _Tp > & operator%= (const _Expr< _Dom, _Tp > &)
- valarray< _Tp > & operator%= (const valarray< _Tp > &)
- valarray< _Tp > & operator%= (const _Tp &)
- _UnaryOp< __unary_plus >::_Rt operator+ () const
- template<class _Dom> valarray< _Tp > & operator+= (const _Expr< _Dom, _Tp > &)
- valarray< _Tp > & operator+= (const valarray< _Tp > &)
- valarray< _Tp > & operator+= (const _Tp &)
- _UnaryOp< __negate >::_Rt operator- () const
- template<class _Dom> valarray< _Tp > & operator-= (const _Expr< _Dom, _Tp > &)
- valarray< _Tp > & operator-= (const valarray< _Tp > &)
- valarray< _Tp > & operator-= (const _Tp &)
- template<class _Dom> valarray< _Tp > & operator/= (const _Expr< _Dom, _Tp > &)
- valarray< _Tp > & operator/= (const valarray< _Tp > &)
- valarray< _Tp > & operator/= (const _Tp &)
- template<class _Dom> valarray< _Tp > & operator<<= (const _Expr< _Dom, _Tp > &)
- valarray< _Tp > & operator<<= (const valarray< _Tp > &)
- valarray< _Tp > & operator<<= (const _Tp &)
- template<class _Dom> valarray< _Tp > & operator= (const _Expr< _Dom, _Tp > &)
- valarray< _Tp > & operator= (const indirect_array< _Tp > &)
- valarray< _Tp > & operator= (const mask_array< _Tp > &)
- valarray< _Tp > & operator= (const gslice_array< _Tp > &)
- valarray< _Tp > & operator= (const slice_array< _Tp > &)
- valarray< _Tp > & operator= (const _Tp &)
- valarray< _Tp > & operator= (const valarray< _Tp > &)
- template<class _Dom> valarray< _Tp > & operator>>= (const _Expr< _Dom, _Tp > &)
- valarray< _Tp > & operator>>= (const valarray< _Tp > &)
- valarray< _Tp > & operator>>= (const _Tp &)
- indirect_array< _Tp > operator[] (const valarray< size_t > &)
- _Expr< _IClos< _ValArray,
  _Tp >, _Tp > operator[] (const valarray< size_t > &) const
- mask_array< _Tp > operator[] (const valarray< bool > &)
- valarray< _Tp > operator[] (const valarray< bool > &) const
- gslice_array< _Tp > operator[] (const gslice &)
- _Expr< _GClos< _ValArray,
  _Tp >, _Tp > operator[] (const gslice &) const
- slice_array< _Tp > operator[] (slice)
- _Expr< _SClos< _ValArray,
  _Tp >, _Tp > operator[] (slice) const
- const _Tp & operator[] (size_t) const
- _Tp & operator[] (size_t)
- template<class _Dom> valarray< _Tp > & operator^= (const _Expr< _Dom, _Tp > &)
- valarray< _Tp > & operator^= (const valarray< _Tp > &)
- valarray< _Tp > & operator^= (const _Tp &)
- template<class _Dom> valarray< _Tp > & operator|= (const _Expr< _Dom, _Tp > &)
- valarray< _Tp > & operator|= (const valarray< _Tp > &)
- valarray< _Tp > & operator|= (const _Tp &)
- _UnaryOp< __bitwise_not >::_Rt operator~ () const
- void resize (size_t __size, _Tp __c=_Tp())
- valarray< _Tp > shift (int) const
- size_t size () const
- _Tp sum () const
- template<typename _Tp> valarray (const _Tp *__restrict__ __p, size_t __n)
- template<class _Dom> valarray (const _Expr< _Dom, _Tp > &__e)
- valarray (const indirect_array< _Tp > &)
- valarray (const mask_array< _Tp > &)
- valarray (const gslice_array< _Tp > &)
- valarray (const slice_array< _Tp > &)
- valarray (const valarray &)
- valarray (const _Tp *__restrict__, size_t)
- valarray (const _Tp &, size_t)
- valarray (size_t)
- valarray ()

## Friends

- class _Array< _Tp >

## Constructor & Destructor Documentation

valarray | ( |  | ) | `[inline]`

| Construct an empty array. Definition at line 552 of file valarray.

valarray | ( | size_t |  | ) | `[inline, explicit]`

| Construct an array with n elements. Definition at line 556 of file valarray.

valarray | ( | const _Tp & | ,
|  | size_t |
| ) | `[inline]`

| Construct an array with n elements initialized to t. Definition at line 562 of file valarray.

valarray | ( | const _Tp * | __restrict__,
|  | size_t |
| ) |

| Construct an array initialized to the first n elements of t.

valarray | ( | const valarray< _Tp > & |  | ) | `[inline]`

| Copy constructor. Definition at line 577 of file valarray. References valarray::_M_data.

valarray | ( | const slice_array< _Tp > & |  | ) | `[inline]`

| Construct an array with the same size and values in sa. Definition at line 584 of file valarray. References slice_array::_M_array, slice_array::_M_stride, and slice_array::_M_sz.

valarray | ( | const gslice_array< _Tp > & |  | ) | `[inline]`

| Construct an array with the same size and values in ga. Definition at line 593 of file valarray. References gslice_array::_M_array, and gslice_array::_M_index.

valarray | ( | const mask_array< _Tp > & |  | ) | `[inline]`

| Construct an array with the same size and values in ma. Definition at line 604 of file valarray. References mask_array::_M_array, and mask_array::_M_mask.

valarray | ( | const indirect_array< _Tp > & |  | ) | `[inline]`

| Construct an array with the same size and values in ia. Definition at line 613 of file valarray. References indirect_array::_M_array, and indirect_array::_M_index.

## Member Function Documentation

_Expr< _RefFunClos< _ValArray, _Tp >, _Tp > apply | ( | _Tp | func(const _Tp &) | ) | const`[inline]`

Apply a function to the array.

Returns a new valarray with elements assigned to the result of applying func to the corresponding element of this array. The new array is the same size as this one.

Parameters:

  | func | Function of const Tp& returning Tp to apply.

Returns:
  New valarray with transformed elements.

Definition at line 879 of file valarray.

_Expr< _ValFunClos< _ValArray, _Tp >, _Tp > apply | ( | _Tp | func(_Tp) | ) | const`[inline]`

Apply a function to the array.

Returns a new valarray with elements assigned to the result of applying func to the corresponding element of this array. The new array is the same size as this one.

Parameters:

  | func | Function of Tp returning Tp to apply.

Returns:
  New valarray with transformed elements.

Definition at line 871 of file valarray.

valarray< _Tp > cshift | ( | int |  | ) | const`[inline]`

Return a rotated array.

A new valarray is constructed as a copy of this array with elements in shifted positions. For an element with index i, the new position is (i - n) % size(). The new valarray is the same size as the current one. Elements that are shifted beyond the array bounds are shifted into the other end of the array. No elements are lost.

Positive arguments shift toward index 0, wrapping around the top. Negative arguments shift towards the top, wrapping around to 0.

Parameters:

  | n | Number of element positions to rotate.

Returns:
  New valarray with elements in shifted positions.

Definition at line 813 of file valarray.

_Tp max | ( |  | ) | const`[inline]`

| Return the maximum element using operator<(). Definition at line 863 of file valarray. References std::max_element().

_Tp min | ( |  | ) | const`[inline]`

| Return the minimum element using operator<(). Definition at line 855 of file valarray. References std::min_element().

valarray<_Tp>& operator &= | ( | const valarray< _Tp > & |  | ) |

| Logical and corresponding elements of v with elements of array.

valarray<_Tp>& operator &= | ( | const _Tp & |  | ) |

| Set each element e of array to e & t.

valarray<_Tp>& operator *= | ( | const valarray< _Tp > & |  | ) |

| Multiply elements of array by corresponding elements of v.

valarray<_Tp>& operator *= | ( | const _Tp & |  | ) |

| Multiply each element of array by t.

_UnaryOp<__logical_not>::_Rt operator! | ( |  | ) | const

| Return a new valarray by applying unary ! to each element.

valarray<_Tp>& operator%= | ( | const valarray< _Tp > & |  | ) |

| Modulo elements of array by corresponding elements of v.

valarray<_Tp>& operator%= | ( | const _Tp & |  | ) |

| Set each element e of array to e % t.

_UnaryOp<__unary_plus>::_Rt operator+ | ( |  | ) | const

| Return a new valarray by applying unary + to each element.

valarray<_Tp>& operator+= | ( | const valarray< _Tp > & |  | ) |

| Add corresponding elements of v to elements of array.

valarray<_Tp>& operator+= | ( | const _Tp & |  | ) |

| Add t to each element of array.

_UnaryOp<__negate>::_Rt operator- | ( |  | ) | const

| Return a new valarray by applying unary - to each element.

valarray<_Tp>& operator-= | ( | const valarray< _Tp > & |  | ) |

| Subtract corresponding elements of v from elements of array.

valarray<_Tp>& operator-= | ( | const _Tp & |  | ) |

| Subtract t to each element of array.

valarray<_Tp>& operator/= | ( | const valarray< _Tp > & |  | ) |

| Divide elements of array by corresponding elements of v.

valarray<_Tp>& operator/= | ( | const _Tp & |  | ) |

| Divide each element of array by t.

valarray<_Tp>& operator<<= | ( | const valarray< _Tp > & |  | ) |

| Left shift elements of array by corresponding elements of v.

valarray<_Tp>& operator<<= | ( | const _Tp & |  | ) |

| Left shift each element e of array by t bits.

valarray< _Tp > & operator= | ( | const indirect_array< _Tp > & |  | ) | `[inline]`

Assign elements to an array subset.

Assign elements of array to values in ia. Results are undefined if ia is not the same size as this array.

Parameters:

  | ia | Array slice to get values from.

Definition at line 683 of file valarray.

References indirect_array::_M_array, indirect_array::_M_index, and indirect_array::_M_sz.

valarray< _Tp > & operator= | ( | const mask_array< _Tp > & |  | ) | `[inline]`

Assign elements to an array subset.

Assign elements of array to values in ma. Results are undefined if ma is not the same size as this array.

Parameters:

  | ma | Array slice to get values from.

Definition at line 673 of file valarray.

References mask_array::_M_array, mask_array::_M_mask, and mask_array::_M_sz.

valarray< _Tp > & operator= | ( | const gslice_array< _Tp > & |  | ) | `[inline]`

Assign elements to an array subset.

Assign elements of array to values in ga. Results are undefined if ga is not the same size as this array.

Parameters:

  | ga | Array slice to get values from.

Definition at line 663 of file valarray.

References gslice_array::_M_array, gslice_array::_M_index, and valarray::size().

valarray< _Tp > & operator= | ( | const slice_array< _Tp > & |  | ) | `[inline]`

Assign elements to an array subset.

Assign elements of array to values in sa. Results are undefined if sa is not the same size as this array.

Parameters:

  | sa | Array slice to get values from.

Definition at line 653 of file valarray.

References slice_array::_M_array, slice_array::_M_stride, and slice_array::_M_sz.

valarray< _Tp > & operator= | ( | const _Tp & |  | ) | `[inline]`

Assign elements to a value.

Assign all elements of array to t.

Parameters:

  | t | Value for elements.

Definition at line 645 of file valarray.

valarray< _Tp > & operator= | ( | const valarray< _Tp > & |  | ) | `[inline]`

Assign elements to an array.

Assign elements of array to values in v. Results are undefined if v is not the same size as this array.

Parameters:

  | v | Valarray to get values from.

Definition at line 636 of file valarray.

References valarray::_M_data, and valarray::_M_size.

valarray<_Tp>& operator>>= | ( | const valarray< _Tp > & |  | ) |

| Right shift elements of array by corresponding elements of v.

valarray<_Tp>& operator>>= | ( | const _Tp & |  | ) |

| Right shift each element e of array by t bits.

indirect_array< _Tp > operator[] | ( | const valarray< size_t > & |  | ) | `[inline]`

Return a reference to an array subset.

Returns an indirect_array referencing the elements of the array indicated by the argument. The elements in the argument are interpreted as the indices of elements of this valarray to include in the subset. The returned indirect_array refers to these elements.

Parameters:

  | i | The valarray element index list.

Returns:
  Indirect_array referencing elements in i.

Definition at line 763 of file valarray.

References valarray::size().

_Expr< _IClos< _ValArray, _Tp >, _Tp > operator[] | ( | const valarray< size_t > & |  | ) | const`[inline]`

Return an array subset.

Returns a new valarray containing the elements of the array indicated by the argument. The elements in the argument are interpreted as the indices of elements of this valarray to copy to the return valarray.

Parameters:

  | i | The valarray element index list.

Returns:
  New valarray containing elements in s.

Definition at line 755 of file valarray.

mask_array< _Tp > operator[] | ( | const valarray< bool > & |  | ) | `[inline]`

Return a reference to an array subset.

Returns a new mask_array referencing the elements of the array indicated by the argument. The input is a valarray of bool which represents a bitmask indicating which elements are part of the subset. Elements of the array are part of the subset if the corresponding element of the argument is true.

Parameters:

  | m | The valarray bitmask.

Returns:
  New valarray containing elements indicated by m.

Definition at line 744 of file valarray.

valarray< _Tp > operator[] | ( | const valarray< bool > & |  | ) | const`[inline]`

Return an array subset.

Returns a new valarray containing the elements of the array indicated by the argument. The input is a valarray of bool which represents a bitmask indicating which elements should be copied into the new valarray. Each element of the array is added to the return valarray if the corresponding element of the argument is true.

Parameters:

  | m | The valarray bitmask.

Returns:
  New valarray containing elements indicated by m.

Definition at line 732 of file valarray.

References valarray::size().

gslice_array< _Tp > operator[] | ( | const gslice & |  | ) | `[inline]`

Return a reference to an array subset.

Returns a new valarray containing the elements of the array indicated by the gslice argument. The new valarray is the size of the input gslice.

See also:
  gslice.

Parameters:

  | s | The source gslice.

Returns:
  New valarray containing elements in s.

Definition at line 724 of file valarray.

References gslice::_M_index.

_Expr< _GClos< _ValArray, _Tp >, _Tp > operator[] | ( | const gslice & |  | ) | const`[inline]`

Return an array subset.

Returns a slice_array referencing the elements of the array indicated by the slice argument.

See also:
  gslice.

Parameters:

  | s | The source slice.

Returns:
  Slice_array referencing elements indicated by s.

Definition at line 715 of file valarray.

References gslice::_M_index.

slice_array< _Tp > operator[] | ( | slice |  | ) | `[inline]`

Return a reference to an array subset.

Returns a new valarray containing the elements of the array indicated by the slice argument. The new valarray is the size of the input slice.

See also:
  slice.

Parameters:

  | s | The source slice.

Returns:
  New valarray containing elements in s.

Definition at line 710 of file valarray.

_Expr< _SClos< _ValArray, _Tp >, _Tp > operator[] | ( | slice |  | ) | const`[inline]`

Return an array subset.

Returns a new valarray containing the elements of the array indicated by the slice argument. The new valarray is the size of the input slice.

See also:
  slice.

Parameters:

  | s | The source slice.

Returns:
  New valarray containing elements in s.

Definition at line 702 of file valarray.

_Tp & operator[] | ( | size_t |  | ) | `[inline]`

Return a reference to the i'th array element.

Parameters:

  | i | Index of element to return.

Returns:
  Reference to the i'th element.

Definition at line 532 of file valarray.

valarray<_Tp>& operator^= | ( | const valarray< _Tp > & |  | ) |

| Logical xor corresponding elements of v with elements of array.

valarray<_Tp>& operator^= | ( | const _Tp & |  | ) |

| Set each element e of array to e ^ t.

valarray<_Tp>& operator|= | ( | const valarray< _Tp > & |  | ) |

| Logical or corresponding elements of v with elements of array.

valarray<_Tp>& operator|= | ( | const _Tp & |  | ) |

| Set each element e of array to e | t.

_UnaryOp<__bitwise_not>::_Rt operator~ | ( |  | ) | const

| Return a new valarray by applying unary ~ to each element.

void resize | ( | size_t | __size,
|  | _Tp | __c = `_Tp()`
| ) | `[inline]`

Resize array.

Resize this array to be size and set all elements to c. All references and iterators are invalidated.

Parameters:

  | size | New array size.
  | c | New value for all elements.

Definition at line 838 of file valarray.

valarray< _Tp > shift | ( | int |  | ) | const`[inline]`

Return a shifted array.

A new valarray is constructed as a copy of this array with elements in shifted positions. For an element with index i, the new position is i - n. The new valarray is the same size as the current one. New elements without a value are set to 0. Elements whos new position is outside the bounds of the array are discarded.

Positive arguments shift toward index 0, discarding elements [0, n). Negative arguments discard elements from the top of the array.

Parameters:

  | n | Number of element positions to shift.

Returns:
  New valarray with elements in shifted positions.

Definition at line 784 of file valarray.

size_t size | ( |  | ) | const`[inline]`

| Return the number of elements in array. Definition at line 771 of file valarray. Referenced by valarray::operator=(), gslice_array::operator=(), and valarray::operator[]().

_Tp sum | ( |  | ) | const`[inline]`

| Return the sum of all elements in the array. Accumulates the sum of all elements into a Tp using +=. The order of adding the elements is unspecified. Definition at line 776 of file valarray.

The documentation for this class was generated from the following file:

- valarray