std::slice (3) - Linux Manuals
std::slice: std::slice
NAME
Synopsis
Defined in header <valarray>
class slice;
std::slice is the selector class that identifies a subset of std::valarray similar to BLAS slice. An object of type std::slice holds three values: the starting index, the stride, and the total number of values in the subset. Objects of type std::slice can be used as indexes with valarray's operator[].
Member functions
constructor (public member function)
start returns the parameters of the slice
size (public member function)
stride
std::slice::slice
slice()
slice( std::size_t start, std::size_t size, std::size_t stride );
slice( const slice& other );
Constructs a new slice.
1) Default constructor. Equivalent to slice(0, 0, 0). This constructor exists only to allow construction of arrays of slices.
2) Constructs a new slice with parameters start, size, stride. This slice will refer to size number of elements, each with the position:
start + 0*stride
start + 1*stride
...
start + (size-1)*stride
3) Constructs a copy of other.
Parameters
start - the position of the first element
size - the number of elements in the slice
stride - the number of positions between successive elements in the slice
other - another slice to copy
std::slice::start, size, stride
std::size_t start() const; (1)
std::size_t size() const; (2)
std::size_t stride() const; (3)
Returns the parameters passed to the slice on construction - start, size and stride respectively.
Parameters
(none)
Return value
The parameters of the slice -- start, size and stride respectively.
Complexity
Constant.
Example
Barebones valarray-backed Matrix class with a trace calculating function.
// Run this code
Output:
See also
operator[] (public member function)
gslice (class)
slice_array (class template)