< cpp‎ | numeric‎ | valarray
const T&            operator[]( size_t pos ) const;
T&                  operator[]( size_t pos );
valarray<T>         operator[]( slice slicearr ) const;
slice_array<T>      operator[]( slice slicearr );
valarray<T>         operator[]( const gslice& gslicearr ) const;
gslice_array<T>     operator[]( const gslice& gslicearr );
valarray<T>         operator[]( const valarray<bool>& boolarr ) const;
mask_array<T>       operator[]( const valarray<bool>& boolarr );
valarray<T>         operator[]( const valarray<size_t>& indarr ) const;
indirect_array<T>   operator[]( const valarray<size_t>& indarr );

Retrieve single elements or portions of the array.

The const overloads that return element sequences create a new std::valarray object. The non-const overloads return classes holding references to the array elements.


[edit] Parameters

[edit] Return value

1,2) A reference to the corresponding element
3,5,7,9) A std::valarray object containing copies of the selected items
4,6,8,10) The corresponding data structure containing references to the selected items

[edit] Exceptions


[edit] Precondition

The selected elements must exist.

[edit] Notes

  • For proper values of i and j, the following properties are true:
1) (a[i] = q, a[i]) == q
For a non-const a.
2) &a[i+j] == &a[i] + j
This means that valarray elements are adjacent in memory.
3) &a[i] != &b[j]
This holds for every objects a and b that are not aliases of one another.
This means that there are no aliases in the elements and this property can be used to perform some kinds of optimization.
  • References become invalid on resize or when the array is destructed.