Horizon
reverse_copy.hpp
Go to the documentation of this file.
1 // Range v3 library
3 //
4 // Copyright Eric Niebler 2014-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 #ifndef RANGES_V3_ALGORITHM_REVERSE_COPY_HPP
14 #define RANGES_V3_ALGORITHM_REVERSE_COPY_HPP
15 
16 #include <meta/meta.hpp>
17 
18 #include <range/v3/range_fwd.hpp>
19 
20 #include <range/v3/algorithm/result_types.hpp>
28 #include <range/v3/utility/static_const.hpp>
29 
30 #include <range/v3/detail/prologue.hpp>
31 
32 namespace ranges
33 {
36  template<typename I, typename O>
37  using reverse_copy_result = detail::in_out_result<I, O>;
38 
39  RANGES_FUNC_BEGIN(reverse_copy)
40 
41 
42  template(typename I, typename S, typename O)(
43  requires bidirectional_iterator<I> AND sentinel_for<S, I> AND
44  weakly_incrementable<O> AND indirectly_copyable<I, O>)
45  constexpr reverse_copy_result<I, O> RANGES_FUNC(reverse_copy)(I first, S end_, O out) //
46  {
47  I last = ranges::next(first, end_), res = last;
48  for(; first != last; ++out)
49  *out = *--last;
50  return {res, out};
51  }
52 
54  template(typename Rng, typename O)(
55  requires bidirectional_range<Rng> AND weakly_incrementable<O> AND
56  indirectly_copyable<iterator_t<Rng>, O>)
57  constexpr reverse_copy_result<borrowed_iterator_t<Rng>, O> //
58  RANGES_FUNC(reverse_copy)(Rng && rng, O out) //
59  {
60  return (*this)(begin(rng), end(rng), std::move(out));
61  }
62 
63  RANGES_FUNC_END(reverse_copy)
64 
65  namespace cpp20
66  {
67  using ranges::reverse_copy;
68  using ranges::reverse_copy_result;
69  } // namespace cpp20
71 } // namespace ranges
72 
73 #include <range/v3/detail/epilogue.hpp>
74 
75 #endif
CPP_concept indirectly_copyable
\concept indirectly_copyable
Definition: concepts.hpp:782
front< Pair > first
Retrieve the first element of the pair Pair.
Definition: meta.hpp:2251
Tiny meta-programming library.