std::indirect_array
From cppreference.com
C++
Numerics library
| Common mathematical functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical special functions (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical constants (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic linear algebra algorithms (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data-parallel types (SIMD) (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Floating-point environment (C++11) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Complex numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric array (valarray) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pseudo-random number generation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bit manipulation (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Saturation arithmetic (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C-style checked integer arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::valarray
| Member functions | ||||||||||||||||
| Non-member functions | ||||||||||||||||
| Helper classes | ||||||||||||||||
| ||||||||||||||||
| Deduction guides (C++17) | ||||||||||||||||
std::indirect_array
| Member functions | ||||
| Defined in header <valarray>
|
|
| template< class T > class indirect_array; |
|
std::indirect_array is a helper template used by the valarray subscript operator with std::valarray<std::size_t> argument. It has reference semantics to a subset of the array whose indices specified by the std::valarray<std::size_t> object.
[edit] Member types
| Type | Definition |
value_type
|
T
|
[edit] Member functions
constructs a indirect_array (public member function) [edit] | |
destroys a indirect_array (public member function) [edit] | |
| assigns contents (public member function) [edit] | |
| performs arithmetic operation on the array referred by indirect array. (public member function) [edit] |
[edit] Example
Run this code
#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 indices '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