class template
<valarray>

std::gslice_array

template <class T> gslice_array;
Valarray gslice selection
This class is used as an intermediate type returned by valarray's subscript operator (operator[]) when used with generalized gslices.

It references the elements in the valarray object that are selected by the gslice, and overloads the assignment and compound assignment operators, allowing direct access to the elements in the selection.

The type is convertible to a valarray (see valarray constructor), producing a new object with copies of the referred elements.

Objects of this type are obtained as the return value of a call to valarray::operator[]. They cannot be directly constructed nor copied. It is declared as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
template <class T> class gslice_array {
public:
  typedef T value_type;
  void operator=   (const valarray<T>&) const;
  void operator*=  (const valarray<T>&) const;
  void operator/=  (const valarray<T>&) const;
  void operator%=  (const valarray<T>&) const;
  void operator+=  (const valarray<T>&) const;
  void operator-=  (const valarray<T>&) const;
  void operator^=  (const valarray<T>&) const;
  void operator&=  (const valarray<T>&) const;
  void operator|=  (const valarray<T>&) const;
  void operator<<= (const valarray<T>&) const;
  void operator>>= (const valarray<T>&) const;
  void operator=(const T&);
  ~gslice_array();
private:
  gslice_array();
  gslice_array(const gslice_array&);
  gslice_array& operator= (const gslice_array&);
};

Objects of this type are obtained as the return value of a call to valarray::operator[]. They cannot be default-constructed, but can be copied. It is declared as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
template <class T> class gslice_array {
public:
  typedef T value_type;
  void operator=   (const valarray<T>&) const;
  void operator*=  (const valarray<T>&) const;
  void operator/=  (const valarray<T>&) const;
  void operator%=  (const valarray<T>&) const;
  void operator+=  (const valarray<T>&) const;
  void operator-=  (const valarray<T>&) const;
  void operator^=  (const valarray<T>&) const;
  void operator&=  (const valarray<T>&) const;
  void operator|=  (const valarray<T>&) const;
  void operator<<= (const valarray<T>&) const;
  void operator>>= (const valarray<T>&) const;
  void operator=(const T&) const;

  gslice_array() = delete;
  gslice_array(const gslice_array&);
  const gslice_array& operator= (const gslice_array&) const;
  ~gslice_array();
};


Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// gslice_array example
#include <iostream>     // std::cout
#include <cstddef>      // std::size_t
#include <valarray>     // std::valarray, std::gslice

int main ()
{
  std::valarray<int> foo (14);
  for (int i=0; i<14; ++i) foo[i]=i;

  std::size_t start=1;
  std::size_t lengths[]= {2,3};
  std::size_t strides[]= {7,2};

  std::gslice mygslice (start,
                        std::valarray<std::size_t>(lengths,2),
                        std::valarray<std::size_t>(strides,2));
  foo[mygslice] = 0;

  std::cout << "foo:\n";
  for (std::size_t n=0; n<foo.size(); n++)
	  std::cout << ' ' << foo[n];
  std::cout << '\n';

  return 0;
}


Output:

0 0 2 0 4 0 6 7 0 9 0 11 0 13

See also