Skip to content

Commit 6b801c1

Browse files
authored
Refactor some boost code to std code (#7123)
1 parent 88a17c1 commit 6b801c1

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

include/engine/api/base_api.hpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99
#include "engine/hint.hpp"
1010
#include "util/coordinate_calculation.hpp"
1111

12-
#include <boost/algorithm/string/join.hpp>
13-
#include <boost/assert.hpp>
14-
#include <boost/range/adaptor/transformed.hpp>
15-
#include <boost/range/algorithm/transform.hpp>
16-
17-
#include <boost/range/adaptor/filtered.hpp>
1812
#include <memory>
13+
#include <ranges>
14+
#include <sstream>
1915
#include <vector>
2016

2117
namespace osrm::engine::api
@@ -40,15 +36,14 @@ class BaseAPI
4036
util::json::Array waypoints;
4137
waypoints.values.resize(parameters.coordinates.size());
4238

43-
boost::range::transform(waypoint_candidates,
44-
waypoints.values.begin(),
45-
[this](const PhantomNodeCandidates &candidates)
46-
{ return MakeWaypoint(candidates); });
39+
std::ranges::transform(waypoint_candidates,
40+
waypoints.values.begin(),
41+
[this](const PhantomNodeCandidates &candidates)
42+
{ return MakeWaypoint(candidates); });
4743
return waypoints;
4844
}
4945

50-
// FIXME: gcc 4.9 does not like MakeWaypoints to be protected
51-
// protected:
46+
protected:
5247
util::json::Object MakeWaypoint(const PhantomNodeCandidates &candidates) const
5348
{
5449
// TODO: check forward/reverse
@@ -60,9 +55,9 @@ class BaseAPI
6055

6156
// At an intersection we may have multiple phantom node candidates.
6257
// Combine them to represent the waypoint name.
63-
std::string waypoint_name = boost::algorithm::join(
64-
candidates | boost::adaptors::transformed(toName) | boost::adaptors::filtered(noEmpty),
65-
INTERSECTION_DELIMITER);
58+
std::string waypoint_name =
59+
join(candidates | std::views::transform(toName) | std::views::filter(noEmpty),
60+
INTERSECTION_DELIMITER);
6661

6762
const auto &snapped_location = candidatesSnappedLocation(candidates);
6863
const auto &input_location = candidatesInputLocation(candidates);
@@ -109,8 +104,6 @@ class BaseAPI
109104
return builder->CreateVector(waypoints);
110105
}
111106

112-
// FIXME: gcc 4.9 does not like MakeWaypoints to be protected
113-
// protected:
114107
std::unique_ptr<fbresult::WaypointBuilder>
115108
MakeWaypoint(flatbuffers::FlatBufferBuilder *builder,
116109
const PhantomNodeCandidates &candidates) const
@@ -130,9 +123,9 @@ class BaseAPI
130123

131124
// At an intersection we may have multiple phantom node candidates.
132125
// Combine them to represent the waypoint name.
133-
std::string waypoint_name = boost::algorithm::join(
134-
candidates | boost::adaptors::transformed(toName) | boost::adaptors::filtered(noEmpty),
135-
INTERSECTION_DELIMITER);
126+
std::string waypoint_name =
127+
join(candidates | std::views::transform(toName) | std::views::filter(noEmpty),
128+
INTERSECTION_DELIMITER);
136129
auto name_string = builder->CreateString(waypoint_name);
137130

138131
flatbuffers::Offset<flatbuffers::String> hint_string;
@@ -163,6 +156,25 @@ class BaseAPI
163156

164157
const datafacade::BaseDataFacade &facade;
165158
const BaseParameters &parameters;
159+
160+
private:
161+
// Helper join function using std
162+
template <typename Range> std::string join(Range &&range, const std::string &delimiter) const
163+
{
164+
std::ostringstream result;
165+
auto it = std::begin(range);
166+
const auto end = std::end(range);
167+
168+
if (it != end)
169+
{
170+
result << *it++;
171+
while (it != end)
172+
{
173+
result << delimiter << *it++;
174+
}
175+
}
176+
return result.str();
177+
}
166178
};
167179

168180
} // namespace osrm::engine::api

include/engine/guidance/collapsing_utility.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ inline bool areSameSide(const RouteStep &lhs, const RouteStep &rhs)
179179
step.maneuver.waypoint_type == WaypointType::None;
180180
};
181181

182-
boost::remove_erase_if(steps, not_is_valid);
182+
steps.erase(std::remove_if(std::begin(steps), std::end(steps), not_is_valid), std::end(steps));
183183

184184
// the steps should still include depart and arrive at least
185185
BOOST_ASSERT(steps.size() >= 2);

0 commit comments

Comments
 (0)