最終更新日時(UTC):
が更新

履歴 編集

function
<bitset>

std::bitset::operator~

bitset<N> operator~() const;          // (1) C++03
bitset<N> operator~() const noexcept; // (1) C++11
constexpr bitset<N> operator~() const noexcept; // (1) C++23

概要

ビットを反転させる。

戻り値

*thisのビットを反転させたbitsetオブジェクトを生成して返す。
この関数は、以下のプログラムと同じ動作をする:

return bitset(*this).flip();

例外

投げない。

#include <iostream>
#include <bitset>

int main()
{
  std::bitset<4> bs("0011");

  std::bitset<4> result = ~bs;

  std::cout << result << std::endl;
}

出力

1100

参照