Share via


slice_array

slice_array

template<class T>
    class slice_array {
public:
    typedef T value_type;
    void operator=(const valarray<T> x) const;
    void operator=(const T& x);
    void operator*=(const valarray<T> x) const;
    void operator/=(const valarray<T> x) const;
    void operator%=(const valarray<T> x) const;
    void operator+=(const valarray<T> x) const;
    void operator-=(const valarray<T> x) const;
    void operator^=(const valarray<T> x) const;
    void operator&=(const valarray<T> x) const;
    void operator|=(const valarray<T> x) const;
    void operator<<=(const valarray<T> x) const;
    void operator>>=(const valarray<T> x) const;
    void fill();
    };

The class describes an object that stores a reference to an object x of class valarray<T>, along with an object sl of class slice which describes the sequence of elements to select from the valarray<T> object.

You construct a slice_array<T> object only by writing an expression of the form x[sl]. The member functions of class slice_array then behave like the corresponding function signatures defined for valarray<T>, except that only the sequence of selected elements is affected.

The sequence consists of sl.size() elements, where element i becomes the index sl.start() + i * sl.stride() within x. For example:

// x[slice(2, 5, 3)] selects elements with indices
//   2, 5, 8, 11, 14