Skip to content

Commit 71f7d68

Browse files
committed
fix sample implementation
1 parent edc4860 commit 71f7d68

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

reference/algorithm/ranges_search_n.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ struct search_n_impl {
167167
requires indirectly_comparable<I, const T*, Pred, Proj>
168168
constexpr subrange<I> operator()(I first, S last, iter_difference_t<I> count, const T& value, Pred pred = {}, Proj proj = {}) const {
169169
if (first == last || count <= 0)
170-
return first;
170+
return {first, first};
171171
172172
while (first != last) {
173173
if (*first == value) {
@@ -177,20 +177,21 @@ struct search_n_impl {
177177
for (; i < count && it != last && invoke(pred, invoke(proj, *it), value); ++i, ++it)
178178
;
179179
if (i == count)
180-
return {first, i};
180+
return {first, it};
181181
else if (it == last)
182-
return {last, last};
182+
return {it, it};
183183
else
184184
first = it;
185185
}
186186
++first;
187187
}
188+
return {first, first};
188189
}
189190
190191
template<forward_range R, class T, class Pred = ranges::equal_to, class Proj = identity>
191192
requires indirectly_comparable<iterator_t<R>, const T*, Pred, Proj>
192193
constexpr borrowed_subrange_t<R> operator()(R&& r, range_difference_t<R> count, const T& value, Pred pred = {}, Proj proj = {}) const {
193-
return (*this)(begin(r1), end(r1), count, value, ref(pred), ref(proj));
194+
return (*this)(begin(r), end(r), count, value, ref(pred), ref(proj));
194195
}
195196
};
196197

0 commit comments

Comments
 (0)