Defined in header
<valarray> | ||
---|---|---|
template< class T > class indirect_array; |
std::gslice_array
is a helper template used by std::indirect_array
subscript operator. It has reference semantics to a subset of the array specified by an indirect array (std::valarray<std::size_t>
object).
Type | Definition |
---|---|
value_type | T |
constructs a indirect_array (public member function) |
|
destroys a indirect_array (public member function) |
|
assigns contents (public member function) |
|
performs arithmetic operation on the array referred by indirect array. (public member function) |
#include <iostream> #include <valarray> int main() { std::valarray<int> data = {0,1,2,3,4,5,6,7,8,9}; std::valarray<std::size_t> idx = {0,2,4,6,8}; std::cout << "Original valarray: "; for(int n: data) std::cout << n << ' '; std::cout << '\n'; data[idx] += data[idx]; // double the values at indexes 'idx' // the type of data[idx] is std::indirect_array<int> std::cout << "After indirect modification: "; for(int n: data) std::cout << n << ' '; std::cout << '\n'; }
Output:
Original valarray: 0 1 2 3 4 5 6 7 8 9 After indirect modification: 0 1 4 3 8 5 12 7 16 9
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/numeric/valarray/indirect_array