Skip to content

Commit 2af9a6f

Browse files
committed
Address feedback about using iterator_traits<_Iter>::difference_type instead of a templated _Distance in _IterOps::__advance_to()
1 parent 4588447 commit 2af9a6f

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

libcxx/include/__algorithm/iterator_operations.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,28 @@ struct _IterOps<_ClassicAlgPolicy> {
8989
// advance with sentinel, a la std::ranges::advance
9090
// it's unclear whether _Iter has a difference_type and whether that's signed, so we play it safe:
9191
// use the incoming type for returning and steer clear of negative overflows
92-
template <class _Iter, class _Distance>
93-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static _Distance
94-
__advance_to(_Iter& __iter, _Distance __count, const _Iter& __sentinel) {
92+
template <class _Iter>
93+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_Iter>
94+
__advance_to(_Iter& __iter, __difference_type<_Iter> __count, const _Iter& __sentinel) {
9595
return _IterOps::__advance_to(__iter, __count, __sentinel, typename iterator_traits<_Iter>::iterator_category());
9696
}
9797

9898
private:
9999
// advance with sentinel, a la std::ranges::advance -- InputIterator specialization
100-
template <class _InputIter, class _Distance>
101-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static _Distance
102-
__advance_to(_InputIter& __iter, _Distance __count, const _InputIter& __sentinel, input_iterator_tag) {
103-
_Distance __dist = _Distance();
100+
template <class _InputIter>
101+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_InputIter>
102+
__advance_to(_InputIter& __iter, __difference_type<_InputIter> __count, const _InputIter& __sentinel, input_iterator_tag) {
103+
__difference_type<_InputIter> __dist = 0;
104104
for (; __dist < __count && __iter != __sentinel; ++__dist)
105105
++__iter;
106106
return __count - __dist;
107107
}
108108

109109
// advance with sentinel, a la std::ranges::advance -- BidirectionalIterator specialization
110-
template <class _BiDirIter, class _Distance>
111-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static _Distance
112-
__advance_to(_BiDirIter& __iter, _Distance __count, const _BiDirIter& __sentinel, bidirectional_iterator_tag) {
113-
_Distance __dist = _Distance();
110+
template <class _BiDirIter>
111+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_BiDirIter>
112+
__advance_to(_BiDirIter& __iter, __difference_type<_BiDirIter> __count, const _BiDirIter& __sentinel, bidirectional_iterator_tag) {
113+
__difference_type<_BiDirIter> __dist = 0;
114114
if (__count >= 0)
115115
for (; __dist < __count && __iter != __sentinel; ++__dist)
116116
++__iter;
@@ -121,9 +121,9 @@ struct _IterOps<_ClassicAlgPolicy> {
121121
}
122122

123123
// advance with sentinel, a la std::ranges::advance -- RandomIterator specialization
124-
template <class _RandIter, class _Distance>
125-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static _Distance
126-
__advance_to(_RandIter& __iter, _Distance __count, const _RandIter& __sentinel, random_access_iterator_tag) {
124+
template <class _RandIter>
125+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_RandIter>
126+
__advance_to(_RandIter& __iter, __difference_type<_RandIter> __count, const _RandIter& __sentinel, random_access_iterator_tag) {
127127
auto __dist = _IterOps::distance(__iter, __sentinel);
128128
_LIBCPP_ASSERT_VALID_INPUT_RANGE(
129129
__count == 0 || (__dist < 0) == (__count < 0), "__sentinel must precede __iter when __count < 0");

0 commit comments

Comments
 (0)