operator==,!=(std::bitset)
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
| (1) | ||
bool operator==( const bitset<N>& rhs ) const; |
(C++11未満) | |
bool operator==( const bitset<N>& rhs ) const noexcept; |
(C++11以上) | |
| (2) | ||
bool operator!=( const bitset<N>& rhs ) const; |
(C++11未満) | |
bool operator!=( const bitset<N>& rhs ) const noexcept; |
(C++11以上) (C++20未満) |
|
1)
*this と rhs のすべてのビットが等しければ true を返します。2)
*this と rhs のいずれかのビットが等しくなければ true を返します。引数
| rhs | - | 比較するビットセット |
戻り値
1)
*this 内の各ビットの値が rhs 内の対応するビットの値と等しければ true、そうでなければ false。2)
!(*this == rhs) であれば true、そうでなければ false。例
2つのビットセットが同一かどうかを調べるために比較します。
Run this code
#include <iostream>
#include <bitset>
int main()
{
std::bitset<4> b1(3); // [0,0,1,1]
std::bitset<4> b2(b1);
std::bitset<4> b3(4); // [0,1,0,0]
std::cout << "b1 == b2: " << (b1 == b2) << '\n';
std::cout << "b1 == b3: " << (b1 == b3) << '\n';
std::cout << "b1 != b3: " << (b1 != b3) << '\n';
}
出力:
b1 == b2: 1
b1 == b3: 0
b1 != b3: 1