std::experimental::where_expression
来自cppreference.com
| 在标头 <experimental/simd> 定义
|
||
| |
(并行 TS v2) | |
类模板 where_expression 抽象给定的算术或数据并行类型非 const 对象的被选择元素的概念。被选择元素为 V 类型的左值,其对应的掩码元素(类型为 M)为 true。应用于 where_expression<M, V> 类型对象的运算符仅对被选择元素应用。遗留所有其他元素未改变。
使用 where 函数构造 where_expression 对象。
模板形参
| M | - | 掩码类型 |
| V | - | 应用 M 到其上的值类型 |
(M, V) 的合法组合是:
(simd_mask<T, Abi>,simd<T, Abi>),(simd_mask<T, Abi>,simd_mask<T, Abi>),(bool,T)。
成员函数
| 赋值被选择位置 (公开成员函数) | |
| 复合赋值运算符 (公开成员函数) | |
| 自增和自减运算符 (公开成员函数) | |
| 从地址加载到被选择位置 (公开成员函数) |
示例
运行此代码
#include <cstddef>
#include <experimental/simd>
#include <iostream>
namespace stdx = std::experimental;
void print(auto const& a)
{
for (std::size_t i{}; i != std::size(a); ++i)
std::cout << a[i] << ' ';
std::cout << '\n';
}
template<class A>
stdx::simd<int, A> my_abs(stdx::simd<int, A> x)
{
where(x < 0, x) = -x;
return x;
}
int main()
{
const stdx::native_simd<int> a([](int i) { return i - 2; });
print(a);
const auto b = my_abs(a);
print(b);
}
可能的输出:
-2 -1 0 1
2 1 0 1