Horizon
stride.hpp
Go to the documentation of this file.
1
2// Range v3 library
3//
4// Copyright Eric Niebler 2013-present
5//
6// Use, modification and distribution is subject to the
7// Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt)
10//
11// Project home: https://github.com/ericniebler/range-v3
12//
13
14#ifndef RANGES_V3_ACTION_STRIDE_HPP
15#define RANGES_V3_ACTION_STRIDE_HPP
16
18
25#include <range/v3/utility/static_const.hpp>
26
27#include <range/v3/detail/prologue.hpp>
28
29namespace ranges
30{
33 namespace actions
34 {
35 struct stride_fn
36 {
37 template(typename D)(
38 requires detail::integer_like_<D>)
39 constexpr auto operator()(D step) const
40 {
41 return make_action_closure(bind_back(stride_fn{}, step));
42 }
43
44 template(typename Rng, typename D = range_difference_t<Rng>)(
45 requires forward_range<Rng> AND
46 erasable_range<Rng &, iterator_t<Rng>, sentinel_t<Rng>> AND
48 Rng operator()(Rng && rng, range_difference_t<Rng> const step) const
49 {
50 using I = iterator_t<Rng>;
51 using S = sentinel_t<Rng>;
52 RANGES_EXPECT(0 < step);
53 if(1 < step)
54 {
55 I first = ranges::begin(rng);
56 S const last = ranges::end(rng);
57 if(first != last)
58 {
59 for(I i = ranges::next(++first, step - 1, last); i != last;
60 advance(i, step, last), ++first)
61 {
62 *first = iter_move(i);
63 }
64 }
65 ranges::actions::erase(rng, first, last);
66 }
67 return static_cast<Rng &&>(rng);
68 }
69 };
70
73 } // namespace actions
75} // namespace ranges
76
77#include <range/v3/detail/epilogue.hpp>
78
79#endif
The erasable_range concept.
The forward_range concept.
The permutable concept.
decltype(begin(declval(Rng &))) iterator_t
Definition: access.hpp:698
RANGES_INLINE_VARIABLE(detail::to_container_fn< detail::from_range< std::vector > >, to_vector) template< template< typename... > class ContT > auto to(RANGES_HIDDEN_DETAIL(detail
For initializing a container of the specified type with the elements of an Range.
Definition: conversion.hpp:399
defer< bind_back, Fn, Ts... > bind_back
Definition: meta.hpp:994
front< Pair > first
Retrieve the first element of the pair Pair.
Definition: meta.hpp:2251
Definition: stride.hpp:36