constexpr value_type operator[](simd-size-type i) const; // (1) C++26
template<simd-integral I>
constexpr resize_t<I::size(), basic_mask>
operator[](const I& indices) const; // (2) C++26
概要
- (1) : 指定した位置の単一要素の値を取得する
- (2) : 添字を保持したデータ並列型
indicesを渡し、それらの位置の要素を並べ替えたbasic_maskを取得する
事前条件
- (1) :
i >= 0 && i < size()であること
効果
- (2) : 以下と等価である。
return permute(*this, indices);
戻り値
- (1) :
i番目の要素の値 - (2) :
indicesの第j要素が指すインデックスの要素を第j要素とするbasic_mask。要素数はindicesの要素数(I::size())となる
例外
- (1) : 投げない
例
#include <simd>
#include <print>
namespace simd = std::simd;
int main()
{
simd::mask<int, 4> m = [](int i) { return i % 2 == 0; }; // {true, false, true, false}
// (1) 位置を指定して要素を取得する
for (int i = 0; i < m.size(); ++i) {
std::print("{} ", m[i]);
}
std::println("");
}
出力
true false true false
バージョン
言語
- C++26
処理系
- Clang: 22 ❌
- GCC: 16.1 ❌
- Visual C++: 2026 Update 2 ❌
関連項目
参照
- P1928R15 std::simd — merge data-parallel types from the Parallelism TS 2
- C++26で
std::simdが追加された
- C++26で
- P2876R3 Proposal to extend
std::simdwith more constructors and accessors- インデックス列による並べ替えを取得する添字演算子が追加された