-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify flip() for std::bitset #120807
Open
winner245
wants to merge
1
commit into
llvm:main
Choose a base branch
from
winner245:simplify-flip-for-bit_set
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Simplify flip() for std::bitset #120807
+152
−133
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
winner245
changed the title
Simplify flip() for std::bit_set
Simplify flip() for std::bitset
Dec 21, 2024
winner245
force-pushed
the
simplify-flip-for-bit_set
branch
2 times, most recently
from
December 21, 2024 12:22
cda3842
to
67a745e
Compare
winner245
force-pushed
the
simplify-flip-for-bit_set
branch
2 times, most recently
from
December 30, 2024 03:57
1317d65
to
355e08c
Compare
winner245
force-pushed
the
simplify-flip-for-bit_set
branch
from
January 2, 2025 16:52
355e08c
to
6fed773
Compare
llvmbot
added
the
libc++
libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
label
Jan 2, 2025
@llvm/pr-subscribers-libcxx Author: Peng Liu (winner245) ChangesThis PR simplifies the internal bitwise logic of the Patch is 21.36 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/120807.diff 3 Files Affected:
diff --git a/libcxx/include/bitset b/libcxx/include/bitset
index 919d2a0f07e096..fc6b0b958c0bc8 100644
--- a/libcxx/include/bitset
+++ b/libcxx/include/bitset
@@ -327,12 +327,8 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Siz
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
*__p = ~*__p;
// do last partial word
- if (__n > 0) {
- __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
- __storage_type __b = *__p & __m;
- *__p &= ~__m;
- *__p |= ~__b & __m;
- }
+ if (__n > 0)
+ *__p ^= (__storage_type(1) << __n) - 1;
}
template <size_t _N_words, size_t _Size>
@@ -514,9 +510,7 @@ __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
template <size_t _Size>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<1, _Size>::flip() _NOEXCEPT {
- __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
- __first_ = ~__first_;
- __first_ &= __m;
+ __first_ ^= ~__storage_type(0) >> (__bits_per_word - _Size);
}
template <size_t _Size>
diff --git a/libcxx/test/std/utilities/template.bitset/bitset.members/flip_all.pass.cpp b/libcxx/test/std/utilities/template.bitset/bitset.members/flip_all.pass.cpp
index 79fa505e63cd3d..55401367cd08fc 100644
--- a/libcxx/test/std/utilities/template.bitset/bitset.members/flip_all.pass.cpp
+++ b/libcxx/test/std/utilities/template.bitset/bitset.members/flip_all.pass.cpp
@@ -18,19 +18,21 @@
template <std::size_t N>
TEST_CONSTEXPR_CXX23 void test_flip_all() {
- std::vector<std::bitset<N> > const cases = get_test_cases<N>();
- for (std::size_t c = 0; c != cases.size(); ++c) {
- std::bitset<N> v1 = cases[c];
- std::bitset<N> v2 = v1;
- v2.flip();
- for (std::size_t i = 0; i < v1.size(); ++i)
- assert(v2[i] == ~v1[i]);
- }
+ std::vector<std::bitset<N> > const cases = get_test_cases<N>();
+ for (std::size_t c = 0; c != cases.size(); ++c) {
+ std::bitset<N> v1 = cases[c];
+ std::bitset<N> v2 = v1;
+ v2.flip();
+ for (std::size_t i = 0; i < v1.size(); ++i)
+ assert(v2[i] == ~v1[i]);
+ }
}
TEST_CONSTEXPR_CXX23 bool test() {
test_flip_all<0>();
test_flip_all<1>();
+ test_flip_all<2>();
+ test_flip_all<5>();
test_flip_all<31>();
test_flip_all<32>();
test_flip_all<33>();
diff --git a/libcxx/test/std/utilities/template.bitset/bitset_test_cases.h b/libcxx/test/std/utilities/template.bitset/bitset_test_cases.h
index dada9bcca8f486..1ca19ec469e2c9 100644
--- a/libcxx/test/std/utilities/template.bitset/bitset_test_cases.h
+++ b/libcxx/test/std/utilities/template.bitset/bitset_test_cases.h
@@ -20,161 +20,184 @@ TEST_CONSTEXPR_CXX23 std::vector<std::bitset<N> > get_test_cases();
template <>
TEST_CONSTEXPR_CXX23 inline std::vector<std::bitset<0> > get_test_cases<0>() {
- std::vector<std::bitset<0> > cases;
- cases.push_back(std::bitset<0>());
- return cases;
+ std::vector<std::bitset<0> > cases;
+ cases.push_back(std::bitset<0>());
+ return cases;
}
template <>
TEST_CONSTEXPR_CXX23 inline std::vector<std::bitset<1> > get_test_cases<1>() {
- std::vector<std::bitset<1> > cases;
- cases.push_back(std::bitset<1>("0"));
- cases.push_back(std::bitset<1>("1"));
- return cases;
+ std::vector<std::bitset<1> > cases;
+ cases.push_back(std::bitset<1>("0"));
+ cases.push_back(std::bitset<1>("1"));
+ return cases;
}
template <>
TEST_CONSTEXPR_CXX23 inline std::vector<std::bitset<2> > get_test_cases<2>() {
- std::vector<std::bitset<2> > cases;
- cases.push_back(std::bitset<2>("00"));
- cases.push_back(std::bitset<2>("01"));
- cases.push_back(std::bitset<2>("10"));
- cases.push_back(std::bitset<2>("11"));
- return cases;
+ std::vector<std::bitset<2> > cases;
+ cases.push_back(std::bitset<2>("00"));
+ cases.push_back(std::bitset<2>("01"));
+ cases.push_back(std::bitset<2>("10"));
+ cases.push_back(std::bitset<2>("11"));
+ return cases;
+}
+
+template <>
+TEST_CONSTEXPR_CXX23 inline std::vector<std::bitset<5> > get_test_cases<5>() {
+ std::vector<std::bitset<5> > cases;
+ cases.push_back(std::bitset<5>("00000"));
+ cases.push_back(std::bitset<5>("00001"));
+ cases.push_back(std::bitset<5>("10000"));
+ cases.push_back(std::bitset<5>("00010"));
+ cases.push_back(std::bitset<5>("01000"));
+ cases.push_back(std::bitset<5>("00011"));
+ cases.push_back(std::bitset<5>("11000"));
+ cases.push_back(std::bitset<5>("00100"));
+ cases.push_back(std::bitset<5>("11011"));
+ cases.push_back(std::bitset<5>("00101"));
+ cases.push_back(std::bitset<5>("10100"));
+ cases.push_back(std::bitset<5>("00110"));
+ cases.push_back(std::bitset<5>("01100"));
+ cases.push_back(std::bitset<5>("00111"));
+ cases.push_back(std::bitset<5>("11100"));
+ cases.push_back(std::bitset<5>("11111"));
+ return cases;
}
template <>
TEST_CONSTEXPR_CXX23 inline std::vector<std::bitset<31> > get_test_cases<31>() {
- std::vector<std::bitset<31> > cases;
- cases.push_back(std::bitset<31>("0000000000000000000000000000000"));
- cases.push_back(std::bitset<31>("0000000000000000000000000000001"));
- cases.push_back(std::bitset<31>("1000000000000000000000000000000"));
- cases.push_back(std::bitset<31>("1000000000000000000000000000001"));
- cases.push_back(std::bitset<31>("1000000000000000000001000000001"));
- cases.push_back(std::bitset<31>("0000000000000000111111111111111"));
- cases.push_back(std::bitset<31>("1000000000000000111111111111111"));
- cases.push_back(std::bitset<31>("1111111111111111000000000000000"));
- cases.push_back(std::bitset<31>("1111111111111111000000000000001"));
- cases.push_back(std::bitset<31>("1010101010101010101010101010101"));
- cases.push_back(std::bitset<31>("0101010101010101010101010101010"));
- cases.push_back(std::bitset<31>("1111111111111111111111111111111"));
- return cases;
+ std::vector<std::bitset<31> > cases;
+ cases.push_back(std::bitset<31>("0000000000000000000000000000000"));
+ cases.push_back(std::bitset<31>("0000000000000000000000000000001"));
+ cases.push_back(std::bitset<31>("1000000000000000000000000000000"));
+ cases.push_back(std::bitset<31>("1000000000000000000000000000001"));
+ cases.push_back(std::bitset<31>("1000000000000000000001000000001"));
+ cases.push_back(std::bitset<31>("0000000000000000111111111111111"));
+ cases.push_back(std::bitset<31>("1000000000000000111111111111111"));
+ cases.push_back(std::bitset<31>("1111111111111111000000000000000"));
+ cases.push_back(std::bitset<31>("1111111111111111000000000000001"));
+ cases.push_back(std::bitset<31>("1010101010101010101010101010101"));
+ cases.push_back(std::bitset<31>("0101010101010101010101010101010"));
+ cases.push_back(std::bitset<31>("1111111111111111111111111111111"));
+ return cases;
}
template <>
TEST_CONSTEXPR_CXX23 inline std::vector<std::bitset<32> > get_test_cases<32>() {
- std::vector<std::bitset<32> > cases;
- cases.push_back(std::bitset<32>("00000000000000000000000000000000"));
- cases.push_back(std::bitset<32>("00000000000000000000000000000001"));
- cases.push_back(std::bitset<32>("10000000000000000000000000000000"));
- cases.push_back(std::bitset<32>("10000000000000000000000000000001"));
- cases.push_back(std::bitset<32>("10000000000000000000111000000001"));
- cases.push_back(std::bitset<32>("00000000000000001111111111111111"));
- cases.push_back(std::bitset<32>("10000000000000001111111111111111"));
- cases.push_back(std::bitset<32>("11111111111111110000000000000000"));
- cases.push_back(std::bitset<32>("11111111111111110000000000000001"));
- cases.push_back(std::bitset<32>("10101010101010101010101010101010"));
- cases.push_back(std::bitset<32>("01010101010101010101010101010101"));
- cases.push_back(std::bitset<32>("11111111111111111111111111111111"));
- return cases;
+ std::vector<std::bitset<32> > cases;
+ cases.push_back(std::bitset<32>("00000000000000000000000000000000"));
+ cases.push_back(std::bitset<32>("00000000000000000000000000000001"));
+ cases.push_back(std::bitset<32>("10000000000000000000000000000000"));
+ cases.push_back(std::bitset<32>("10000000000000000000000000000001"));
+ cases.push_back(std::bitset<32>("10000000000000000000111000000001"));
+ cases.push_back(std::bitset<32>("00000000000000001111111111111111"));
+ cases.push_back(std::bitset<32>("10000000000000001111111111111111"));
+ cases.push_back(std::bitset<32>("11111111111111110000000000000000"));
+ cases.push_back(std::bitset<32>("11111111111111110000000000000001"));
+ cases.push_back(std::bitset<32>("10101010101010101010101010101010"));
+ cases.push_back(std::bitset<32>("01010101010101010101010101010101"));
+ cases.push_back(std::bitset<32>("11111111111111111111111111111111"));
+ return cases;
}
template <>
TEST_CONSTEXPR_CXX23 inline std::vector<std::bitset<33> > get_test_cases<33>() {
- std::vector<std::bitset<33> > cases;
- cases.push_back(std::bitset<33>("000000000000000000000000000000000"));
- cases.push_back(std::bitset<33>("000000000000000000000000000000001"));
- cases.push_back(std::bitset<33>("100000000000000000000000000000000"));
- cases.push_back(std::bitset<33>("100000000000000000000000000000001"));
- cases.push_back(std::bitset<33>("100000000000000000001110000000001"));
- cases.push_back(std::bitset<33>("000000000000000011111111111111111"));
- cases.push_back(std::bitset<33>("100000000000000011111111111111111"));
- cases.push_back(std::bitset<33>("111111111111111100000000000000000"));
- cases.push_back(std::bitset<33>("111111111111111100000000000000001"));
- cases.push_back(std::bitset<33>("101010101010101010101010101010101"));
- cases.push_back(std::bitset<33>("010101010101010101010101010101010"));
- cases.push_back(std::bitset<33>("111111111111111111111111111111111"));
- return cases;
+ std::vector<std::bitset<33> > cases;
+ cases.push_back(std::bitset<33>("000000000000000000000000000000000"));
+ cases.push_back(std::bitset<33>("000000000000000000000000000000001"));
+ cases.push_back(std::bitset<33>("100000000000000000000000000000000"));
+ cases.push_back(std::bitset<33>("100000000000000000000000000000001"));
+ cases.push_back(std::bitset<33>("100000000000000000001110000000001"));
+ cases.push_back(std::bitset<33>("000000000000000011111111111111111"));
+ cases.push_back(std::bitset<33>("100000000000000011111111111111111"));
+ cases.push_back(std::bitset<33>("111111111111111100000000000000000"));
+ cases.push_back(std::bitset<33>("111111111111111100000000000000001"));
+ cases.push_back(std::bitset<33>("101010101010101010101010101010101"));
+ cases.push_back(std::bitset<33>("010101010101010101010101010101010"));
+ cases.push_back(std::bitset<33>("111111111111111111111111111111111"));
+ return cases;
}
template <>
TEST_CONSTEXPR_CXX23 inline std::vector<std::bitset<63> > get_test_cases<63>() {
- std::vector<std::bitset<63> > cases;
- cases.push_back(std::bitset<63>("000000000000000000000000000000000000000000000000000000000000000"));
- cases.push_back(std::bitset<63>("000000000000000000000000000000000000000000000000000000000000001"));
- cases.push_back(std::bitset<63>("100000000000000000000000000000000000000000000000000000000000000"));
- cases.push_back(std::bitset<63>("100000000000000000000000000000000000000000000000000000000000001"));
- cases.push_back(std::bitset<63>("100000000000000000000000001111100000000000000000000000000000001"));
- cases.push_back(std::bitset<63>("000000000000000000000000000000001111111111111111111111111111111"));
- cases.push_back(std::bitset<63>("100000000000000000000000000000001111111111111111111111111111111"));
- cases.push_back(std::bitset<63>("111111111111111111111111111111110000000000000000000000000000000"));
- cases.push_back(std::bitset<63>("111111111111111111111111111111110000000000000000000000000000001"));
- cases.push_back(std::bitset<63>("101010101010101010101010101010101010101010101010101010101010101"));
- cases.push_back(std::bitset<63>("010101010101010101010101010101010101010101010101010101010101010"));
- cases.push_back(std::bitset<63>("111111111111111111111111111111111111111111111111111111111111111"));
- return cases;
+ std::vector<std::bitset<63> > cases;
+ cases.push_back(std::bitset<63>("000000000000000000000000000000000000000000000000000000000000000"));
+ cases.push_back(std::bitset<63>("000000000000000000000000000000000000000000000000000000000000001"));
+ cases.push_back(std::bitset<63>("100000000000000000000000000000000000000000000000000000000000000"));
+ cases.push_back(std::bitset<63>("100000000000000000000000000000000000000000000000000000000000001"));
+ cases.push_back(std::bitset<63>("100000000000000000000000001111100000000000000000000000000000001"));
+ cases.push_back(std::bitset<63>("000000000000000000000000000000001111111111111111111111111111111"));
+ cases.push_back(std::bitset<63>("100000000000000000000000000000001111111111111111111111111111111"));
+ cases.push_back(std::bitset<63>("111111111111111111111111111111110000000000000000000000000000000"));
+ cases.push_back(std::bitset<63>("111111111111111111111111111111110000000000000000000000000000001"));
+ cases.push_back(std::bitset<63>("101010101010101010101010101010101010101010101010101010101010101"));
+ cases.push_back(std::bitset<63>("010101010101010101010101010101010101010101010101010101010101010"));
+ cases.push_back(std::bitset<63>("111111111111111111111111111111111111111111111111111111111111111"));
+ return cases;
}
template <>
TEST_CONSTEXPR_CXX23 inline std::vector<std::bitset<64> > get_test_cases<64>() {
- std::vector<std::bitset<64> > cases;
- cases.push_back(std::bitset<64>("0000000000000000000000000000000000000000000000000000000000000000"));
- cases.push_back(std::bitset<64>("0000000000000000000000000000000000000000000000000000000000000001"));
- cases.push_back(std::bitset<64>("1000000000000000000000000000000000000000000000000000000000000000"));
- cases.push_back(std::bitset<64>("1000000000000000000000000000000000000000000000000000000000000001"));
- cases.push_back(std::bitset<64>("1000000000000000000000000011111000000000000000000000000000000001"));
- cases.push_back(std::bitset<64>("0000000000000000000000000000000011111111111111111111111111111111"));
- cases.push_back(std::bitset<64>("1000000000000000000000000000000011111111111111111111111111111111"));
- cases.push_back(std::bitset<64>("1111111111111111111111111111111100000000000000000000000000000000"));
- cases.push_back(std::bitset<64>("1111111111111111111111111111111100000000000000000000000000000001"));
- cases.push_back(std::bitset<64>("1010101010101010101010101010101010101010101010101010101010101010"));
- cases.push_back(std::bitset<64>("0101010101010101010101010101010101010101010101010101010101010101"));
- cases.push_back(std::bitset<64>("1111111111111111111111111111111111111111111111111111111111111111"));
- return cases;
+ std::vector<std::bitset<64> > cases;
+ cases.push_back(std::bitset<64>("0000000000000000000000000000000000000000000000000000000000000000"));
+ cases.push_back(std::bitset<64>("0000000000000000000000000000000000000000000000000000000000000001"));
+ cases.push_back(std::bitset<64>("1000000000000000000000000000000000000000000000000000000000000000"));
+ cases.push_back(std::bitset<64>("1000000000000000000000000000000000000000000000000000000000000001"));
+ cases.push_back(std::bitset<64>("1000000000000000000000000011111000000000000000000000000000000001"));
+ cases.push_back(std::bitset<64>("0000000000000000000000000000000011111111111111111111111111111111"));
+ cases.push_back(std::bitset<64>("1000000000000000000000000000000011111111111111111111111111111111"));
+ cases.push_back(std::bitset<64>("1111111111111111111111111111111100000000000000000000000000000000"));
+ cases.push_back(std::bitset<64>("1111111111111111111111111111111100000000000000000000000000000001"));
+ cases.push_back(std::bitset<64>("1010101010101010101010101010101010101010101010101010101010101010"));
+ cases.push_back(std::bitset<64>("0101010101010101010101010101010101010101010101010101010101010101"));
+ cases.push_back(std::bitset<64>("1111111111111111111111111111111111111111111111111111111111111111"));
+ return cases;
}
template <>
TEST_CONSTEXPR_CXX23 inline std::vector<std::bitset<65> > get_test_cases<65>() {
- std::vector<std::bitset<65> > cases;
- cases.push_back(std::bitset<65>("00000000000000000000000000000000000000000000000000000000000000000"));
- cases.push_back(std::bitset<65>("00000000000000000000000000000000000000000000000000000000000000001"));
- cases.push_back(std::bitset<65>("10000000000000000000000000000000000000000000000000000000000000000"));
- cases.push_back(std::bitset<65>("10000000000000000000000000000000000000000000000000000000000000001"));
- cases.push_back(std::bitset<65>("10000000000000000000000000011111000000000000000000000000000000001"));
- cases.push_back(std::bitset<65>("00000000000000000000000000000000011111111111111111111111111111111"));
- cases.push_back(std::bitset<65>("10000000000000000000000000000000011111111111111111111111111111111"));
- cases.push_back(std::bitset<65>("11111111111111111111111111111111000000000000000000000000000000000"));
- cases.push_back(std::bitset<65>("11111111111111111111111111111111000000000000000000000000000000001"));
- cases.push_back(std::bitset<65>("10101010101010101010101010101010101010101010101010101010101010101"));
- cases.push_back(std::bitset<65>("01010101010101010101010101010101010101010101010101010101010101010"));
- cases.push_back(std::bitset<65>("11111111111111111111111111111111111111111111111111111111111111111"));
- return cases;
+ std::vector<std::bitset<65> > cases;
+ cases.push_back(std::bitset<65>("00000000000000000000000000000000000000000000000000000000000000000"));
+ cases.push_back(std::bitset<65>("00000000000000000000000000000000000000000000000000000000000000001"));
+ cases.push_back(std::bitset<65>("10000000000000000000000000000000000000000000000000000000000000000"));
+ cases.push_back(std::bitset<65>("10000000000000000000000000000000000000000000000000000000000000001"));
+ cases.push_back(std::bitset<65>("10000000000000000000000000011111000000000000000000000000000000001"));
+ cases.push_back(std::bitset<65>("00000000000000000000000000000000011111111111111111111111111111111"));
+ cases.push_back(std::bitset<65>("10000000000000000000000000000000011111111111111111111111111111111"));
+ cases.push_back(std::bitset<65>("11111111111111111111111111111111000000000000000000000000000000000"));
+ cases.push_back(std::bitset<65>("11111111111111111111111111111111000000000000000000000000000000001"));
+ cases.push_back(std::bitset<65>("10101010101010101010101010101010101010101010101010101010101010101"));
+ cases.push_back(std::bitset<65>("01010101010101010101010101010101010101010101010101010101010101010"));
+ cases.push_back(std::bitset<65>("11111111111111111111111111111111111111111111111111111111111111111"));
+ return cases;
}
TEST_CONSTEXPR_CXX23 inline std::string str_repeat(std::string s, unsigned int n) {
- std::string res = s;
- for (; n != 0; --n)
- res += s;
- return res;
+ std::string res = s;
+ for (; n != 0; --n)
+ res += s;
+ return res;
}
template <>
TEST_CONSTEXPR_CXX23 inline std::vector<std::bitset<1000> > get_test_cases<1000>() {
- std::vector<std::bitset<1000> > cases;
- cases.push_back(std::bitset<1000>(std::string(1000, '0')));
- cases.push_back(std::bitset<1000>(std::string(999, '0') + std::string(1, '1')));
- cases.push_back(std::bitset<1000>(std::string(1, '1') + std::string(999, '0')));
- cases.push_back(std::bitset<1000>(std::string(1, '1') + std::string(998, '0') + std::string(1, '1')));
- cases.push_back(std::bitset<1000>(std::string(1, '1') + std::string(400, '0') + std::string(99, '1') + std::string(499, '0') + std::string(1, '1')));
- cases.push_back(std::bitset<1000>(std::string(500, '0') + std::string(500, '1')));
- cases.push_back(std::bitset<1000>(std::string(1, '1') + std::string(499, '0') + std::string(500, '1')));
- cases.push_back(std::bitset<1000>(std::string(500, '1') + std::string(500, '0')));
- cases.push_back(std::bitset<1000>(std::string(500, '1') + std::string(499, '0') + std::string(1, '1')));
- cases.push_back(std::bitset<1000>...
[truncated]
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR simplifies the internal bitwise logic of the
flip()
function forstd::bitset
.