@@ -36,63 +36,51 @@ _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
// __pointer
46
40
template <class _Tp >
47
41
using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer;
48
42
49
43
template <class _Tp , class _Alloc >
50
44
using __pointer _LIBCPP_NODEBUG = __detected_or_t <_Tp*, __pointer_member, __libcpp_remove_reference_t <_Alloc> >;
51
45
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 > {
46
+ // This trait returns _Alias<_Alloc> if that's well-formed, and _Ptr rebound to _Tp otherwise
47
+ template <class _Alloc , template <class > class _Alias , class _Ptr , class _Tp , class = void >
48
+ struct __rebind_or_alias_pointer {
60
49
#ifdef _LIBCPP_CXX03_LANG
61
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>::other;
50
+ using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<_Tp>::other;
62
51
#else
63
- using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>;
52
+ using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<_Tp>;
64
53
#endif
65
54
};
66
55
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;
56
+ template <class _Ptr , class _Alloc , class _Tp , template <class > class _Alias >
57
+ struct __rebind_or_alias_pointer <_Alloc, _Alias, _Ptr, _Tp, __void_t <_Alias<_Alloc> > > {
58
+ using type _LIBCPP_NODEBUG = _Alias<_Alloc>;
72
59
};
60
+
61
+ // __const_pointer
62
+ template <class _Alloc >
63
+ using __const_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_pointer;
64
+
65
+ template <class _Tp , class _Ptr , class _Alloc >
66
+ using __const_pointer_t _LIBCPP_NODEBUG =
67
+ typename __rebind_or_alias_pointer<_Alloc, __const_pointer_member, _Ptr, const _Tp>::type;
68
+
69
+ // __void_pointer
70
+ template <class _Alloc >
71
+ using __void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::void_pointer;
72
+
73
73
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
- };
74
+ using __void_pointer_t _LIBCPP_NODEBUG =
75
+ typename __rebind_or_alias_pointer<_Alloc, __void_pointer_member, _Ptr, void >::type;
81
76
82
77
// __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
- };
78
+ template <class _Alloc >
79
+ using __const_void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer;
80
+
88
81
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_t _LIBCPP_NODEBUG =
83
+ typename __rebind_or_alias_pointer<_Alloc, __const_void_pointer_member, _Ptr, const void >::type;
96
84
97
85
// __size_type
98
86
template <class _Tp >
@@ -102,13 +90,13 @@ template <class _Alloc, class _DiffType>
102
90
using __size_type _LIBCPP_NODEBUG = __detected_or_t <__make_unsigned_t <_DiffType>, __size_type_member, _Alloc>;
103
91
104
92
// __alloc_traits_difference_type
105
- _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX (__has_alloc_traits_difference_type, difference_type);
106
- template <class _Alloc , class _Ptr , bool = __has_alloc_traits_difference_type<_Alloc>::value>
93
+ template <class _Alloc , class _Ptr , class = void >
107
94
struct __alloc_traits_difference_type {
108
95
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::difference_type;
109
96
};
97
+
110
98
template <class _Alloc , class _Ptr >
111
- struct __alloc_traits_difference_type <_Alloc, _Ptr, true > {
99
+ struct __alloc_traits_difference_type <_Alloc, _Ptr, __void_t < typename _Alloc::difference_type> > {
112
100
using type _LIBCPP_NODEBUG = typename _Alloc::difference_type;
113
101
};
114
102
@@ -239,9 +227,9 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits {
239
227
using allocator_type = _Alloc;
240
228
using value_type = typename allocator_type::value_type;
241
229
using pointer = __pointer<value_type, allocator_type>;
242
- using const_pointer = typename __const_pointer <value_type, pointer, allocator_type>::type ;
243
- using void_pointer = typename __void_pointer <pointer, allocator_type>::type ;
244
- using const_void_pointer = typename __const_void_pointer <pointer, allocator_type>::type ;
230
+ using const_pointer = __const_pointer_t <value_type, pointer, allocator_type>;
231
+ using void_pointer = __void_pointer_t <pointer, allocator_type>;
232
+ using const_void_pointer = __const_void_pointer_t <pointer, allocator_type>;
245
233
using difference_type = typename __alloc_traits_difference_type<allocator_type, pointer>::type;
246
234
using size_type = __size_type<allocator_type, difference_type>;
247
235
using propagate_on_container_copy_assignment = __propagate_on_container_copy_assignment<allocator_type>;
@@ -405,8 +393,6 @@ struct __is_cpp17_copy_insertable<
405
393
__has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value > >
406
394
: __is_cpp17_move_insertable<_Alloc> {};
407
395
408
- #undef _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX
409
-
410
396
_LIBCPP_END_NAMESPACE_STD
411
397
412
398
_LIBCPP_POP_MACROS
0 commit comments