| (1) | ||
bool operator==( const bitset& rhs ) const; | (until C++11) | |
bool operator==( const bitset& rhs ) const noexcept; | (since C++11) (until C++23) | |
constexpr bool operator==( const bitset& rhs ) const noexcept; | (since C++23) | |
| (2) | ||
bool operator!=( const bitset& rhs ) const; | (until C++11) | |
bool operator!=( const bitset& rhs ) const noexcept; | (since C++11) (until C++20) |
*this and rhs are equal.*this and rhs are not equal.| The | (since C++20) |
| rhs | - | bitset to compare |
true if the value of each bit in *this equals the value of the corresponding bit in rhs, otherwise false
true if !(*this == rhs), otherwise false
Compare given bitsets to determine if they are identical:
#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
}Output:
b1 == b2: true b1 == b3: false b1 != b3: true
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/utility/bitset/operator_cmp