[libcxx-commits] [libcxx] [libc++] Fix ambiguity due to non-uglified member typedefs (PR #121664)

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 9 08:28:13 PST 2025


================
@@ -75,8 +75,10 @@ template <class, class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<__bit_iterator<_Cp, _IsConst> >
 __count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) {
   if (__value)
-    return std::__count_bool<true>(__first, static_cast<typename _Cp::size_type>(__last - __first));
-  return std::__count_bool<false>(__first, static_cast<typename _Cp::size_type>(__last - __first));
+    return std::__count_bool<true>(
+        __first, static_cast<typename __size_difference_type_traits<_Cp>::size_type>(__last - __first));
+  return std::__count_bool<false>(
----------------
winner245 wrote:

I think I need to meet two goals simultaneously here. Currently, `__bit_iterator<_Cp, _IsConst>` is used as the `iterator` type for both `vector<bool>` and `std::bitset`. 
- When used with `vector<bool>::iterator`, we have `_Cp = vector<bool>` and we can only access `_Cp::{size_type, difference_type}`; 
- When used with `bitset<N>::iterator`, we have `_Cp = vector<bool>` and we can only access `_Cp::{__size_type, __difference_type}`. 

This means that always using one deterministic way would fail, and that's why I need `__size_difference_type_traits` which tells me to access the right member types depending on what `_Cp` is.  

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


More information about the libcxx-commits mailing list