[libcxx-commits] [libcxx] [libc++] Refactor bitset::{any, all} (PR #128445)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 21 09:33:20 PDT 2025


================
@@ -224,11 +225,21 @@ protected:
     return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>());
   }
 
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT {
+    return __scan_bits<false>(__bit_not());
+  }
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT {
+    return __scan_bits<true>(std::__identity());
+  }
   _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
 
 private:
+  struct __bit_not {
----------------
ldionne wrote:

I wouldn't block this patch on it, however it might be nice to consider a follow-up refactoring.

We have a `__bit_not` in `valarray` here: https://github.com/llvm/llvm-project/blob/main/libcxx/include/valarray#L491

We could provide a single `__bit_not` in https://github.com/llvm/llvm-project/blob/main/libcxx/include/__functional/operations.h#L220 and use it from both `valarray` and `bitset`.

https://github.com/llvm/llvm-project/pull/128445


More information about the libcxx-commits mailing list