std::bitset<N>::operator==, std::bitset<N>::operator!=
bool operator==( const bitset& rhs ) const; | (1) |
(noexcept since C++11) (constexpr since C++23) |
bool operator!=( const bitset& rhs ) const; | (2) |
(noexcept since C++11) (until C++20) |
1) Возвращает true, если все биты в
*this и rhs равны.
2) Возвращает true, если какие-либо биты в
*this и rhs не равны.| Оператор | (с C++20) |
Параметры
| rhs | - | битовый набор для сравнения |
Возвращаемое значение
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
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/utility/bitset/operator_cmp