[libcxx-commits] [libcxx] [libc++] Simplify the implementation of pointer_traits a bit (PR #142260)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jun 12 08:48:55 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>)
----------------
ldionne wrote:
I find the previous code more readable sinceĀ it lists the requirements in a consistent way. Right now I have to jump between the various ways to apply constraints on a template. I'd go back to using simple `requires` everywhere.
Also this seems to have removed the requirement `__has_element_type<pointer_traits<_Tp>>::value` -- is that intended?
https://github.com/llvm/llvm-project/pull/142260
More information about the libcxx-commits
mailing list