< cpp‎ | numeric‎ | valarray
Revision as of 08:39, 5 December 2012 by Bazzy (Talk | contribs)


Template:ddcl list begin <tr class="t-dcl ">

<td >
const T&            operator[]( std::size_t pos ) const;
T&                  operator[]( std::size_t pos );

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
valarray<T>         operator[]( std::slice slicearr ) const;

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
std::slice_array<T> operator[]( std::slice slicearr );

<td > (3) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
valarray<T>         operator[]( const std::gslice& gslicearr ) const;

<td > (4) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
gslice_array<T>     operator[]( const std::gslice& gslicearr );

<td > (5) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
valarray<T>         operator[]( const valarray<bool>& boolarr ) const;

<td > (6) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
valarray<T>         operator[]( const valarray<size_t>& indarr ) const;

<td > (7) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
indirect_array<T>   operator[]( const valarray<size_t>& indarr );

<td > (8) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

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.



Return value

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




The selected elements must exist.


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