[libcxx-commits] [libcxx] [libc++] Simplify the implementation of pointer_traits a bit (PR #142260)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jun 15 08:08:22 PDT 2025


================
@@ -257,20 +212,24 @@ template <class _Tp>
 struct __pointer_of {};
 
 template <class _Tp>
-  requires(__has_pointer<_Tp>::value)
+concept __has_pointer_member = requires { typename _Tp::pointer; };
+
+template <class _Tp>
+concept __has_element_type_member = requires { typename _Tp::element_type; };
+
+template <__has_pointer_member _Tp>
 struct __pointer_of<_Tp> {
   using type _LIBCPP_NODEBUG = typename _Tp::pointer;
 };
 
-template <class _Tp>
-  requires(!__has_pointer<_Tp>::value && __has_element_type<_Tp>::value)
+template <__has_element_type_member _Tp>
+  requires(!__has_pointer_member<_Tp>)
 struct __pointer_of<_Tp> {
   using type _LIBCPP_NODEBUG = typename _Tp::element_type*;
 };
 
 template <class _Tp>
-  requires(!__has_pointer<_Tp>::value && !__has_element_type<_Tp>::value &&
-           __has_element_type<pointer_traits<_Tp>>::value)
+  requires(!__has_pointer_member<_Tp> && !__has_element_type_member<_Tp>)
----------------
philnik777 wrote:

That wasn't intended. Curiously the entire CI is happy, so we're either missing coverage or this constraint is unnecessary. I've added it back for now, but we should look into it. CC @Zingam 

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


More information about the libcxx-commits mailing list