Namespaces
Variants
Views
Actions

operator==,!=(std::bitset)

From cppreference.com
< cpp‎ | utility‎ | bitset
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++14)
(C++11)

(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

Elementary string conversions
(C++17)
(C++17)
 
 
(1)
bool operator==( const bitset<N>& rhs ) const;
(until C++11)
bool operator==( const bitset<N>& rhs ) const noexcept;
(since C++11)
(2)
bool operator!=( const bitset<N>& rhs ) const;
(until C++11)
bool operator!=( const bitset<N>& rhs ) const noexcept;
(since C++11)
(until C++20)
1) Returns true if all of the bits in *this and rhs are equal.
2) Returns true if any of the bits in *this and rhs are not equal.

[edit] Parameters

rhs - bitset to compare

[edit] Return value

1) true if the value of each bit in *this equals the value of the corresponding bit in rhs, otherwise false
2) true if !(*this == rhs), otherwise false

[edit] Example

Compare two bitsets to determine if they are identical:

#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';
}

Output:

b1 == b2: 1
b1 == b3: 0
b1 != b3: 1