std::bitset::flip(3)
π
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 ofstd::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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms