Akonadi

vectorhelper.h
1 /*
2  Copyright (C) 2015-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #ifndef VECTORHELPER_H
21 #define VECTORHELPER_H
22 
23 #include <QVector>
24 #include <QSet>
25 
26 #include <algorithm>
27 
28 namespace Akonadi
29 {
30 template<typename Key, typename Value, template<typename, typename> class Container>
31 QVector<Value> valuesToVector(const Container<Key, Value> &container)
32 {
34  values.reserve(container.size());
35  for (const auto &value : container) {
36  values.append(value);
37  }
38  return values;
39 }
40 
41 template<typename T>
42 QSet<T> vectorToSet(const QVector<T> &container)
43 {
44  QSet<T> set;
45  set.reserve(container.size());
46  for (const auto &value : container) {
47  set.insert(value);
48  }
49  return set;
50 }
51 
52 template<typename Value, template<typename> class Container>
53 QVector<Value> setToVector(const Container<Value> &container)
54 {
55  QVector<Value> values;
56  values.reserve(container.size());
57  for (const auto &value : container) {
58  values.append(value);
59  }
60  return values;
61 }
62 
63 } // namespace Akonadi
64 
65 #endif // VECTORHELPER_H
void append(const T &value)
QVector< V > values(const QMultiHash< K, V > &c)
void reserve(int size)
Definition: item.h:44
Helper integration between Akonadi and Qt.
void reserve(int size)
int size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.