[libcxx-commits] [libcxx] [libc++] Simplify the implementation of the pointer aliases in allocator_traits (PR #127079)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 26 08:19:07 PST 2025
================
@@ -49,50 +49,38 @@ using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer;
template <class _Tp, class _Alloc>
using __pointer _LIBCPP_NODEBUG = __detected_or_t<_Tp*, __pointer_member, __libcpp_remove_reference_t<_Alloc> >;
-// __const_pointer
-_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_pointer, const_pointer);
-template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
-struct __const_pointer {
- using type _LIBCPP_NODEBUG = typename _Alloc::const_pointer;
-};
-template <class _Tp, class _Ptr, class _Alloc>
-struct __const_pointer<_Tp, _Ptr, _Alloc, false> {
+template <class _Ptr, class _Alloc, class _Tp, template <class> class _Alias, class = void>
+struct __rebind_or_alias_pointer {
#ifdef _LIBCPP_CXX03_LANG
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>::other;
+ using type = typename pointer_traits<_Ptr>::template rebind<_Tp>::other;
#else
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>;
+ using type = typename pointer_traits<_Ptr>::template rebind<_Tp>;
#endif
};
-// __void_pointer
-_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_void_pointer, void_pointer);
-template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
-struct __void_pointer {
- using type _LIBCPP_NODEBUG = typename _Alloc::void_pointer;
+template <class _Ptr, class _Alloc, class _Tp, template <class> class _Alias>
+struct __rebind_or_alias_pointer<_Ptr, _Alloc, _Tp, _Alias, __void_t<_Alias<_Alloc> > > {
+ using type = _Alias<_Alloc>;
};
+
+template <class _Alloc>
+using __const_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_pointer;
+
+template <class _Tp, class _Ptr, class _Alloc>
+using __const_pointer _LIBCPP_NODEBUG = __rebind_or_alias_pointer<_Ptr, _Alloc, const _Tp, __const_pointer_member>;
+
+template <class _Alloc>
+using __void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::void_pointer;
+
template <class _Ptr, class _Alloc>
-struct __void_pointer<_Ptr, _Alloc, false> {
-#ifdef _LIBCPP_CXX03_LANG
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>::other;
-#else
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>;
-#endif
-};
+using __void_pointer _LIBCPP_NODEBUG = __rebind_or_alias_pointer<_Ptr, _Alloc, void, __void_pointer_member>;
+
+template <class _Alloc>
+using __const_void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer;
-// __const_void_pointer
-_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_void_pointer, const_void_pointer);
----------------
ldionne wrote:
I think there's only one usage of `_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX` left after this patch. You could probably remove the macro and inline that usage instead (below).
https://github.com/llvm/llvm-project/pull/127079
More information about the libcxx-commits
mailing list