本文共 1344 字,大约阅读时间需要 4 分钟。
std::slice
This class represents a
slice selector. It does not contain nor refers to any element - it only describes a selection of elements to be used as an index in
.
A
valarray slice is defined by a
starting index, a
size, and a
stride.
The
starting index (
) is the index of the first element in the selection.
The
size (
) is the number of elements in the selection.
The
stride (
) is the span that separates the elements selected.
Therefore, a slice with a stride higher than 1 does not select contiguous elements in the
; For example,
slice(3,4,5)
selects the elements 3, 8, 13 and 18.
Member functions
- slice constructor (public member function )
- Return start of slice (public member function )
- Return size of slice (public member function )
- Return stride of slice (public member function )
Example
12345678910111213141516171819 | // slice example#include // std::cout#include // std::size_t#include // std::valarray, std::sliceint main (){ std::valarray foo (12); for (int i=0; i<12; ++i) foo[i]=i; std::valarray bar = foo[std::slice(2,3,4)]; std::cout << "slice(2,3,4):"; for (std::size_t n=0; n | |
Output
转载地址:http://fjxdi.baihongyu.com/