## slice

    Valarray helpers

- Summary
- Data Type and Member Function Indexes
- Synopsis
- Description
- Interface
- Constructors
- Accessors
- Example
- Warnings
- See Also

### Summary

A numeric array class for representing a BLAS-like slice from an array.

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

Member Functions
size() start() stride()

### Synopsis

    #include <valarray>
    class slice ;

### Description

slice allows you to represent a BLAS-like slice from an array. A BLAS slice contains a starting index, a length, and a stride. The index indicates the first element in the slice, the length determines the number of elements, and the stride indicates the interval between elements in the original array. For instance, the slice (1,3,2) applied to the array (1,2,3,4,5,6,7) produces the array (2,4,6).

When applied to a valarray using the slice subscript operator (see valarray) a slice produces a slice_array. The slice_array gives a view into the original valarray that is tailored to match parameters of the slice. The elements in a slice_array are references to the elements in the original array. This means you need to explicitly copy the slice_array into another valarray in order to have a distinct array.

### Interface

    class slice {
    public:
      // constructors
      slice();
      slice(size_t, size_t, size_t);

      // Accessors
      size_t start() const;
      size_t size() const;
      size_t stride() const;
    };

### Constructors

    slice();

Creates a slice specifying no elements. This constructor is only intended to allow the creation of arrays of slices.

    slice(size_t start, size_t length, size_t stride);

Creates a slice with starting index, length, and stride as indicated by the arguments.

    slice(const slice&)

Creates a slice with starting index, length, and stride as indicated by the slice argument.

### Accessors

    size_t start();

Returns the starting index of the slice.

    size_t size();

Returns the length of the slice.

    size_t stride();

Returns the stride of the slice.

### Example

    //
    // slice.cpp
    //
    #include "valarray.h" // Contains a valarray stream inserter
    using namespace std;
    int main(void)
    {
      int ibuf[10] = {0,1,2,3,4,5,6,7,8,9};

      // create a valarray of ints
      valarray<int>         vi(ibuf,10);
      // print it out
      cout << vi << endl;

      // print out a slice
      cout << valarray<int>(vi[slice(1,3,2)]) << endl;
      return 0;
    }

Program Output

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

### Warnings

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

### See Also

valarray, slice_array, gslice, gslice_array, 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