Skip to content

Commit 714a015

Browse files
committed
[libc++] Simplify the implementation of the pointer aliases in allocator_traits
1 parent 59cbe2f commit 714a015

File tree

1 file changed

+23
-35
lines changed

1 file changed

+23
-35
lines changed

libcxx/include/__memory/allocator_traits.h

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,50 +49,38 @@ using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer;
4949
template <class _Tp, class _Alloc>
5050
using __pointer _LIBCPP_NODEBUG = __detected_or_t<_Tp*, __pointer_member, __libcpp_remove_reference_t<_Alloc> >;
5151

52-
// __const_pointer
53-
_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_pointer, const_pointer);
54-
template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
55-
struct __const_pointer {
56-
using type _LIBCPP_NODEBUG = typename _Alloc::const_pointer;
57-
};
58-
template <class _Tp, class _Ptr, class _Alloc>
59-
struct __const_pointer<_Tp, _Ptr, _Alloc, false> {
52+
template <class _Ptr, class _Alloc, class _Tp, template <class> class _Alias, class = void>
53+
struct __rebind_or_alias_pointer {
6054
#ifdef _LIBCPP_CXX03_LANG
61-
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>::other;
55+
using type = typename pointer_traits<_Ptr>::template rebind<_Tp>::other;
6256
#else
63-
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>;
57+
using type = typename pointer_traits<_Ptr>::template rebind<_Tp>;
6458
#endif
6559
};
6660

67-
// __void_pointer
68-
_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_void_pointer, void_pointer);
69-
template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
70-
struct __void_pointer {
71-
using type _LIBCPP_NODEBUG = typename _Alloc::void_pointer;
61+
template <class _Ptr, class _Alloc, class _Tp, template <class> class _Alias>
62+
struct __rebind_or_alias_pointer<_Ptr, _Alloc, _Tp, _Alias, __void_t<_Alias<_Alloc> > > {
63+
using type = _Alias<_Alloc>;
7264
};
65+
66+
template <class _Alloc>
67+
using __const_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_pointer;
68+
69+
template <class _Tp, class _Ptr, class _Alloc>
70+
using __const_pointer _LIBCPP_NODEBUG = __rebind_or_alias_pointer<_Ptr, _Alloc, const _Tp, __const_pointer_member>;
71+
72+
template <class _Alloc>
73+
using __void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::void_pointer;
74+
7375
template <class _Ptr, class _Alloc>
74-
struct __void_pointer<_Ptr, _Alloc, false> {
75-
#ifdef _LIBCPP_CXX03_LANG
76-
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>::other;
77-
#else
78-
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>;
79-
#endif
80-
};
76+
using __void_pointer _LIBCPP_NODEBUG = __rebind_or_alias_pointer<_Ptr, _Alloc, void, __void_pointer_member>;
77+
78+
template <class _Alloc>
79+
using __const_void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer;
8180

82-
// __const_void_pointer
83-
_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_void_pointer, const_void_pointer);
84-
template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
85-
struct __const_void_pointer {
86-
using type _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer;
87-
};
8881
template <class _Ptr, class _Alloc>
89-
struct __const_void_pointer<_Ptr, _Alloc, false> {
90-
#ifdef _LIBCPP_CXX03_LANG
91-
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>::other;
92-
#else
93-
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>;
94-
#endif
95-
};
82+
using __const_void_pointer _LIBCPP_NODEBUG =
83+
__rebind_or_alias_pointer<_Ptr, _Alloc, const void, __const_void_pointer_member>;
9684

9785
// __size_type
9886
template <class _Tp>

0 commit comments

Comments
 (0)