std::bitset<N>:: operator==, std::bitset<N>:: operator!=
From cppreference.net
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::bitset
| Member types | ||||
| Member functions | ||||
|
bitset::operator==
bitset::operator!=
(until C++20)
|
||||
| Element access | ||||
| Capacity | ||||
| Modifiers | ||||
| Conversions | ||||
|
(C++11)
|
||||
| Non-member functions | ||||
| Helper classes | ||||
|
(C++11)
|
||||
|
bool
operator
==
(
const
bitset
&
rhs
)
const
;
|
(1) |
(noexcept seit C++11)
(constexpr seit C++23) |
|
bool
operator
!
=
(
const
bitset
&
rhs
)
const
;
|
(2) |
(noexcept seit C++11)
(bis C++20) |
1)
Gibt true zurück, wenn alle Bits in
*
this
und
rhs
gleich sind.
2)
Gibt true zurück, wenn irgendwelche Bits in
*
this
und
rhs
nicht gleich sind.
|
Der
|
(seit C++20) |
Parameter
| rhs | - | zu vergleichendes Bitset |
Rückgabewert
1)
true
wenn der Wert jedes Bits in
*
this
dem Wert des entsprechenden Bits in
rhs
entspricht, andernfalls
false
.
2)
true
falls
!
(
*
this
==
rhs
)
, andernfalls
false
.
Beispiel
Vergleichen Sie gegebene Bitsets, um festzustellen, ob sie identisch sind:
Diesen Code ausführen
#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 }
Ausgabe:
b1 == b2: true b1 == b3: false b1 != b3: true