There is no such thing in the standard library as far as I can tell.
http://en.cppreference.com/w/cpp/numeric/valarray/slice
http://en.cppreference.com/w/cpp/numeric/valarray/slice_array
But if you use const std :: valarray, you can use the operator
valarray<T> operator[] (slice slc) const;
which will return another std :: valarray, in which case you can apply std :: slice again.
// slice example #include <iostream> // std::cout #include <cstddef> // std::size_t #include <valarray> // std::valarray, std::slice int main() { std::valarray<int> foo(100); for (int i = 0; i < 100; ++i) foo[i] = i; std::valarray<int> bar = foo[std::slice(2, 20, 4)]; std::cout << "slice(2,20,4):"; for (auto b : bar) std::cout << ' ' << b; std::cout << '\n'; auto const cfoo = foo; std::valarray<int> baz = cfoo[std::slice(2, 20, 4)][std::slice(3, 3, 3)]; std::cout << "slice(3,3,3):"; for (auto b : baz) std::cout << ' ' << b; std::cout << '\n'; return 0; }
Tiago vieira
source share