tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
reverse.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_REVERSE_HPP
4#define TETL_ALGORITHM_REVERSE_HPP
5
10
11namespace etl {
12
15template <typename BidirIt>
16constexpr auto reverse(BidirIt first, BidirIt last) -> void
17{
20 if (first == last) {
21 return;
22 }
23
24 for (--last; first < last; (void)++first, --last) {
25 etl::iter_swap(first, last);
26 }
27 } else {
28 while (first != last and first != --last) {
29 etl::iter_swap(first++, last);
30 }
31 }
32}
33
34} // namespace etl
35
36#endif // TETL_ALGORITHM_REVERSE_HPP
constexpr auto iter_swap(ForwardIt1 a, ForwardIt2 b) -> void
Swaps the values of the elements the given iterators are pointing to.
Definition iter_swap.hpp:19
constexpr auto reverse(BidirIt first, BidirIt last) -> void
Reverses the order of the elements in the range [first, last).
Definition reverse.hpp:16
Definition adjacent_find.hpp:8
constexpr bool is_base_of_v
Definition is_base_of.hpp:39
iterator_traits is the type trait class that provides uniform interface to the properties of LegacyIt...
Definition iterator_traits.hpp:47