Horizon
Loading...
Searching...
No Matches
reverse.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#ifndef RANGES_V3_ALGORITHM_REVERSE_HPP
14#define RANGES_V3_ALGORITHM_REVERSE_HPP
15
17
25#include <range/v3/utility/static_const.hpp>
27
28#include <range/v3/detail/prologue.hpp>
29
30namespace ranges
31{
34
36 namespace detail
37 {
38 template<typename I>
39 constexpr void reverse_impl(I first, I last, std::bidirectional_iterator_tag)
40 {
41 while(first != last)
42 {
43 if(first == --last)
44 break;
45 ranges::iter_swap(first, last);
46 ++first;
47 }
48 }
49
50 template<typename I>
51 constexpr void reverse_impl(I first, I last, std::random_access_iterator_tag)
52 {
53 if(first != last)
54 for(; first < --last; ++first)
55 ranges::iter_swap(first, last);
56 }
57 } // namespace detail
59
60 RANGES_FUNC_BEGIN(reverse)
61
62
63 template(typename I, typename S)(
64 requires bidirectional_iterator<I> AND sentinel_for<S, I> AND permutable<I>)
65 constexpr I RANGES_FUNC(reverse)(I first, S end_)
66 {
67 I last = ranges::next(first, end_);
68 detail::reverse_impl(first, last, iterator_tag_of<I>{});
69 return last;
70 }
71
73 template(typename Rng, typename I = iterator_t<Rng>)(
75 constexpr borrowed_iterator_t<Rng> RANGES_FUNC(reverse)(Rng && rng) //
76 {
77 return (*this)(begin(rng), end(rng));
78 }
79
80 RANGES_FUNC_END(reverse)
81
82 namespace cpp20
83 {
84 using ranges::reverse;
85 }
87} // namespace ranges
88
89#include <range/v3/detail/epilogue.hpp>
90
91#endif
The bidirectional_iterator concept.
The bidirectional_range concept.
The permutable concept.
The sentinel_for concept.
decltype(begin(declval(Rng &))) iterator_t
Definition access.hpp:698
front< Pair > first
Retrieve the first element of the pair Pair.
Definition meta.hpp:2251