• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

boostorg / geometry / 20212

28 Jul 2023 09:16AM UTC coverage: 94.211% (-0.2%) from 94.458%
20212

push

circle-ci

vissarion
Merge branch 'develop'

39303 of 41718 relevant lines covered (94.21%)

1319371.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.44
include/boost/geometry/util/algorithm.hpp
1
// Boost.Geometry
2

3
// Copyright (c) 2021, Oracle and/or its affiliates.
4

5
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6

7
// Licensed under the Boost Software License version 1.0.
8
// http://www.boost.org/users/license.html
9

10
#ifndef BOOST_GEOMETRY_UTIL_ALGORITHM_HPP
11
#define BOOST_GEOMETRY_UTIL_ALGORITHM_HPP
12

13

14
#include <boost/geometry/core/coordinate_dimension.hpp>
15
#include <boost/geometry/util/type_traits_std.hpp>
16

17

18
namespace boost { namespace geometry
19
{
20

21
#ifndef DOXYGEN_NO_DETAIL
22
namespace detail
23
{
24

25
// Other implementations can be found in the history of this file.
26
// The discussion and benchmarks can be found here:
27
// https://github.com/boostorg/geometry/pull/827
28

29
// O(logN) version 2
30

31
template <std::size_t N>
32
struct for_each_index_impl2
33
{
34
    static const std::size_t N1 = N / 2;
35
    static const std::size_t N2 = N - N1;
36

37
    template <std::size_t Offset, typename UnaryFunction>
38
    constexpr static inline void apply(UnaryFunction& function)
29✔
39
    {
40
        for_each_index_impl2<N1>::template apply<Offset>(function);
29✔
41
        for_each_index_impl2<N2>::template apply<Offset + N1>(function);
29✔
42
    }
29✔
43
};
44

45
template <>
46
struct for_each_index_impl2<3>
47
{
48
    template <std::size_t Offset, typename UnaryFunction>
49
    constexpr static inline void apply(UnaryFunction& function)
122,519✔
50
    {
51
        function(util::index_constant<Offset>());
122,519✔
52
        function(util::index_constant<Offset + 1>());
122,519✔
53
        function(util::index_constant<Offset + 2>());
122,519✔
54
    }
122,519✔
55
};
56

57
template <>
58
struct for_each_index_impl2<2>
59
{
60
    template <std::size_t Offset, typename UnaryFunction>
61
    constexpr static inline void apply(UnaryFunction& function)
8,151,471✔
62
    {
63
        function(util::index_constant<Offset>());
8,151,471✔
64
        function(util::index_constant<Offset + 1>());
8,151,471✔
65
    }
8,151,471✔
66
};
67

68
template <>
69
struct for_each_index_impl2<1>
70
{
71
    template <std::size_t Offset, typename UnaryFunction>
72
    constexpr static inline void apply(UnaryFunction& function)
38,367✔
73
    {
74
        function(util::index_constant<Offset>());
38,367✔
75
    }
38,367✔
76
};
77

78
template <>
79
struct for_each_index_impl2<0>
80
{
81
    template <std::size_t Offset, typename UnaryFunction>
82
    constexpr static inline void apply(UnaryFunction& )
1✔
83
    {}
1✔
84
};
85

86
// Interface
87

88
template <std::size_t N, typename UnaryFunction>
89
constexpr inline UnaryFunction for_each_index(UnaryFunction function)
5✔
90
{
91
    for_each_index_impl2
92
        <
93
            N
94
        >::template apply<0>(function);
5✔
95
    return function;
5✔
96
}
97

98
template <typename Geometry, typename UnaryFunction>
99
constexpr inline UnaryFunction for_each_dimension(UnaryFunction function)
8,312,324✔
100
{
101
    for_each_index_impl2
102
        <
103
            geometry::dimension<Geometry>::value
104
        >::template apply<0>(function);
8,312,324✔
105
    return function;
8,312,324✔
106
}
107

108
// ----------------------------------------------------------------------------
109

110
// O(logN) version 2
111

112
template <std::size_t N>
113
struct all_indexes_of_impl2
114
{
115
    static const std::size_t N1 = N / 2;
116
    static const std::size_t N2 = N - N1;
117

118
    template <std::size_t Offset, typename UnaryPredicate>
119
    constexpr static inline bool apply(UnaryPredicate& predicate)
1✔
120
    {
121
        return all_indexes_of_impl2<N1>::template apply<Offset>(predicate)
1✔
122
            && all_indexes_of_impl2<N2>::template apply<Offset + N1>(predicate);
1✔
123
    }
124
};
125

126
template <>
127
struct all_indexes_of_impl2<3>
128
{
129
    template <std::size_t Offset, typename UnaryPredicate>
130
    constexpr static inline bool apply(UnaryPredicate& predicate)
1✔
131
    {
132
        return predicate(util::index_constant<Offset>())
1✔
133
            && predicate(util::index_constant<Offset + 1>())
×
134
            && predicate(util::index_constant<Offset + 2>());
1✔
135
    }
136
};
137

138
template <>
139
struct all_indexes_of_impl2<2>
140
{
141
    template <std::size_t Offset, typename UnaryPredicate>
142
    constexpr static inline bool apply(UnaryPredicate& predicate)
2✔
143
    {
144
        return predicate(util::index_constant<Offset>())
2✔
145
            && predicate(util::index_constant<Offset + 1>());
2✔
146
    }
147
};
148

149
template <>
150
struct all_indexes_of_impl2<1>
151
{
152
    template <std::size_t Offset, typename UnaryPredicate>
153
    constexpr static inline bool apply(UnaryPredicate& predicate)
1✔
154
    {
155
        return predicate(util::index_constant<Offset>());
1✔
156
    }
157
};
158

159
template <>
160
struct all_indexes_of_impl2<0>
161
{
162
    template <std::size_t Offset, typename UnaryPredicate>
163
    constexpr static inline bool apply(UnaryPredicate& )
6✔
164
    {
165
        return true;
6✔
166
    }
167
};
168

169
// Interface
170

171
template <std::size_t N, typename UnaryPredicate>
172
constexpr inline bool all_indexes_of(UnaryPredicate predicate)
6✔
173
{
174
    return all_indexes_of_impl2<N>::template apply<0>(predicate);
6✔
175
}
176

177
template <typename Geometry, typename UnaryPredicate>
178
constexpr inline bool all_dimensions_of(UnaryPredicate predicate)
4✔
179
{
180
    return all_indexes_of_impl2
181
        <
182
            geometry::dimension<Geometry>::value
183
        >::template apply<0>(predicate);
4✔
184
}
185

186
// ----------------------------------------------------------------------------
187

188
// O(logN) version 2
189

190
template <std::size_t N>
191
struct any_index_of_impl2
192
{
193
    static const std::size_t N1 = N / 2;
194
    static const std::size_t N2 = N - N1;
195

196
    template <std::size_t Offset, typename UnaryPredicate>
197
    constexpr static inline bool apply(UnaryPredicate& predicate)
2✔
198
    {
199
        return any_index_of_impl2<N1>::template apply<Offset>(predicate)
2✔
200
            || any_index_of_impl2<N2>::template apply<Offset + N1>(predicate);
2✔
201
    }
202
};
203

204
template <>
205
struct any_index_of_impl2<3>
206
{
207
    template <std::size_t Offset, typename UnaryPredicate>
208
    constexpr static inline bool apply(UnaryPredicate& predicate)
2✔
209
    {
210
        return predicate(util::index_constant<Offset>())
2✔
211
            || predicate(util::index_constant<Offset + 1>())
1✔
212
            || predicate(util::index_constant<Offset + 2>());
3✔
213
    }
214
};
215

216
template <>
217
struct any_index_of_impl2<2>
218
{
219
    template <std::size_t Offset, typename UnaryPredicate>
220
    constexpr static inline bool apply(UnaryPredicate& predicate)
5✔
221
    {
222
        return predicate(util::index_constant<Offset>())
5✔
223
            || predicate(util::index_constant<Offset + 1>());
5✔
224
    }
225
};
226

227
template <>
228
struct any_index_of_impl2<1>
229
{
230
    template <std::size_t Offset, typename UnaryPredicate>
231
    constexpr static inline bool apply(UnaryPredicate& predicate)
2✔
232
    {
233
        return predicate(util::index_constant<Offset>());
2✔
234
    }
235
};
236

237
template <>
238
struct any_index_of_impl2<0>
239
{
240
    template <std::size_t Offset, typename UnaryPredicate>
241
    constexpr static inline bool apply(UnaryPredicate& )
12✔
242
    {
243
        return false;
12✔
244
    }
245
};
246

247
// Interface
248

249
template <std::size_t N, typename UnaryPredicate>
250
constexpr inline bool any_index_of(UnaryPredicate predicate)
6✔
251
{
252
    return any_index_of_impl2<N>::template apply<0>(predicate);
6✔
253
}
254

255
template <typename Geometry, typename UnaryPredicate>
256
constexpr inline bool any_dimension_of(UnaryPredicate predicate)
4✔
257
{
258
    return any_index_of_impl2
259
        <
260
            geometry::dimension<Geometry>::value
261
        >::template apply<0>(predicate);
4✔
262
}
263

264
template <std::size_t N, typename UnaryPredicate>
265
constexpr inline bool none_index_of(UnaryPredicate predicate)
6✔
266
{
267
    return ! any_index_of_impl2<N>::template apply<0>(predicate);
6✔
268
}
269

270
template <typename Geometry, typename UnaryPredicate>
271
constexpr inline bool none_dimension_of(UnaryPredicate predicate)
4✔
272
{
273
    return ! any_index_of_impl2
274
        <
275
            geometry::dimension<Geometry>::value
276
        >::template apply<0>(predicate);
4✔
277
}
278

279
// ----------------------------------------------------------------------------
280

281

282
} // namespace detail
283
#endif // DOXYGEN_NO_DETAIL
284

285
}} // namespace boost::geometry
286

287
#endif // BOOST_GEOMETRY_UTIL_ALGORITHM_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc