最終更新日時:
が更新

履歴 編集

function
<simd>

std::simd::basic_mask::operator[](C++26)

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

処理系

関連項目

参照