Skip to content

Commit 435b204

Browse files
committed
[libc++] Merge the private iterator_traits aliases with their ranges versions
1 parent 3141bde commit 435b204

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+231
-250
lines changed

libcxx/include/__algorithm/copy.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ struct __copy_impl {
197197
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
198198
operator()(_InIter __first, _InIter __last, _OutIter __result) const {
199199
using _Traits = __segmented_iterator_traits<_OutIter>;
200-
using _DiffT =
201-
typename common_type<__iterator_difference_type<_InIter>, __iterator_difference_type<_OutIter> >::type;
200+
using _DiffT = typename common_type<__iter_difference_t<_InIter>, __iter_difference_t<_OutIter> >::type;
202201

203202
if (__first == __last)
204203
return std::make_pair(std::move(__first), std::move(__result));

libcxx/include/__algorithm/copy_backward.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ struct __copy_backward_impl {
214214

215215
auto __local_last = _Traits::__local(__result);
216216
while (true) {
217-
using _DiffT =
218-
typename common_type<__iterator_difference_type<_InIter>, __iterator_difference_type<_OutIter> >::type;
217+
using _DiffT = typename common_type<__iter_difference_t<_InIter>, __iter_difference_t<_OutIter> >::type;
219218

220219
auto __local_first = _Traits::__begin(__segment_iterator);
221220
auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first);

libcxx/include/__algorithm/count.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#ifndef _LIBCPP___ALGORITHM_COUNT_H
1111
#define _LIBCPP___ALGORITHM_COUNT_H
1212

13-
#include <__algorithm/iterator_operations.h>
1413
#include <__algorithm/min.h>
1514
#include <__bit/invert_if.h>
1615
#include <__bit/popcount.h>
@@ -31,10 +30,10 @@ _LIBCPP_PUSH_MACROS
3130
_LIBCPP_BEGIN_NAMESPACE_STD
3231

3332
// generic implementation
34-
template <class _AlgPolicy, class _Iter, class _Sent, class _Tp, class _Proj>
35-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename _IterOps<_AlgPolicy>::template __difference_type<_Iter>
33+
template <class _Iter, class _Sent, class _Tp, class _Proj>
34+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_difference_t<_Iter>
3635
__count(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
37-
typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> __r(0);
36+
__iter_difference_t<_Iter> __r(0);
3837
for (; __first != __last; ++__first)
3938
if (std::__invoke(__proj, *__first) == __value)
4039
++__r;
@@ -71,8 +70,8 @@ __count_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_t
7170
return __r;
7271
}
7372

74-
template <class, class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t<__is_identity<_Proj>::value, int> = 0>
75-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iterator_difference_type<__bit_iterator<_Cp, _IsConst> >
73+
template <class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t<__is_identity<_Proj>::value, int> = 0>
74+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_difference_t<__bit_iterator<_Cp, _IsConst> >
7675
__count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) {
7776
if (__value)
7877
return std::__count_bool<true>(
@@ -82,10 +81,10 @@ __count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __l
8281
}
8382

8483
template <class _InputIterator, class _Tp>
85-
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iterator_difference_type<_InputIterator>
84+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_difference_t<_InputIterator>
8685
count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
8786
__identity __proj;
88-
return std::__count<_ClassicAlgPolicy>(__first, __last, __value, __proj);
87+
return std::__count(__first, __last, __value, __proj);
8988
}
9089

9190
_LIBCPP_END_NAMESPACE_STD

libcxx/include/__algorithm/count_if.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#ifndef _LIBCPP___ALGORITHM_COUNT_IF_H
1111
#define _LIBCPP___ALGORITHM_COUNT_IF_H
1212

13-
#include <__algorithm/iterator_operations.h>
1413
#include <__config>
1514
#include <__functional/identity.h>
1615
#include <__iterator/iterator_traits.h>
@@ -22,10 +21,10 @@
2221

2322
_LIBCPP_BEGIN_NAMESPACE_STD
2423

25-
template <class _AlgPolicy, class _Iter, class _Sent, class _Proj, class _Pred>
26-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __policy_iter_diff_t<_AlgPolicy, _Iter>
24+
template <class _Iter, class _Sent, class _Proj, class _Pred>
25+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __iter_difference_t<_Iter>
2726
__count_if(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
28-
__policy_iter_diff_t<_AlgPolicy, _Iter> __counter(0);
27+
__iter_difference_t<_Iter> __counter(0);
2928
for (; __first != __last; ++__first) {
3029
if (std::__invoke(__pred, std::__invoke(__proj, *__first)))
3130
++__counter;
@@ -38,7 +37,7 @@ template <class _InputIterator, class _Predicate>
3837
typename iterator_traits<_InputIterator>::difference_type
3938
count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
4039
__identity __proj;
41-
return std::__count_if<_ClassicAlgPolicy>(__first, __last, __pred, __proj);
40+
return std::__count_if(__first, __last, __pred, __proj);
4241
}
4342

4443
_LIBCPP_END_NAMESPACE_STD

libcxx/include/__algorithm/is_permutation.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation_impl(
7878
_Pred&& __pred,
7979
_Proj1&& __proj1,
8080
_Proj2&& __proj2) {
81-
using _D1 = __iterator_difference_type<_Iter1>;
81+
using _D1 = __iter_difference_t<_Iter1>;
8282

8383
for (auto __i = __first1; __i != __last1; ++__i) {
8484
// Have we already counted the number of *__i in [f1, l1)?
@@ -126,7 +126,7 @@ template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _Fo
126126
return true;
127127

128128
// __first1 != __last1 && *__first1 != *__first2
129-
using _D1 = __iterator_difference_type<_ForwardIterator1>;
129+
using _D1 = __iter_difference_t<_ForwardIterator1>;
130130
_D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
131131
if (__l1 == _D1(1))
132132
return false;
@@ -173,10 +173,10 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
173173
if (__first2 == __last2) // Second range is shorter
174174
return false;
175175

176-
using _D1 = __iterator_difference_type<_Iter1>;
176+
using _D1 = __iter_difference_t<_Iter1>;
177177
_D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
178178

179-
using _D2 = __iterator_difference_type<_Iter2>;
179+
using _D2 = __iter_difference_t<_Iter2>;
180180
_D2 __l2 = _IterOps<_AlgPolicy>::distance(__first2, __last2);
181181
if (__l1 != __l2)
182182
return false;

libcxx/include/__algorithm/iterator_operations.h

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,9 @@ struct _RangeAlgPolicy {};
4747

4848
template <>
4949
struct _IterOps<_RangeAlgPolicy> {
50-
template <class _Iter>
51-
using __value_type _LIBCPP_NODEBUG = iter_value_t<_Iter>;
52-
5350
template <class _Iter>
5451
using __iterator_category _LIBCPP_NODEBUG = ranges::__iterator_concept<_Iter>;
5552

56-
template <class _Iter>
57-
using __difference_type _LIBCPP_NODEBUG = iter_difference_t<_Iter>;
58-
5953
static constexpr auto advance = ranges::advance;
6054
static constexpr auto distance = ranges::distance;
6155
static constexpr auto __iter_move = ranges::iter_move;
@@ -71,15 +65,9 @@ struct _ClassicAlgPolicy {};
7165

7266
template <>
7367
struct _IterOps<_ClassicAlgPolicy> {
74-
template <class _Iter>
75-
using __value_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::value_type;
76-
7768
template <class _Iter>
7869
using __iterator_category _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::iterator_category;
7970

80-
template <class _Iter>
81-
using __difference_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::difference_type;
82-
8371
// advance
8472
template <class _Iter, class _Distance>
8573
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void advance(_Iter& __iter, _Distance __count) {
@@ -164,30 +152,30 @@ struct _IterOps<_ClassicAlgPolicy> {
164152

165153
// advance with sentinel, a la std::ranges::advance
166154
template <class _Iter>
167-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_Iter>
168-
__advance_to(_Iter& __iter, __difference_type<_Iter> __count, const _Iter& __sentinel) {
155+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __iter_difference_t<_Iter>
156+
__advance_to(_Iter& __iter, __iter_difference_t<_Iter> __count, const _Iter& __sentinel) {
169157
return _IterOps::__advance_to(__iter, __count, __sentinel, typename iterator_traits<_Iter>::iterator_category());
170158
}
171159

172160
private:
173161
// advance with sentinel, a la std::ranges::advance -- InputIterator specialization
174162
template <class _InputIter>
175-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_InputIter> __advance_to(
176-
_InputIter& __iter, __difference_type<_InputIter> __count, const _InputIter& __sentinel, input_iterator_tag) {
177-
__difference_type<_InputIter> __dist = 0;
163+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __iter_difference_t<_InputIter> __advance_to(
164+
_InputIter& __iter, __iter_difference_t<_InputIter> __count, const _InputIter& __sentinel, input_iterator_tag) {
165+
__iter_difference_t<_InputIter> __dist = 0;
178166
for (; __dist < __count && __iter != __sentinel; ++__dist)
179167
++__iter;
180168
return __count - __dist;
181169
}
182170

183171
// advance with sentinel, a la std::ranges::advance -- BidirectionalIterator specialization
184172
template <class _BiDirIter>
185-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_BiDirIter>
173+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __iter_difference_t<_BiDirIter>
186174
__advance_to(_BiDirIter& __iter,
187-
__difference_type<_BiDirIter> __count,
175+
__iter_difference_t<_BiDirIter> __count,
188176
const _BiDirIter& __sentinel,
189177
bidirectional_iterator_tag) {
190-
__difference_type<_BiDirIter> __dist = 0;
178+
__iter_difference_t<_BiDirIter> __dist = 0;
191179
if (__count >= 0)
192180
for (; __dist < __count && __iter != __sentinel; ++__dist)
193181
++__iter;
@@ -199,9 +187,9 @@ struct _IterOps<_ClassicAlgPolicy> {
199187

200188
// advance with sentinel, a la std::ranges::advance -- RandomIterator specialization
201189
template <class _RandIter>
202-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_RandIter>
190+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __iter_difference_t<_RandIter>
203191
__advance_to(_RandIter& __iter,
204-
__difference_type<_RandIter> __count,
192+
__iter_difference_t<_RandIter> __count,
205193
const _RandIter& __sentinel,
206194
random_access_iterator_tag) {
207195
auto __dist = _IterOps::distance(__iter, __sentinel);
@@ -216,9 +204,6 @@ struct _IterOps<_ClassicAlgPolicy> {
216204
}
217205
};
218206

219-
template <class _AlgPolicy, class _Iter>
220-
using __policy_iter_diff_t _LIBCPP_NODEBUG = typename _IterOps<_AlgPolicy>::template __difference_type<_Iter>;
221-
222207
_LIBCPP_END_NAMESPACE_STD
223208

224209
_LIBCPP_POP_MACROS

libcxx/include/__algorithm/lexicographical_compare_three_way.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ template <class _InputIterator1, class _InputIterator2, class _Cmp>
3737
_LIBCPP_HIDE_FROM_ABI constexpr auto __lexicographical_compare_three_way_fast_path(
3838
_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Cmp& __comp)
3939
-> decltype(__comp(*__first1, *__first2)) {
40-
static_assert(signed_integral<__iterator_difference_type<_InputIterator1>>,
40+
static_assert(signed_integral<__iter_difference_t<_InputIterator1>>,
4141
"Using a non-integral difference_type is undefined behavior.");
42-
static_assert(signed_integral<__iterator_difference_type<_InputIterator2>>,
42+
static_assert(signed_integral<__iter_difference_t<_InputIterator2>>,
4343
"Using a non-integral difference_type is undefined behavior.");
4444

45-
using _Len1 = __iterator_difference_type<_InputIterator1>;
46-
using _Len2 = __iterator_difference_type<_InputIterator2>;
45+
using _Len1 = __iter_difference_t<_InputIterator1>;
46+
using _Len2 = __iter_difference_t<_InputIterator2>;
4747
using _Common = common_type_t<_Len1, _Len2>;
4848

4949
_Len1 __len1 = __last1 - __first1;

libcxx/include/__algorithm/make_heap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
3333
__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
3434
__comp_ref_type<_Compare> __comp_ref = __comp;
3535

36-
using __diff_t = __iterator_difference_type<_RandomAccessIterator>;
36+
using __diff_t = __iter_difference_t<_RandomAccessIterator>;
3737
const __diff_t __n = __last - __first;
3838

39-
const bool __assume_both_children = is_arithmetic<__iterator_value_type<_RandomAccessIterator> >::value;
39+
const bool __assume_both_children = is_arithmetic<__iter_value_t<_RandomAccessIterator> >::value;
4040

4141
// While it would be correct to always assume we have both children, in practice we observed this to be a performance
4242
// improvement only for arithmetic types.

libcxx/include/__algorithm/mismatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ __mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Pro
6060
template <class _Iter>
6161
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter, _Iter>
6262
__mismatch_vectorized(_Iter __first1, _Iter __last1, _Iter __first2) {
63-
using __value_type = __iterator_value_type<_Iter>;
63+
using __value_type = __iter_value_t<_Iter>;
6464
constexpr size_t __unroll_count = 4;
6565
constexpr size_t __vec_size = __native_vector_size<__value_type>;
6666
using __vec = __simd_vector<__value_type, __vec_size>;

libcxx/include/__algorithm/move.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ struct __move_impl {
8080
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
8181
operator()(_InIter __first, _InIter __last, _OutIter __result) const {
8282
using _Traits = __segmented_iterator_traits<_OutIter>;
83-
using _DiffT =
84-
typename common_type<__iterator_difference_type<_InIter>, __iterator_difference_type<_OutIter> >::type;
83+
using _DiffT = typename common_type<__iter_difference_t<_InIter>, __iter_difference_t<_OutIter> >::type;
8584

8685
if (__first == __last)
8786
return std::make_pair(std::move(__first), std::move(__result));

0 commit comments

Comments
 (0)