Akonadi

vectorhelper.h
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QList>
10#include <QSet>
11
12#include <algorithm>
13
14namespace Akonadi
15{
16template<typename Key, typename Value, template<typename, typename> class Container>
17QList<Value> valuesToVector(const Container<Key, Value> &container)
18{
19 QList<Value> values;
20 values.reserve(container.size());
21 for (const auto &value : container) {
22 values.append(value);
23 }
24 return values;
25}
26
27template<typename T>
28QSet<T> vectorToSet(const QList<T> &container)
29{
30 QSet<T> set;
31 set.reserve(container.size());
32 for (const auto &value : container) {
33 set.insert(value);
34 }
35 return set;
36}
37
38template<typename Value, template<typename> class Container>
39QList<Value> setToVector(const Container<Value> &container)
40{
41 QList<Value> values;
42 values.reserve(container.size());
43 for (const auto &value : container) {
44 values.append(value);
45 }
46 return values;
47}
48
49} // namespace Akonadi
Helper integration between Akonadi and Qt.
void append(QList< T > &&value)
void reserve(qsizetype size)
qsizetype size() const const
iterator insert(const T &value)
void reserve(qsizetype size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.