Name

indirect_array class template — Helper class for indirect arrays

Synopsis

template <typename T>
class indirect_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&);
  ~indirect_array(  );
private:
  indirect_array(  );
  indirect_array(const indirect_array&);
  indirect_array& operator=(const indirect_array&);
};

The indirect_array class template represents a subset of the elements of a valarray. To create an indirect subset, use valarray’s operator[] with an argument of type valarray<size_t>. The elements of the argument are the desired indices in the subset.

For some operations, the indirect_array object is transparent. In particular, you can assign a valarray to an indirect_array object (provided they have the same size), or you can construct a new valarray from an indirect_array.

If you want to perform other operations, such as non-assignment arithmetic, you must explicitly convert the indirect_array to valarray, as demonstrated in Example 13-44.

Example

Example 13-44. Using indirect_array
int main( ) { using namespace ...

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.