Name

mask_array class template — Helper class for mask arrays

Synopsis

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

The mask_array class template represents a subset of the elements of a valarray. To create a mask subset, use valarray’s operator[] with an argument of type valarray<bool>. An element is included in the result set if the corresponding element in the argument is true.

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

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

Example

Example 13-45. Using mask_array
// Simple average template<typename T> T avg(const std::valarray<T>& ...

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.