codex
Loading...
Searching...
No Matches
rotate.hpp
Go to the documentation of this file.
1#ifndef CODEX_ALGO_ROTATE_H
2#define CODEX_ALGO_ROTATE_H
3
4#include <iterator>
5
6namespace codex {
7
8template<std::permutable I, std::sentinel_for<I> S>
9void rotate_rec(I b, I n, S e) {
10 if(b == n || n == e)
11 return;
12 for(auto i = n;;) {
13 std::iter_swap(b++, i++);
14 if(b == n)
15 return rotate_rec(b, i, e);
16 if(i == e)
17 return rotate_rec(b, n, e);
18 }
19}
20
21template<std::permutable I, std::sentinel_for<I> S>
22void rotate(I b, I n, S e) {
23 if(b == n || n == e)
24 return;
25 for(auto i = n;;) {
26 std::iter_swap(b++, i++);
27 if(i == e) {
28 if(b == n)
29 return;
30 i = n;
31 } else if(b == n)
32 n = i;
33 }
34}
35
36}
37
38#endif
Definition rotate.hpp:6
void rotate(I b, I n, S e)
Definition rotate.hpp:22
void rotate_rec(I b, I n, S e)
Definition rotate.hpp:9
Definition reflexpr.cpp:168
Definition mult_inh.c:26