AusweisApp
Lade ...
Suche ...
Keine Treffer
FuncUtils.h
gehe zur Dokumentation dieser Datei
1
4
5#pragma once
6
7#include <functional>
8#include <type_traits>
9
10#include <QList>
11
12
13namespace governikus
14{
15
16
17/*
18 * Usage example: map<Reader, QString>([](const Reader& r){ return r.getName(); }, readers)
19 *
20 * where readers has type QList<Reader>
21 */
22template<typename S, typename T>
23std::enable_if_t<!std::is_void_v<T>, QList<T>> map(const std::function<T(const S&)>& pFunc, const QList<S>& pItems)
24{
25 const auto sz = pItems.size();
26 QList<T> result;
27 for (int index = 0; index < sz; ++index)
28 {
29 result.append(pFunc(pItems[index]));
30 }
31
32 return result;
33}
34
35
36/*
37 * Usage example: filter<Reader>([](const Reader& r){ return r.getCard() != nullptr; }, readers)
38 *
39 * where readers has type QList<Reader>
40 */
41template<typename T>
42std::enable_if_t<!std::is_void_v<T>, QList<T>> filter(const std::function<bool(const T&)>& pFunc, const QList<T>& pItems)
43{
44 QList<T> result;
45 for (const T& item : pItems)
46 {
47 if (pFunc(item))
48 {
49 result += item;
50 }
51 }
52
53 return result;
54}
55
56
57} // namespace governikus
#define T(v)
Definition http_parser.cpp:237
Defines the AccessRight and AccessRole enum.
Definition CommandApdu.h:17
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:23
std::enable_if_t<!std::is_void_v< T >, QList< T > > filter(const std::function< bool(const T &)> &pFunc, const QList< T > &pItems)
Definition FuncUtils.h:42