Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |utility‎ |bitset
       
       
      Utilities library
       
       
      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) Returns true if all of the bits in*this andrhs are equal.
      2) Returns true if any of the bits in*this andrhs are not equal.

      The!= operator issynthesized fromoperator==.

      (since C++20)

      [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 inrhs, otherwisefalse.
      2)true if!(*this== rhs), otherwisefalse.

      [edit]Example

      Compare given bitsets to determine if they are identical:

      Run this code
      #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: trueb1 == b3: falseb1 != b3: true
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/bitset/operator_cmp&oldid=171727"

      [8]ページ先頭

      ©2009-2025 Movatter.jp