std::bitset::flip(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::bitset::flip(3) β€” C++ Standard Libary, bestie πŸ’…

okay so this is std::bitset::flip, straight from the C++ Standard Libary (yes, that's the manual name right there), and it is literally the glow-up button for your bits. true becomes false, false becomes true β€” no cap, it's a logical NOT for part or all of the bitset. ✨

πŸŽ€ NAME πŸŽ€

  • std::bitset::flip - std::bitset::flip β€” yes bestie, that's the whole name, it's giving self-titled era πŸ’…

🌸 Synopsis 🌸

bitset& flip();                  (1) (noexcept since C++11)
                                             (constexpr since C++23)
bitset& flip( std::size_t pos ); (2) (constexpr since C++23)

okay so overload (1) flips all the bits β€” like operator~, but in-place. Overload (2) flips the bit at the position pos. Both are out here doing the most useful little bit inversion. πŸ¦‹

πŸ“ Parameters πŸ“

  • pos β€” the position of the bit to flip

πŸ‘‘ Return value πŸ‘‘

*this β€” that's it, that's the return value, and it's iconic.

πŸ’€ Exceptions πŸ’€

Overload 2) throws std::out_of_range if pos does not correspond to a valid position within the bitset. That's the danger zone, bestie β€” if pos is not valid, it is not gonna be cute.

πŸ”₯ 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: 🌈

0000
0001
0101
1010

🫢 See also 🫢

  • set β€” sets bits to true or given value (public member function)
  • reset β€” sets bits to false (public member function)
  • operator&=, operator|=, operator^=, operator~ β€” performs binary AND, OR, XOR and NOT (public member function)
  • flip β€” flips all the bits (public member function of std::vector<bool,Allocator>)

source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::bitset::flip(3) β€” stay flipped, bestie πŸ’‹

πŸ“¦ where this page comes from