PlasmaActivities

qflatset.h
1/*
2 SPDX-FileCopyrightText: 2016 Ivan Čukić <ivan.cukic(at)kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef KACTIVITIES_STATS_QFLATSET_H
8#define KACTIVITIES_STATS_QFLATSET_H
9
10#include <QList>
11#include <QPair>
12
13namespace KActivities
14{
15template<typename T, typename LessThan>
16class QFlatSet : public QList<T>
17{
18public:
19 QFlatSet()
20 {
21 }
22
23 inline
24 // QPair<typename QList<T>::iterator, bool> insert(const T &value)
25 std::tuple<typename QList<T>::iterator, int, bool>
26 insert(const T &value)
27 {
28 auto lessThan = LessThan();
29 auto begin = this->begin();
30 auto end = this->end();
31
32 if (begin == end) {
34
35 return std::make_tuple(QList<T>::begin(), 0, true);
36
37 } else {
38 auto iterator = std::lower_bound(begin, end, value, lessThan);
39
40 if (iterator != end) {
41 if (!lessThan(value, *iterator)) {
42 // Already present
43 return std::make_tuple(iterator, iterator - begin, false);
44 }
45 }
46
47 QList<T>::insert(iterator, value);
48
49 return std::make_tuple(iterator, iterator - begin, true);
50 }
51 }
52
53private:
54 QFlatSet(const QFlatSet &original); // = delete
55};
56
57} // namespace KActivities
58
59#endif // KACTIVITIES_STATS_QFLATSET_H
Namespace for everything in libkactivities.
iterator begin()
iterator end()
iterator insert(const_iterator before, parameter_type value)
T value(qsizetype i) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 12:01:06 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.