tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
rotate.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_ROTATE_HPP
4#define TETL_ALGORITHM_ROTATE_HPP
5
7
8namespace etl {
9
16template <typename ForwardIt>
17constexpr auto rotate(ForwardIt first, ForwardIt nFirst, ForwardIt last) -> ForwardIt
18{
19 if (first == nFirst) {
20 return last;
21 }
22 if (nFirst == last) {
23 return first;
24 }
25
26 auto read = nFirst;
27 auto write = first;
28 auto nextRead = first;
29
30 while (read != last) {
31 if (write == nextRead) {
32 nextRead = read;
33 }
34 etl::iter_swap(write++, read++);
35 }
36
37 etl::rotate(write, nextRead, last);
38 return write;
39}
40
41} // namespace etl
42
43#endif // TETL_ALGORITHM_ROTATE_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 rotate(ForwardIt first, ForwardIt nFirst, ForwardIt last) -> ForwardIt
Performs a left rotation on a range of elements.
Definition rotate.hpp:17
Definition adjacent_find.hpp:8