Skip to content

Commit 592024e

Browse files
authored
Merge pull request #1168 from awulkiew/feature/constexpr
Add if constexpr macro and replace condition macro.
2 parents b6a7349 + 9684581 commit 592024e

File tree

8 files changed

+99
-54
lines changed

8 files changed

+99
-54
lines changed

include/boost/geometry/algorithms/densify.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Boost.Geometry
22

3-
// Copyright (c) 2017-2021, Oracle and/or its affiliates.
3+
// Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
44

5+
// Copyright (c) 2017-2021, Oracle and/or its affiliates.
56
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
67

78
// Licensed under the Boost Software License version 1.0.
@@ -33,7 +34,7 @@
3334
#include <boost/geometry/strategies/densify/geographic.hpp>
3435
#include <boost/geometry/strategies/densify/spherical.hpp>
3536
#include <boost/geometry/strategies/detail.hpp>
36-
#include <boost/geometry/util/condition.hpp>
37+
#include <boost/geometry/util/constexpr.hpp>
3738
#include <boost/geometry/util/range.hpp>
3839

3940

@@ -102,7 +103,7 @@ struct densify_range
102103
strategy.apply(p0, p1, policy, len);
103104
}
104105

105-
if (BOOST_GEOMETRY_CONDITION(AppendLastPoint))
106+
if BOOST_GEOMETRY_CONSTEXPR (AppendLastPoint)
106107
{
107108
convert_and_push_back(rng_out, *prev); // back(rng)
108109
}
@@ -130,7 +131,7 @@ struct densify_ring
130131

131132
strategy.apply(p0, p1, policy, len);
132133

133-
if (BOOST_GEOMETRY_CONDITION(IsClosed2))
134+
if BOOST_GEOMETRY_CONSTEXPR (IsClosed2)
134135
{
135136
convert_and_push_back(ring_out, p1);
136137
}

include/boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Boost.Geometry (aka GGL, Generic Geometry Library)
22

33
// Copyright (c) 2012-2020 Barend Gehrels, Amsterdam, the Netherlands.
4-
// Copyright (c) 2022 Adam Wulkiewicz, Lodz, Poland.
4+
// Copyright (c) 2022-2023 Adam Wulkiewicz, Lodz, Poland.
55

66
// This file was modified by Oracle on 2017-2022.
77
// Modifications copyright (c) 2017-2022 Oracle and/or its affiliates.
@@ -44,7 +44,7 @@
4444
#include <boost/geometry/strategies/buffer.hpp>
4545
#include <boost/geometry/strategies/side.hpp>
4646

47-
#include <boost/geometry/util/condition.hpp>
47+
#include <boost/geometry/util/constexpr.hpp>
4848
#include <boost/geometry/util/math.hpp>
4949
#include <boost/geometry/util/type_traits.hpp>
5050

