Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::bitset<N>::flip

      From cppreference.com
      <cpp‎ |utility‎ |bitset
       
       
      Utilities library
       
       
      bitset& flip();
      (1)(noexcept since C++11)
      (constexpr since C++23)
      bitset& flip(std::size_t pos);
      (2)(constexpr since C++23)

      Flips bits, i.e. changestrue values tofalse andfalse values totrue. Equivalent to a logical NOT operation on part or all of the bitset.

      1) Flips all bits (likeoperator~, but in-place).
      2) Flips the bit at the positionpos.

      Contents

      [edit]Parameters

      pos - the position of the bit to flip

      [edit]Return value

      *this

      [edit]Exceptions

      2) Throwsstd::out_of_range ifpos does not correspond to a valid bit position.

      [edit]Example

      Run this code
      #include <bitset>#include <iostream> int main(){std::bitset<4> flops; std::cout<< flops<<'\n'<< flops.flip(0)<<'\n'<< flops.flip(2)<<'\n'<< flops.flip()<<'\n';}

      Output:

      0000000101011010

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2250C++98the behavior was undefined ifpos does
      not correspond to a valid bit position
      always throws an
      exception in this case

      [edit]See also

      sets bits totrue or given value
      (public member function)[edit]
      sets bits tofalse
      (public member function)[edit]
      performs binary AND, OR, XOR and NOT
      (public member function)[edit]
      flips all the bits
      (public member function ofstd::vector<bool,Allocator>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/bitset/flip&oldid=178325"

      [8]ページ先頭

      ©2009-2025 Movatter.jp