最終更新日時:
が更新

履歴 編集

function
<simd>

std::simd::basic_vec::operator<<=(C++26)

friend constexpr basic_vec&
  operator<<=(basic_vec& lhs, const basic_vec& rhs) noexcept; // (1)
friend constexpr basic_vec&
  operator<<=(basic_vec& lhs, simd-size-type n) noexcept;     // (2)

概要

basic_vecオブジェクトの各要素を左ビットシフトし、その結果を左辺に代入する。

  • (1) : 各要素を、rhsの対応する要素が示すビット数だけ左シフトする
  • (2) : 全要素をnビットだけ左シフトする

simd-size-typeは、要素の添字を表現できる符号付き整数型の説明専用の別名である。

テンプレートパラメータ制約

  • (1) : value_type型の値a, bに対して、式a << bが有効であること
  • (2) : value_type型の値asimd-size-type型の値bに対して、式a << bが有効であること

効果

  • (1) : lhsrhsに対して、左ビットシフトを要素ごとの演算として適用する
  • (2) : 以下と等価である

    return operator<<(lhs, basic_vec(n));
    

戻り値

lhs

例外

投げない

#include <simd>
#include <print>
#include <cstdint>

namespace simd = std::simd;

int main()
{
  simd::vec<std::uint8_t, 4> a = [](int i) { return static_cast<std::uint8_t>(i + 1); };  // {1, 2, 3, 4}

  simd::vec<std::uint8_t, 4> a0 = a;  // 演算前の値
  a <<= 1; // 全要素を1ビット左シフト(2倍)

  for (int i = 0; i < a.size(); ++i) {
    std::println("{:08b} << 1 -> {:08b}", a0[i], a[i]);
  }
}

出力

00000001 << 1 -> 00000010
00000010 << 1 -> 00000100
00000011 << 1 -> 00000110
00000100 << 1 -> 00001000

バージョン

言語

  • C++26

処理系

関連項目

参照