AusweisApp2
Lade ...
Suche ...
Keine Treffer
FuncUtils.h
gehe zur Dokumentation dieser Datei
1
7#pragma once
8
9#include <functional>
10#include <type_traits>
11
12#include <QVector>
13
14namespace governikus
15{
16
17#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
18
19/*
20 * Usage example: map<Reader, QString>([](const Reader& r){ return r.getName(); }, readers)
21 *
22 * where readers has type QVector<Reader>
23 */
24template<typename S, typename T>
25std::enable_if_t<!std::is_void_v<T>, QVector<T>> map(const std::function<T(const S&)>& pFunc, const QVector<S>& pItems)
26{
27 const auto sz = pItems.size();
28 QVector<T> result(sz);
29 for (int index = 0; index < sz; ++index)
30 {
31 result[index] = pFunc(pItems[index]);
32 }
33
34 return result;
35}
36
37
38#endif
39
40
41/*
42 * Usage example: map<Reader, QString>([](const Reader& r){ return r.getName(); }, readers)
43 *
44 * where readers has type QList<Reader>
45 */
46template<typename S, typename T>
47std::enable_if_t<!std::is_void_v<T>, QList<T>> map(const std::function<T(const S&)>& pFunc, const QList<S>& pItems)
48{
49 const auto sz = pItems.size();
50 QList<T> result;
51 for (int index = 0; index < sz; ++index)
52 {
53 result.append(pFunc(pItems[index]));
54 }
55
56 return result;
57}
58
59
60/*
61 * Usage example: filter<Reader>([](const Reader& r){ return r.getCard() != nullptr; }, readers)
62 *
63 * where readers has type QVector<Reader>
64 */
65template<typename T>
66std::enable_if_t<!std::is_void_v<T>, QVector<T>> filter(const std::function<bool(const T&)>& pFunc, const QVector<T>& pItems)
67{
68 QVector<T> result;
69 for (const T& item : pItems)
70 {
71 if (pFunc(item))
72 {
73 result += item;
74 }
75 }
76
77 return result;
78}
79
80
81} // namespace governikus
#define T(v)
Definition: http_parser.cpp:237
A simple template renderer.
Definition: ActivationContext.h:15
std::enable_if_t<!std::is_void_v< T >, QList< T > > map(const std::function< T(const S &)> &pFunc, const QList< S > &pItems)
Definition: FuncUtils.h:47
std::enable_if_t<!std::is_void_v< T >, QVector< T > > filter(const std::function< bool(const T &)> &pFunc, const QVector< T > &pItems)
Definition: FuncUtils.h:66