std::experimental::where_expression
From cppreference.com
< cpp | experimental | simd
| ヘッダー <experimental/simd> で定義 |
||
| template< class M, class V > class where_expression; |
(parallelism TS v2) | |
クラステンプレートwhere_expressionは、指定された算術型またはデータ並列型の左辺値から選択された要素という概念を抽象化します。選択された要素とは、左辺値(V型)の要素のうち、対応するマスク(M型)の要素が真であるような要素のことです。where_expression<M, V>型のオブジェクトに適用される演算子は、選択された要素にのみ適用されます。その他の要素は変更されません。
where_expressionオブジェクトを構築するには、where関数を使用します。
[編集] テンプレートパラメータ
| M | - | マスクの型 |
| V | - | 適用される値の型 M |
(M, V)の有効な組み合わせは次のとおりです。
-
(simd_mask<T, Abi>,simd<T, Abi>), -
(simd_mask<T, Abi>,simd_mask<T, Abi>), -
(bool,T).
[編集] メンバ関数
| 選択された位置への代入 (public member function) | |
| 複合代入演算子 (public member function) | |
| インクリメントおよびデクリメント演算子 (public member function) | |
| アドレスから選択された位置へのロード (public member function) |
[編集] 例
このコードを実行
#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