@@ -36,12 +36,6 @@ _LIBCPP_PUSH_MACROS
36
36
37
37
_LIBCPP_BEGIN_NAMESPACE_STD
38
38
39
- #define _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX (NAME, PROPERTY ) \
40
- template <class _Tp , class = void > \
41
- struct NAME : false_type {}; \
42
- template <class _Tp > \
43
- struct NAME <_Tp, __void_t <typename _Tp::PROPERTY > > : true_type {}
44
-
45
39
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
46
40
// __pointer
47
41
template <class _Tp >
@@ -50,51 +44,45 @@ using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer;
50
44
template <class _Tp , class _Alloc >
51
45
using __pointer _LIBCPP_NODEBUG = __detected_or_t <_Tp*, __pointer_member, __libcpp_remove_reference_t <_Alloc> >;
52
46
53
- // __const_pointer
54
- _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX (__has_const_pointer, const_pointer);
55
- template <class _Tp , class _Ptr , class _Alloc , bool = __has_const_pointer<_Alloc>::value>
56
- struct __const_pointer {
57
- using type _LIBCPP_NODEBUG = typename _Alloc::const_pointer;
58
- };
59
- template <class _Tp , class _Ptr , class _Alloc >
60
- struct __const_pointer <_Tp, _Ptr, _Alloc, false > {
47
+ // This trait returns _Alias<_Alloc> if that's well-formed, and _Ptr rebound to _Tp otherwise
48
+ template <class _Alloc , template <class > class _Alias , class _Ptr , class _Tp , class = void >
49
+ struct __rebind_or_alias_pointer {
61
50
#ifdef _LIBCPP_CXX03_LANG
62
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>::other;
51
+ using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<_Tp>::other;
63
52
#else
64
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>;
53
+ using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<_Tp>;
65
54
#endif
66
55
};
56
+
57
+ template <class _Ptr , class _Alloc , class _Tp , template <class > class _Alias >
58
+ struct __rebind_or_alias_pointer <_Alloc, _Alias, _Ptr, _Tp, __void_t <_Alias<_Alloc> > > {
59
+ using type _LIBCPP_NODEBUG = _Alias<_Alloc>;
60
+ };
61
+
62
+ // __const_pointer
63
+ template <class _Alloc >
64
+ using __const_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_pointer;
65
+
66
+ template <class _Tp , class _Ptr , class _Alloc >
67
+ using __const_pointer_t _LIBCPP_NODEBUG =
68
+ typename __rebind_or_alias_pointer<_Alloc, __const_pointer_member, _Ptr, const _Tp>::type;
67
69
_LIBCPP_SUPPRESS_DEPRECATED_POP
68
70
69
71
// __void_pointer
70
- _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX (__has_void_pointer, void_pointer);
71
- template <class _Ptr , class _Alloc , bool = __has_void_pointer<_Alloc>::value>
72
- struct __void_pointer {
73
- using type _LIBCPP_NODEBUG = typename _Alloc::void_pointer;
74
- };
72
+ template <class _Alloc >
73
+ using __void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::void_pointer;
74
+
75
75
template <class _Ptr , class _Alloc >
76
- struct __void_pointer <_Ptr, _Alloc, false > {
77
- #ifdef _LIBCPP_CXX03_LANG
78
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void >::other;
79
- #else
80
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void >;
81
- #endif
82
- };
76
+ using __void_pointer_t _LIBCPP_NODEBUG =
77
+ typename __rebind_or_alias_pointer<_Alloc, __void_pointer_member, _Ptr, void >::type;
83
78
84
79
// __const_void_pointer
85
- _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX (__has_const_void_pointer, const_void_pointer);
86
- template <class _Ptr , class _Alloc , bool = __has_const_void_pointer<_Alloc>::value>
87
- struct __const_void_pointer {
88
- using type _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer;
89
- };
80
+ template <class _Alloc >
81
+ using __const_void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer;
82
+
90
83
template <class _Ptr , class _Alloc >
91
- struct __const_void_pointer <_Ptr, _Alloc, false > {
92
- #ifdef _LIBCPP_CXX03_LANG
93
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void >::other;
94
- #else
95
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void >;
96
- #endif
97
- };
84
+ using __const_void_pointer_t _LIBCPP_NODEBUG =
85
+ typename __rebind_or_alias_pointer<_Alloc, __const_void_pointer_member, _Ptr, const void >::type;
98
86
99
87
// __size_type
100
88
template <class _Tp >
@@ -104,13 +92,13 @@ template <class _Alloc, class _DiffType>
104
92
using __size_type _LIBCPP_NODEBUG = __detected_or_t <__make_unsigned_t <_DiffType>, __size_type_member, _Alloc>;
105
93
106
94
// __alloc_traits_difference_type
107
- _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX (__has_alloc_traits_difference_type, difference_type);
108
- template <class _Alloc , class _Ptr , bool = __has_alloc_traits_difference_type<_Alloc>::value>
95
+ template <class _Alloc , class _Ptr , class = void >
109
96
struct __alloc_traits_difference_type {
110
97
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::difference_type;
111
98
};
99
+
112
100
template <class _Alloc , class _Ptr >
113
- struct __alloc_traits_difference_type <_Alloc, _Ptr, true > {
101
+ struct __alloc_traits_difference_type <_Alloc, _Ptr, __void_t < typename _Alloc::difference_type> > {
114
102
using type _LIBCPP_NODEBUG = typename _Alloc::difference_type;
115
103
};
116
104
@@ -240,9 +228,9 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits {
240
228
using allocator_type = _Alloc;
241
229
using value_type = typename allocator_type::value_type;
242
230
using pointer = __pointer<value_type, allocator_type>;
243
- using const_pointer = typename __const_pointer <value_type, pointer, allocator_type>::type ;
244
- using void_pointer = typename __void_pointer <pointer, allocator_type>::type ;
245
- using const_void_pointer = typename __const_void_pointer <pointer, allocator_type>::type ;
231
+ using const_pointer = __const_pointer_t <value_type, pointer, allocator_type>;
232
+ using void_pointer = __void_pointer_t <pointer, allocator_type>;
233
+ using const_void_pointer = __const_void_pointer_t <pointer, allocator_type>;
246
234
using difference_type = typename __alloc_traits_difference_type<allocator_type, pointer>::type;
247
235
using size_type = __size_type<allocator_type, difference_type>;
248
236
using propagate_on_container_copy_assignment = __propagate_on_container_copy_assignment<allocator_type>;
@@ -386,8 +374,6 @@ inline const bool __is_cpp17_copy_insertable_v =
386
374
(!__is_std_allocator_v<_Alloc> &&
387
375
__has_construct_v<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>));
388
376
389
- #undef _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX
390
-
391
377
_LIBCPP_END_NAMESPACE_STD
392
378
393
379
_LIBCPP_POP_MACROS
0 commit comments