src/functional.h

Tue, 28 Jun 2022 14:20:08 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 28 Jun 2022 14:20:08 +0300
changeset 287
59562d8f8372
parent 259
c27612f0eac0
permissions
-rw-r--r--

Add scroll bars to the mdi area

63
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 /*
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 * Copyright (C) 2020 Teemu Piippo
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 *
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 * (at your option) any later version.
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 *
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 * GNU General Public License for more details.
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 *
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 */
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #pragma once
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 #include <algorithm>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 #include <functional>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 #include <QVector>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 #include <QSet>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 #include <QList>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 namespace fn
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 template<typename C>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 class InsertIterator;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 }
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 /**
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 * Like std::back_inserter but calls x.insert(v) instead
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 */
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 template<typename C>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 class fn::InsertIterator
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 public:
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 InsertIterator(C& container) :
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 container{container} {}
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 auto operator*()
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 return *this;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 }
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 auto operator++()
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 return *this;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 }
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 auto operator++(int)
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 return *this;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 }
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 template<typename T>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 auto operator=(T&& value)
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 this->container.insert(std::forward<T>(value));
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 return *this;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 }
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 private:
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 C& container;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 };
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 namespace fn
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 // Constructs a fn::InsertIterator
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 template<typename C>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 InsertIterator<C> makeInsertIterator(C& container)
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 return InsertIterator<C>{container};
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 }
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 // Constructs a back_inserter for std::vector
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 template<typename T>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 auto makeDefaultInserter(std::vector<T>& vec)
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 return std::back_inserter(vec);
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77 }
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 123
diff changeset
79 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 123
diff changeset
80 // In Qt6 QVector is now a QList instead, so we need to disable this
63
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81 // Constructs a back_inserter for QVector
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 template<typename T>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 auto makeDefaultInserter(QVector<T>& vec)
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 return std::back_inserter(vec);
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86 }
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 123
diff changeset
87 #endif
63
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 template<typename T>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 auto makeDefaultInserter(QList<T>& vec)
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
92 return std::back_inserter(vec);
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 }
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
94
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
95 // Constructs an fn::InsertIterator for QSet
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
96 template<typename T>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97 auto makeDefaultInserter(QSet<T>& vec)
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
99 return InsertIterator(vec);
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 }
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 // Changes the value type of C
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 template<typename C, typename TT>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 struct ChangeContainerValueType
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
106 };
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
108 // Changes the value type of std::vector
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
109 template<typename T, typename TT>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
110 struct ChangeContainerValueType<std::vector<T>, TT>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
111 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
112 using type = std::vector<TT>;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
113 };
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
114
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 123
diff changeset
115 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
63
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
116 // Changes the value type of QVector
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
117 template<typename T, typename TT>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
118 struct ChangeContainerValueType<QVector<T>, TT>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
119 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
120 using type = QVector<TT>;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
121 };
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 123
diff changeset
122 #endif
63
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
123
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
124 // Changes the value type of QSet
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
125 template<typename T, typename TT>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
126 struct ChangeContainerValueType<QSet<T>, TT>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
127 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
128 using type = QSet<TT>;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
129 };
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
130
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
131 // Changes the value type of QList
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
132 template<typename T, typename TT>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
133 struct ChangeContainerValueType<QList<T>, TT>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
134 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
135 using type = QList<TT>;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
136 };
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
137
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
138 // Changes the value type of C
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
139 template<typename C, typename TT>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
140 using ChangeContainerValueType_t = typename ChangeContainerValueType<C, TT>::type;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
141
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
142 /**
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
143 * \brief Applies \c function to all elements of \c container
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
144 * \param container Container to iterate
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
145 * \param function Function to apply
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
146 * \param Rt result type. If not provided, a suitable result type is deduced from inputs
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
147 * \returns mapped result container
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
148 */
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
149 template<typename Rt = void, typename C, typename Fn>
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
150 auto map(C&& container, Fn&& function)
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
151 {
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
152 using value_t = decltype(*std::declval<C>().begin());
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
153 using newvalue_t = std::result_of_t<Fn(value_t)>;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
154 using result_t = std::conditional_t<
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
155 std::is_same_v<Rt, void>,
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
156 ChangeContainerValueType_t<std::remove_reference_t<C>, newvalue_t>,
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
157 Rt>;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
158 result_t result;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
159 result.reserve(std::end(container) - std::begin(container));
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
160 std::transform(std::begin(container), std::end(container), makeDefaultInserter(result), function);
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
161 return result;
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
162 }
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
163 }
106
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
164
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
165 template<typename T, typename Fn>
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
166 bool any(T&& container, Fn&& f)
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
167 {
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
168 for (auto&& x : container)
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
169 {
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
170 if (f(x))
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
171 {
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
172 return true;
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
173 }
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
174 }
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
175 return false;
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
176 }
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
177
123
e3fe3617b631 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 106
diff changeset
178
106
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
179 template<typename T, typename Fn>
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
180 bool all(T&& container, Fn&& f)
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
181 {
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
182 for (auto&& x : container)
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
183 {
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
184 if (not f(x))
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
185 {
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
186 return false;
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
187 }
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
188 }
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
189 return true;
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
190 }

mercurial