std:: indirect_array
| 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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||||||||||||||
| Non-member functions | ||||||||||||||||
| Helper classes | ||||||||||||||||
|
||||||||||||||||
| Deduction guides (C++17) | ||||||||||||||||
| Member functions | ||||
|
定义于头文件
<valarray>
|
||
|
template
<
class
T
>
class
indirect_array
;
|
||
std::indirect_array
是由
valarray下标运算符
与
std::
valarray
<
std::
size_t
>
参数共同使用的辅助模板。它具有对数组中由
std::
valarray
<
std::
size_t
>
对象指定索引的子集的引用语义。
成员类型
| 类型 | 定义 |
value_type
|
T
|
成员函数
构造
indirect_array
(公开成员函数) |
|
销毁
indirect_array
(公开成员函数) |
|
|
赋值内容
(公开成员函数) |
|
|
对间接数组引用的数组执行算术运算
(公开成员函数) |
示例
#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]; // 将索引 'idx' 处的值翻倍 // data[idx] 的类型是 std::indirect_array<int> std::cout << "After indirect modification: "; for (int n : data) std::cout << n << ' '; std::cout << '\n'; }
输出:
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