iterator_range<I> operator()(Rng & rng, iterator_difference_t<I> dist, V const & val, R pred = R{}, P proj = P{}) const { static_assert(!is_infinite<Rng>::value, "Trying to binary search an infinite range"); RANGES_ASSERT(0 <= dist); RANGES_ASSERT(dist <= distance(rng)); return (*this)(begin(rng), dist, std::move(pred), std::move(proj)); }
friend iterator_rvalue_reference_t<I> indirect_move(common_iterator<I, S> const &it) noexcept(noexcept(iter_move(std::declval<I const &>()))) { common_cursor const &cur = get_cursor(it); RANGES_ASSERT(!cur.is_sentinel()); return iter_move(cur.it()); }
range<I> operator()(I begin, iterator_difference_t<I> dist, V const & val, R pred_ = R{}, P proj_ = P{}) const { RANGES_ASSERT(0 <= dist); auto &&pred = invokable(pred_); auto &&proj = invokable(proj_); while(0 != dist) { auto half = dist / 2; auto middle = next(begin, half); if(pred(proj(*middle), val)) { begin = std::move(++middle); dist -= half + 1; } else if(pred(val, proj(*middle))) { dist = half; } else return {lower_bound_n(std::move(begin), half, val, std::ref(pred)), upper_bound_n(next(middle), dist - half - 1, val, std::ref(pred))}; } return {begin, begin}; }
Rng operator()(Rng && rng, range_difference_t<Rng> from, range_difference_t<Rng> to) const { RANGES_ASSERT(from <= to); ranges::action::erase(rng, next(begin(rng), to), end(rng)); ranges::action::erase(rng, begin(rng), next(begin(rng), from)); return std::forward<Rng>(rng); }
range_iterator_t<Rng> pos_at_(Rng && rng, Int i, concepts::InputRange *, std::false_type) { RANGES_ASSERT(i >= 0 || SizedRange<Rng>() || ForwardRange<Rng>()); if(0 > i) return next(ranges::begin(rng), distance(rng) + i); return next(ranges::begin(rng), i); }
std::pair<O, F> operator()(O begin, iterator_difference_t<O> n, F fun) const { RANGES_ASSERT(n >= 0); auto norig = n; auto b = uncounted(begin); for(; 0 != n; ++b, --n) *b = fun(); return {recounted(begin, b, norig), fun}; }
O operator()(O begin, iterator_difference_t<O> n, V const & val) const { RANGES_ASSERT(n >= 0); auto norig = n; auto b = uncounted(begin); for(; n != 0; ++b, --n) *b = val; return recounted(begin, b, norig); }
std::pair<I, O> operator()(I begin, iterator_difference_t<I> n, O out) const { RANGES_ASSERT(0 <= n); auto norig = n; auto b = uncounted(begin); for(; n != 0; ++b, ++out, --n) *out = *b; return {recounted(begin, b, norig), out}; }
void selection_sort(I begin, I end, C &pred, P &proj) { RANGES_ASSERT(begin != end); for(I lm1 = ranges::prev(end); begin != lm1; ++begin) { I i = ranges::min_element(begin, end, std::ref(pred), std::ref(proj)); if(i != begin) ranges::iter_swap(begin, i); } }
std::pair<I, O> operator()(I begin, iterator_difference_t<I> n, O out, P proj_ = P{}) const { RANGES_ASSERT(0 <= n); auto &&proj = invokable(proj_); auto norig = n; auto b = uncounted(begin); for(; n != 0; ++b, ++out, --n) *out = proj(*b); return {recounted(begin, b, norig), out}; }
void next() { RANGES_ASSERT(cur_ != last_); // If the last match consumed zero elements, bump the position. advance_bounded(cur_, (int)zero_, last_); zero_ = false; for(; cur_ != last_; ++cur_) { std::pair<bool, range_difference_t<Rng>> p = fun_(cur_, last_); if(p.first) { advance(cur_, p.second); zero_ = (0 == p.second); return; } } }
void operator()(Rng & rng, range_difference_t<Rng> const step) const { RANGES_ASSERT(0 < step); if(1 < step) { I begin = ranges::begin(rng); S const end = ranges::end(rng); if(begin != end) { for(I i = next_bounded(++begin, step-1, end); i != end; advance_bounded(i, step, end), ++begin) { *begin = std::move(*i); } } ranges::action::erase(rng, begin, end); } }
I operator()(I const begin_, iterator_difference_t<I> const n_, C pred_ = C{}, P proj_ = P{}) const { RANGES_ASSERT(0 <= n_); auto &&pred = as_function(pred_); auto &&proj = as_function(proj_); iterator_difference_t<I> p = 0, c = 1; I pp = begin_; while(c < n_) { I cp = begin_ + c; if(pred(proj(*pp), proj(*cp))) return cp; ++c; ++cp; if(c == n_ || pred(proj(*pp), proj(*cp))) return cp; ++p; ++pp; c = 2 * p + 1; } return begin_ + n_; }
cursor<true> begin_cursor() const { RANGES_ASSERT(!!gen_); return {*gen_}; }
cursor<false> begin_cursor() { RANGES_ASSERT(!!gen_); return {*gen_}; }
T const & get() const { RANGES_ASSERT(!!t_); return *t_; }
T & get() { RANGES_ASSERT(!!t_); return *t_; }
friend counted_iterator<I, D> recounted(counted_iterator<I, D> const &j, I i, iterator_difference_t<I> n) { RANGES_ASSERT(!ForwardIterator<I>() || ranges::next(j.base(), n) == i); return {i, j.count() - n}; }
void next() { RANGES_ASSERT(0 != n_); --n_; }
T & get() const noexcept { RANGES_ASSERT(nullptr != t_); return *t_; }
slice_view_(Rng rng, difference_type_ from, difference_type_ count) : rng_(std::move(rng)), from_(from), count_(count) { RANGES_ASSERT(0 <= count_); }
I const & it() const { RANGES_ASSERT(!is_sentinel()); return ranges::get<0>(data_); }
Rng operator()(Rng && rng, range_difference_t<Rng> n) const { RANGES_ASSERT(n >= 0); ranges::action::erase(rng, ranges::next(begin(rng), n, end(rng)), end(rng)); return std::forward<Rng>(rng); }
S const & se() const { RANGES_ASSERT(is_sentinel()); return ranges::get<1>(data_); }
chunk_view(Rng rng, range_difference_t<Rng> n) : view_adaptor_t<chunk_view>(std::move(rng)), n_(n) { RANGES_ASSERT(0 < n_); }
constexpr repeat_n_view(Val value, std::ptrdiff_t n) : value_(detail::move(value)), n_((RANGES_ASSERT(0 <= n), n)) {}
range_iterator_t<Rng> pos_at_(Rng && rng, Int i, concepts::InputRange *, std::true_type) { RANGES_ASSERT(0 <= i); return next(ranges::begin(rng), i); }
T const & operator*() const { RANGES_ASSERT(!!*this); return ranges::get<0>(data_); }
stride_view(Rng rng, difference_type_ stride) : view_adaptor_t<stride_view>{std::move(rng)} , stride_(stride) { RANGES_ASSERT(0 < stride_); }
inline Target polymorphic_downcast(Source* x) { RANGES_ASSERT(dynamic_cast<Target>(x) == x); return static_cast<Target>(x); }