[libcxx-commits] [libcxx] [libc++] Merge the private iterator_traits aliases with their ranges versions (PR #162661)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 16 01:50:25 PDT 2025


================
@@ -419,31 +422,60 @@ using __has_exactly_bidirectional_iterator_category _LIBCPP_NODEBUG =
                       __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>::value &&
                           !__has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>::value>;
 
-template <class _InputIterator>
-using __iterator_value_type _LIBCPP_NODEBUG = typename iterator_traits<_InputIterator>::value_type;
+#if _LIBCPP_STD_VER >= 20
+
+// [readable.traits]
+
+// Let `RI` be `remove_cvref_t<I>`. The type `iter_value_t<I>` denotes
+// `indirectly_readable_traits<RI>::value_type` if `iterator_traits<RI>` names a specialization
+// generated from the primary template, and `iterator_traits<RI>::value_type` otherwise.
+// This has to be in this file and not readable_traits.h to break the include cycle between the two.
+template <class _Ip>
+using iter_value_t =
+    typename conditional_t<__is_primary_template<iterator_traits<remove_cvref_t<_Ip> > >::value,
+                           indirectly_readable_traits<remove_cvref_t<_Ip> >,
+                           iterator_traits<remove_cvref_t<_Ip> > >::value_type;
+
+template <class _Iter>
+using __iter_value_t _LIBCPP_NODEBUG = iter_value_t<_Iter>;
+
+template <class _Iter>
+using __iter_difference_t _LIBCPP_NODEBUG = iter_difference_t<_Iter>;
+
+template <class _Iter>
+using __iter_reference_t _LIBCPP_NODEBUG = iter_reference_t<_Iter>;
+
+#else
+
+template <class _Iter>
+using __iter_value_t _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::value_type;
+
+template <class _Iter>
+using __iter_difference_t _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::difference_type;
+
+#endif // _LIBCPP_STD_VER >= 20
 
 #if _LIBCPP_STD_VER >= 23
 template <class _InputIterator>
-using __iter_key_type _LIBCPP_NODEBUG = remove_const_t<tuple_element_t<0, __iterator_value_type<_InputIterator>>>;
+using __iter_key_type _LIBCPP_NODEBUG = remove_const_t<tuple_element_t<0, __iter_value_t<_InputIterator>>>;
----------------
philnik777 wrote:

We were conforming. The constraints are introduced by the exact same wording across the map types AFAICT. It also seems intentional to me, since the rest of the wording is rather close to the legacy containers.

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


More information about the libcxx-commits mailing list