最終更新日時:
が更新

履歴 編集

function template
<simd>

std::simd::expand(C++26)

namespace std::simd {
  template<simd-vec-type V>
  constexpr V
    expand(const V& v,
           const typename V::mask_type& selector,
           const V& original = {});                // (1) C++26
  template<simd-mask-type V>
  constexpr V
    expand(const V& v,
           const type_identity_t<V>& selector,
           const V& original = {});                // (2) C++26
}

概要

expandは、compressの逆操作を行う関数である。先頭に詰められたデータ並列オブジェクトvの要素を、マスクselectortrueである位置へ順番に展開する。

selectortrueである位置には、vの先頭から昇順に要素が配置される。selectorfalseである位置には、originalの対応する要素が配置される。

戻り値

i番目の要素について、selector[i]trueならばvの対応する要素、falseならばoriginal[i]で初期化されたデータ並列オブジェクト。

例外

投げない

#include <simd>
#include <print>

namespace simd = std::simd;

int main()
{
  // 先頭に詰められた値
  simd::vec<int, 4> v([](int i) { return i + 1; });  // {1, 2, 3, 4}

  // trueの位置へ v の先頭から順に展開する。falseの位置は original(=0) となる
  simd::vec<int, 4>::mask_type selector([](int i) { return i % 2 == 1; });
                                             // {false, true, false, true}
  auto r = simd::expand(v, selector);   // {0, 1, 0, 2}

  for (int i = 0; i < r.size(); ++i)
    std::print("{} ", r[i]);
  std::println("");
}

出力

0 1 0 2 

バージョン

言語

  • C++26

処理系

関連項目

参照