Skip to content

Commit 8226e1b

Browse files
committed
[libc++] Move _ITER_TRAITS and _ITER_CONCEPT into <__iterator/concepts.h>
1 parent b060022 commit 8226e1b

File tree

2 files changed

+40
-49
lines changed

2 files changed

+40
-49
lines changed

libcxx/include/__iterator/concepts.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,42 @@ concept sized_sentinel_for =
151151
{ __i - __s } -> same_as<iter_difference_t<_Ip>>;
152152
};
153153

154+
template <class _Iter>
155+
struct __iter_traits_cache {
156+
using type _LIBCPP_NODEBUG =
157+
_If<__is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
158+
};
159+
template <class _Iter>
160+
using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type;
161+
162+
struct __iter_concept_concept_test {
163+
template <class _Iter>
164+
using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_concept;
165+
};
166+
struct __iter_concept_category_test {
167+
template <class _Iter>
168+
using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_category;
169+
};
170+
struct __iter_concept_random_fallback {
171+
template <class _Iter>
172+
using _Apply _LIBCPP_NODEBUG =
173+
__enable_if_t<__is_primary_template<iterator_traits<_Iter> >::value, random_access_iterator_tag>;
174+
};
175+
176+
template <class _Iter, class _Tester>
177+
struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, _Iter>, _Tester {};
178+
179+
template <class _Iter>
180+
struct __iter_concept_cache {
181+
using type _LIBCPP_NODEBUG =
182+
_Or<__test_iter_concept<_Iter, __iter_concept_concept_test>,
183+
__test_iter_concept<_Iter, __iter_concept_category_test>,
184+
__test_iter_concept<_Iter, __iter_concept_random_fallback> >;
185+
};
186+
187+
template <class _Iter>
188+
using _ITER_CONCEPT _LIBCPP_NODEBUG = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
189+
154190
// [iterator.concept.input]
155191
template <class _Ip>
156192
concept input_iterator = input_or_output_iterator<_Ip> && indirectly_readable<_Ip> && requires {

libcxx/include/__iterator/iterator_traits.h

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626
#include <__type_traits/conditional.h>
2727
#include <__type_traits/detected_or.h>
2828
#include <__type_traits/disjunction.h>
29-
#include <__type_traits/enable_if.h>
3029
#include <__type_traits/integral_constant.h>
3130
#include <__type_traits/is_convertible.h>
3231
#include <__type_traits/is_object.h>
3332
#include <__type_traits/is_primary_template.h>
3433
#include <__type_traits/is_reference.h>
3534
#include <__type_traits/is_referenceable.h>
36-
#include <__type_traits/is_valid_expansion.h>
3735
#include <__type_traits/nat.h>
3836
#include <__type_traits/remove_const.h>
3937
#include <__type_traits/remove_cv.h>
@@ -72,42 +70,6 @@ struct random_access_iterator_tag : public bidirectional_iterator_tag {};
7270
struct contiguous_iterator_tag : public random_access_iterator_tag {};
7371
#endif
7472

75-
template <class _Iter>
76-
struct __iter_traits_cache {
77-
using type _LIBCPP_NODEBUG =
78-
_If<__is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
79-
};
80-
template <class _Iter>
81-
using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type;
82-
83-
struct __iter_concept_concept_test {
84-
template <class _Iter>
85-
using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_concept;
86-
};
87-
struct __iter_concept_category_test {
88-
template <class _Iter>
89-
using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_category;
90-
};
91-
struct __iter_concept_random_fallback {
92-
template <class _Iter>
93-
using _Apply _LIBCPP_NODEBUG =
94-
__enable_if_t<__is_primary_template<iterator_traits<_Iter> >::value, random_access_iterator_tag>;
95-
};
96-
97-
template <class _Iter, class _Tester>
98-
struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, _Iter>, _Tester {};
99-
100-
template <class _Iter>
101-
struct __iter_concept_cache {
102-
using type _LIBCPP_NODEBUG =
103-
_Or<__test_iter_concept<_Iter, __iter_concept_concept_test>,
104-
__test_iter_concept<_Iter, __iter_concept_category_test>,
105-
__test_iter_concept<_Iter, __iter_concept_random_fallback> >;
106-
};
107-
108-
template <class _Iter>
109-
using _ITER_CONCEPT _LIBCPP_NODEBUG = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
110-
11173
template <class _Tp>
11274
struct __has_iterator_typedefs {
11375
private:
@@ -194,16 +156,6 @@ concept __specifies_members = requires {
194156
requires __has_member_iterator_category<_Ip>;
195157
};
196158

197-
template <class>
198-
struct __iterator_traits_member_pointer_or_void {
199-
using type _LIBCPP_NODEBUG = void;
200-
};
201-
202-
template <__has_member_pointer _Tp>
203-
struct __iterator_traits_member_pointer_or_void<_Tp> {
204-
using type _LIBCPP_NODEBUG = typename _Tp::pointer;
205-
};
206-
207159
template <class _Tp>
208160
concept __cpp17_iterator_missing_members = !__specifies_members<_Tp> && __iterator_traits_detail::__cpp17_iterator<_Tp>;
209161

@@ -303,6 +255,9 @@ struct __iterator_traits_difference_type<_Ip> {
303255
template <class>
304256
struct __iterator_traits {};
305257

258+
template <class _Tp>
259+
using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer;
260+
306261
// [iterator.traits]/3.1
307262
// If `I` has valid ([temp.deduct]) member types `difference-type`, `value-type`, `reference`, and
308263
// `iterator-category`, then `iterator-traits<I>` has the following publicly accessible members:
@@ -311,7 +266,7 @@ struct __iterator_traits<_Ip> {
311266
using iterator_category = typename _Ip::iterator_category;
312267
using value_type = typename _Ip::value_type;
313268
using difference_type = typename _Ip::difference_type;
314-
using pointer = typename __iterator_traits_member_pointer_or_void<_Ip>::type;
269+
using pointer = __detected_or_t<void, __pointer_member, _Ip>;
315270
using reference = typename _Ip::reference;
316271
};
317272

0 commit comments

Comments
 (0)