std:: mask_array
From cppreference.net
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::mask_array
| Member functions | ||||
|
定义于头文件
<valarray>
|
||
|
template
<
class
T
>
class
mask_array
;
|
||
std::mask_array
是由
valarray下标运算符
与
std::
valarray
<
bool
>
参数配合使用的辅助模板。它具有引用语义,可访问由索引对应于
std::
valarray
<
bool
>
掩码中
true
值的元素组成的valarray子集。
目录 |
成员类型
| 类型 | 定义 |
value_type
|
T
|
成员函数
构造
mask_array
(公开成员函数) |
|
销毁
mask_array
(公开成员函数) |
|
|
赋值内容
(公开成员函数) |
|
|
对掩码引用的数组执行算术运算
(公开成员函数) |
示例
运行此代码
#include <iostream> #include <valarray> void println(auto rem, const auto& data) { for (std::cout << rem; int n : data) std::cout << n << ' '; std::cout << '\n'; } int main() { std::valarray<int> data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; println("Initial valarray: ", data); data[data > 5] = -1; // the type of data>5 is std::valarray<bool> // the type of data[data>5] is std::mask_array<int> println("After v[v>5]=-1: ", data); }
输出:
Initial valarray: 0 1 2 3 4 5 6 7 8 9 After v[v>5]=-1: 0 1 2 3 4 5 -1 -1 -1 -1
参见
|
(C++26)
|
用于指定宽度的
basic_simd_mask
便捷别名模板
(别名模板) |
|
(parallelism TS v2)
|
元素类型为 bool 的数据并行类型
(类模板) |