Namespaces
Variants

std::bitset<N>::operator==, std::bitset<N>::operator!=

cppreference.net에서 가져옴
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 폐기 예정)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
교환(swap) 및 타입 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
일반 어휘 타입
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
 
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를 반환합니다.

!= 연산자는 로부터 합성operator==됩니다.

(C++20부터)

매개변수

rhs - 비교할 bitset

반환값

1) true * this 의 각 비트 값이 rhs 의 해당 비트 값과 같으면, 그렇지 않으면 false 를 반환합니다.
2) true 만약 ! ( * this == rhs ) 인 경우, 그렇지 않으면 false .

예제

주어진 비트셋들이 동일한지 비교합니다:

#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