## gslice_array

    Valarray helpers

- Summary
- Data Type and Member Function Indexes
- Synopsis
- Description
- Interface
- Constructors
- Assignment Operators
- Computed Assignment Operators
- Member Functions
- Example
- Warnings
- See Also

### Summary

A numeric array class used to represent a BLAS-like slice from a valarray.

### Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Member Functions
operator%=() operator&=() operator>>=() operator<<=() operator*=() operator+=() | operator-=() operator/=() operator=() operator^=()

### Synopsis

    #include <valarray>
    template <class T>
    class gslice_array ;

### Description

gslice_array<T> creates a gslice view into a valarray. gslice_arrays are only produced by applying the gslice subscript operator to a valarray. The elements in a gslice_array are references to selected elements in the valarray (so changing an element in the gslice_array really changes the corresponding element in the valarray). A gslice_array does not itself hold any distinct elements. The template cannot be instantiated directly since all its constructors are private. However, you can copy a gslice_array to a valarray using either the valarray copy constructor or the assignment operator. Reference semantics are lost at that point.

### Interface

    template <class T> class gslice_array {
    public:

      // types
      typedef T value_type;

      // destructor
      ~gslice_array();

      // public assignment
      void operator= (const valarray<T>& array) const;
      // computed assignment
      void operator*= (const valarray<T>& array) const;
      void operator/= (const valarray<T>& array) const;
      void operator%= (const valarray<T>& array) const;
      void operator+= (const valarray<T>& array) const;
      void operator-= (const valarray<T>& array) const;
      void operator^= (const valarray<T>& array) const;
      void operator&= (const valarray<T>& array) const;
      void operator|= (const valarray<T>& array) const;
      void operator<<= (const valarray<T>& array) const;
      void operator>>= (const valarray<T>& array) const;

      // fill function
      void operator=(const T&);

    private:
      // constructors
      gslice_array();
      gslice_array(const gslice_array<T>&);
      // operator =
      gslice_array<T>& operator= (const gslice_array<T>& array);
    };

### Constructors

    gslice_array();
    gslice_array(const gslice_array&);

All gslice_array constructors are private and cannot be called directly. This prevents copy construction of gslice_arrays.

### Assignment Operators

    void operator=(const valarray<T>& x) const;

Assigns values from `x` to the selected elements of the valarray that self refers to. Remember that a gslice_array never holds any elements itself; it simply refers to selected elements in the valarray used to generate it.

    gslice_array<T>&
    operator=(const gslice-_array<T>& x);

Private assignment operator. Cannot be called directly, thus preventing assignment between gslice_arrays.

### Computed Assignment Operators

    void operator*=(const valarray<T>& val) const;
    void operator/=(const valarray<T>& val) const;
    void operator%=(const valarray<T>& val) const;
    void operator+=(const valarray<T>& val) const;
    void operator-=(const valarray<T>& val) const;
    void operator^=(const valarray<T>& val) const;
    void operator&=(const valarray<T>& val) const;
    void operator|=(const valarray<T>& val) const;
    void operator<<=(const valarray<T>& val) const;
    void operator>>=(const valarray<T>& val) const;

Applies the indicated operation using elements from `val` to the selected elements of the valarray that self refers to. Remember that a gslice_array never holds any elements itself; it simply refers to selected elements in the valarray used to generate it.

### Member Functions

    void operator=(const T& x) const;

Assigns `x` to the selected elements of the valarray that self refers to.

### Example

    //
    // gslice_array.cpp
    //
    #include "valarray.h" // Contains a valarray stream inserter
    using namespace std;

    int main(void)
    {
      int ibuf[27] =
       {0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10};
      int buf13[9] = {13,13,13,13,13,13,13,13,13};
      size_t len_buf[3] = {3,3,3};
      size_t stride_buf[3] = {9,3,1};

      // create a valarray of ints
      valarray<int>  vi(ibuf,27);

      // print out the valarray
      cout << vi << endl;

      // Get a two dimensional diagonal slice out of the middle
      valarray<size_t> len2(2);
      len2[0] = 3;
      len2[1] = 3;
      valarray<size_t> stride2(2);
      stride2[0] = 3;
      stride2[1] = 10;
      gslice_array<int> gsl = vi[gslice(0,len2,stride2)];

      // print out the slice
      cout << gsl << endl;

      // Assign 13's to everything in the slice
      gsl = valarray<int>(buf13,9);

      // print out the slice and our original valarray
      cout << gsl << endl << vi <<  endl;

      return 0;
    }

Program Output

    [0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10]
    [0,2,4,3,5,7,6,8,10]
    [13,13,13,13,13,13,13,13,13]
    [13,1,2,13,4,5,13,7,8,1,13,3,4,13,6,7,13,9,2,3,13,5,6,13,8,9,13]

### Warnings

If your compiler does not support namespaces, then you do not need the using declaration for `std`.

### See Also

valarray, slice_array, slice, gslice, mask_array, indirect_array

Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998