std::bitset<N>::operator==, std::bitset<N>::operator!=
From cppreference.com
bool operator==( const bitset& rhs ) const; |
(1) | (C++11 以降 noexcept) (C++23 以降 constexpr) |
bool operator!=( const bitset& rhs ) const; |
(2) | (C++11 以降 noexcept) (C++20まで) |
1) *this と rhs のすべてのビットが等しい場合に true を返します。
2) *this と rhs のいずれかのビットが等しくない場合に true を返します。
|
|
(C++20以降) |
[編集] Parameters
| rhs | - | 比較するビットセット |
[編集] Return value
1) true。 *this の各ビットの値が、rhs の対応するビットの値と等しい場合。それ以外の場合は false。
2) true。 !(*this == rhs) の場合。それ以外の場合は false。
[編集] Example
指定されたビットセットを比較して、それらが同一かどうかを判断します。
このコードを実行
#include <bitset> #include <iostream> int main() { std::bitset<4> b1(0b0011); std::bitset<4> b2(b1); std::bitset<4> b3(0b0100); std::cout << std::boolalpha; std::cout << "b1 == b2: " << (b1 == b2) << '\n'; std::cout << "b1 == b3: " << (b1 == b3) << '\n'; std::cout << "b1 != b3: " << (b1 != b3) << '\n'; // b1 == std::bitset<3>{}; // compile-time error: incompatible types }
出力
b1 == b2: true b1 == b3: false b1 != b3: true