[libcxx-commits] [libcxx] [libc++] Fix bitset conversion functions and refactor constructor (PR #121348)

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jun 13 08:52:47 PDT 2025


================
@@ -220,11 +225,63 @@ protected:
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
+
+  // unsigned long spans only one word
+  template <typename _StorageType                                             = __storage_type,
+            __enable_if_t<sizeof(_StorageType) >= sizeof(unsigned long), int> = 0>
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long __to_ulong() const {
+    return static_cast<unsigned long>(__first_[0]);
+  }
+
+  // unsigned long may span multiple words which are concatenated to form the result
+  template <typename _StorageType                                            = __storage_type,
+            __enable_if_t<sizeof(_StorageType) < sizeof(unsigned long), int> = 0>
----------------
winner245 wrote:

As suggested, I've removed this code branch, and I am now focusing only on the case where `sizeof(size_t) >= sizeof(unsigned long)`. 

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


More information about the libcxx-commits mailing list