最終更新日時:
が更新

履歴 編集

function
<simd>

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

friend constexpr basic_vec& operator&=(basic_vec& lhs, const basic_vec& rhs) noexcept;

概要

2つのbasic_vecオブジェクトを要素ごとにビット論理積し、その結果を左辺に代入する。

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

value_type型の値a, bに対して、式a & bが有効であること。

効果

lhsrhsに対して、ビット論理積を要素ごとの演算として適用する。

戻り値

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); };  // {0, 1, 2, 3}
  simd::vec<std::uint8_t, 4> b = std::uint8_t{1};  // {1, 1, 1, 1}

  simd::vec<std::uint8_t, 4> a0 = a;  // 演算前の値
  a &= b;

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

出力

00000000 & 00000001 -> 00000000
00000001 & 00000001 -> 00000001
00000010 & 00000001 -> 00000000
00000011 & 00000001 -> 00000001

バージョン

言語

  • C++26

処理系

関連項目

参照