PlasmaActivitiesStats

slide.h
1/*
2 SPDX-FileCopyrightText: 2015 Ivan Cukic <ivan.cukic(at)kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#ifndef UTILS_SLIDE_H
8#define UTILS_SLIDE_H
9
10#include <algorithm>
11
12// Inspired by C++ Seasoning talk by Sean Parent
13
14namespace kamd
15{
16namespace utils
17{
18template<typename Iterator>
19void slide(Iterator f, Iterator l, Iterator p)
20{
21 if (p < f) {
22 std::rotate(p, f, l);
23 } else if (l < p) {
24 std::rotate(f, l, p);
25 }
26}
27
28template<typename Iterator>
29void slide_one(Iterator f, Iterator p)
30{
31 slide(f, f + 1, p);
32}
33
34template<typename Iterator>
35void move_one(Iterator from, Iterator to)
36{
37 if (from < to) {
38 while (from != to) {
39 using std::swap;
40 swap(*from, *(from + 1));
41 ++from;
42 }
43 } else {
44 while (from != to) {
45 using std::swap;
46 swap(*from, *(from - 1));
47 --from;
48 }
49 }
50}
51
52} // namespace utils
53} // namespace kamd
54
55#endif // UTILS_SLIDE_H
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 12:01:02 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.