@@ -942,17 +942,17 @@ inline void buffer_inserter(GeometryInput const& geometry_input, OutputIterator
942942
{
943943
boost::ignore_unused(visit_pieces_policy);
944944

945-
typedef detail::buffer::buffered_piece_collection
946-
<
947-
typename geometry::ring_type<GeometryOutput>::type,
948-
Strategies,
949-
DistanceStrategy,
950-
RobustPolicy
951-
> collection_type;
945+
using collection_type = detail::buffer::buffered_piece_collection
946+
<
947+
typename geometry::ring_type<GeometryOutput>::type,
948+
Strategies,
949+
DistanceStrategy,
950+
RobustPolicy
951+
>;
952952
collection_type collection(strategies, distance_strategy, robust_policy);
953953
collection_type const& const_collection = collection;
954954

955-
bool const areal = util::is_areal<GeometryInput>::value;
955+
static constexpr bool areal = util::is_areal<GeometryInput>::value;
956956

957957
dispatch::buffer_inserter
958958
<
@@ -969,7 +969,7 @@ inline void buffer_inserter(GeometryInput const& geometry_input, OutputIterator
969969
robust_policy, strategies);
970970

971971
collection.get_turns();
972-
if (BOOST_GEOMETRY_CONDITION(areal))
972+
if BOOST_GEOMETRY_CONSTEXPR (areal)
973973
{
974974
collection.check_turn_in_original();
975975
}
@@ -989,7 +989,7 @@ inline void buffer_inserter(GeometryInput const& geometry_input, OutputIterator
989989
// phase 1: turns (after enrichment/clustering)
990990
visit_pieces_policy.apply(const_collection, 1);
991991

992-
if (BOOST_GEOMETRY_CONDITION(areal))
992+
if BOOST_GEOMETRY_CONSTEXPR (areal)
993993
{
994994
collection.deflate_check_turns();
995995
}
@@ -1001,8 +1001,7 @@ inline void buffer_inserter(GeometryInput const& geometry_input, OutputIterator
10011001
// - the output is counter clockwise
10021002
// and avoid reversing twice
10031003
bool reverse = distance_strategy.negative() && areal;
1004-
if (BOOST_GEOMETRY_CONDITION(
1005-
geometry::point_order<GeometryOutput>::value == counterclockwise))
1004+
if BOOST_GEOMETRY_CONSTEXPR (geometry::point_order<GeometryOutput>::value == counterclockwise)
10061005
{
10071006
reverse = ! reverse;
10081007
}
@@ -1011,9 +1010,12 @@ inline void buffer_inserter(GeometryInput const& geometry_input, OutputIterator
10111010
collection.reverse();
10121011
}
10131012

1014-
if (BOOST_GEOMETRY_CONDITION(distance_strategy.negative() && areal))
1013+
if BOOST_GEOMETRY_CONSTEXPR (areal)
10151014
{
1016-
collection.discard_nonintersecting_deflated_rings();
1015+
if (distance_strategy.negative())
1016+
{
1017+
collection.discard_nonintersecting_deflated_rings();
1018+
}
10171019
}
10181020

10191021
collection.template assign<GeometryOutput>(out);

include/boost/geometry/algorithms/detail/is_valid/linear.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Boost.Geometry (aka GGL, Generic Geometry Library)
22

3-
// Copyright (c) 2014-2021, Oracle and/or its affiliates.
3+
// Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
44

5+
// Copyright (c) 2014-2021, Oracle and/or its affiliates.
56
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
67
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
78
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
@@ -31,7 +32,7 @@
3132
#include <boost/geometry/core/point_type.hpp>
3233
#include <boost/geometry/core/tags.hpp>
3334

34-
#include <boost/geometry/util/condition.hpp>
35+
#include <boost/geometry/util/constexpr.hpp>
3536

3637

3738
namespace boost { namespace geometry
@@ -158,10 +159,12 @@ class is_valid
158159
VisitPolicy& visitor,
159160
Strategy const& strategy)
160161
{
161-
if (BOOST_GEOMETRY_CONDITION(
162-
AllowEmptyMultiGeometries && boost::empty(multilinestring)))
162+
if BOOST_GEOMETRY_CONSTEXPR (AllowEmptyMultiGeometries)
163163
{
164-
return visitor.template apply<no_failure>();
164+
if (boost::empty(multilinestring))
165+
{
166+
return visitor.template apply<no_failure>();
167+
}
165168
}
166169

167170
using per_ls = per_linestring<VisitPolicy, Strategy>;

include/boost/geometry/algorithms/detail/is_valid/multipolygon.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Boost.Geometry (aka GGL, Generic Geometry Library)
22

3-
// Copyright (c) 2014-2021, Oracle and/or its affiliates.
3+
// Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
44

5+
// Copyright (c) 2014-2021, Oracle and/or its affiliates.
56
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
67
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
78
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
@@ -27,7 +28,7 @@
2728
#include <boost/geometry/core/ring_type.hpp>
2829
#include <boost/geometry/core/tags.hpp>
2930

30-
#include <boost/geometry/util/condition.hpp>
31+
#include <boost/geometry/util/constexpr.hpp>
3132
#include <boost/geometry/util/range.hpp>
3233

3334
#include <boost/geometry/geometries/box.hpp>
@@ -282,10 +283,12 @@ class is_valid_multipolygon
282283
{
283284
using debug_phase = debug_validity_phase<MultiPolygon>;
284285

285-
if (BOOST_GEOMETRY_CONDITION(AllowEmptyMultiGeometries)
286-
&& boost::empty(multipolygon))
286+
if BOOST_GEOMETRY_CONSTEXPR (AllowEmptyMultiGeometries)
287287
{
288-
return visitor.template apply<no_failure>();
288+
if (boost::empty(multipolygon))
289+
{
290+
return visitor.template apply<no_failure>();
291+
}
289292
}
290293

291294
// check validity of all polygons ring

include/boost/geometry/algorithms/detail/is_valid/polygon.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Boost.Geometry (aka GGL, Generic Geometry Library)
22

3-
// Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
3+
// Copyright (c) 2017-2023 Adam Wulkiewicz, Lodz, Poland.
44

55
// Copyright (c) 2014-2021, Oracle and/or its affiliates.
6-
76
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
87
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
98
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
@@ -35,7 +34,7 @@
3534
#include <boost/geometry/core/ring_type.hpp>
3635
#include <boost/geometry/core/tags.hpp>
3736

38-
#include <boost/geometry/util/condition.hpp>
37+
#include <boost/geometry/util/constexpr.hpp>
3938
#include <boost/geometry/util/range.hpp>
4039
#include <boost/geometry/util/sequence.hpp>
4140

@@ -447,7 +446,7 @@ class is_valid_polygon
447446
return false;
448447
}
449448

450-
if (BOOST_GEOMETRY_CONDITION(CheckRingValidityOnly))
449+
if BOOST_GEOMETRY_CONSTEXPR (CheckRingValidityOnly)
451450
{
452451
return true;
453452
}

include/boost/geometry/io/wkt/write.hpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include <boost/geometry/strategies/io/geographic.hpp>
5151
#include <boost/geometry/strategies/io/spherical.hpp>
5252

53-
#include <boost/geometry/util/condition.hpp>
53+
#include <boost/geometry/util/constexpr.hpp>
5454
#include <boost/geometry/util/type_traits.hpp>
5555

5656

@@ -129,7 +129,7 @@ struct wkt_range
129129

130130
if (boost::size(range) > 0)
131131
{
132-
if (WriteDoubleBrackets)
132+
if BOOST_GEOMETRY_CONSTEXPR (WriteDoubleBrackets)
133133
{
134134
os << "(";
135135
}
@@ -143,15 +143,17 @@ struct wkt_range
143143
}
144144

145145
// optionally, close range to ring by repeating the first point
146-
if (BOOST_GEOMETRY_CONDITION(ForceClosurePossible)
147-
&& force_closure
148-
&& boost::size(range) > 1
149-
&& wkt_range::disjoint(*begin, *(end - 1)))
146+
if BOOST_GEOMETRY_CONSTEXPR (ForceClosurePossible)
150147
{
151-
os << ",";
152-
stream_type::apply(os, *begin);
148+
if (force_closure
149+
&& boost::size(range) > 1
150+
&& wkt_range::disjoint(*begin, *(end - 1)))
151+
{
152+
os << ",";
153+
stream_type::apply(os, *begin);
154+
}
153155
}
154-
if (WriteDoubleBrackets)
156+
if BOOST_GEOMETRY_CONSTEXPR (WriteDoubleBrackets)
155157
{
156158
os << ")";
157159
}

include/boost/geometry/policies/is_valid/failing_reason_policy.hpp

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Boost.Geometry (aka GGL, Generic Geometry Library)
22

3-
// Copyright (c) 2015, Oracle and/or its affiliates.
3+
// Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
44

5+
// Copyright (c) 2015, Oracle and/or its affiliates.
56
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
67
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
78

@@ -14,7 +15,7 @@
1415
#include <sstream>
1516

1617
#include <boost/geometry/io/dsv/write.hpp>
17-
#include <boost/geometry/util/condition.hpp>
18+
#include <boost/geometry/util/constexpr.hpp>
1819
#include <boost/geometry/util/range.hpp>
1920
#include <boost/geometry/algorithms/validity_failure_type.hpp>
2021
#include <boost/geometry/algorithms/detail/overlay/debug_turn_info.hpp>
@@ -69,10 +70,12 @@ class failing_reason_policy
6970
static inline
7071
validity_failure_type transform_failure_type(validity_failure_type failure)
7172
{
72-
if (BOOST_GEOMETRY_CONDITION(
73-
AllowDuplicates && failure == failure_duplicate_points))
73+
if BOOST_GEOMETRY_CONSTEXPR (AllowDuplicates)
7474
{
75-
return no_failure;
75+
if (failure == failure_duplicate_points)
76+
{
77+
return no_failure;
78+
}
7679
}
7780
return failure;
7881
}
@@ -81,10 +84,12 @@ class failing_reason_policy
8184
validity_failure_type transform_failure_type(validity_failure_type failure,
8285
bool is_linear)
8386
{
84-
if (BOOST_GEOMETRY_CONDITION(
85-
is_linear && AllowSpikes && failure == failure_spikes))
87+
if BOOST_GEOMETRY_CONSTEXPR (AllowSpikes)
8688
{
87-
return no_failure;
89+
if (is_linear && failure == failure_spikes)
90+
{
91+
return no_failure;
92+
}
8893
}
8994
return transform_failure_type(failure);
9095
}
@@ -123,9 +128,12 @@ class failing_reason_policy
123128
bool is_linear,
124129
SpikePoint const& spike_point)
125130
{
126-
if (BOOST_GEOMETRY_CONDITION(is_linear && AllowSpikes))
131+
if BOOST_GEOMETRY_CONSTEXPR (AllowSpikes)
127132
{
128-
return;
133+
if (is_linear)
134+
{
135+
return;
136+
}
129137
}
130138

131139
oss << ". A spike point was found with apex at "
@@ -173,7 +181,7 @@ class failing_reason_policy
173181
static inline void apply(std::ostringstream& oss,
174182
Point const& point)
175183
{
176-
if (BOOST_GEOMETRY_CONDITION(AllowDuplicates))
184+
if BOOST_GEOMETRY_CONSTEXPR (AllowDuplicates)
177185
{
178186
return;
179187
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Boost.Geometry
2+
3+
// Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
4+
5+
// Use, modification and distribution is subject to the Boost Software License,
6+
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7+
// http://www.boost.org/LICENSE_1_0.txt)
8+
9+
#ifndef BOOST_GEOMETRY_UTIL_CONSTEXPR_HPP
10+
#define BOOST_GEOMETRY_UTIL_CONSTEXPR_HPP
11+
12+
13+
#include <boost/geometry/util/condition.hpp>
14+
15+
16+
#ifndef BOOST_NO_CXX17_IF_CONSTEXPR
17+
18+
#define BOOST_GEOMETRY_CONSTEXPR(CONDITION) constexpr (CONDITION)
19+
20+
#else
21+
22+
#define BOOST_GEOMETRY_CONSTEXPR(CONDITION) (BOOST_GEOMETRY_CONDITION(CONDITION))
23+
24+
#endif
25+
26+
27+
#endif // BOOST_GEOMETRY_UTIL_CONSTEXPR_HPP

0 commit comments

Comments
 (0)