Name
gslice class — Generalized slice
Synopsis
class gslice { public: gslice( ); gslice(size_t start, const valarray<size_t>& size, const valarray<size_t>& stride); size_t start( ) const; valarray<size_t> size( ) const; valarray<size_t> stride( ) const; };
The gslice
class describes
a generalized slice of a valarray
. A generalized slice is a subset
of the elements of a valarray
,
characterized by a starting index and a set of sizes and strides.
The size
and stride
arrays must have the same size.
Each size/stride pair denotes a set of elements at periodic indices.
The number of elements in the generalized slice is equal to the
product of the values in the size
array. The elements are taken from a valarray
at each index
i
:
i = start + Σ k
j × stride
j |
in which kj
takes all the values in
the range [0
, size
[j
]), and
j
is in the range [0
, stride.size(
)
). The highest value of j
varies fastest. With a single element in stride
and size
, gslice
is the same as plain slice
. Example 13-41 demonstrates
gslice
more clearly. Pay
particular attention to the final gslice
, where you can see how the indices
advance, first with a stride of 3 (k
1
ranges from 0 to 2), then with a stride of 2
(k
0 ranges from 0 to 3)
Example
// Construct valarray objects from a few integers. std::valarray<std::size_t> va(std::size_t a0) { std::valarray<std::size_t> result(1); result[0] = a0; return result; } std::valarray<std::size_t> va(std::size_t a0, std::size_t a1) { std::valarray<std::size_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.