Skip to content

Commit

Permalink
Refactor some boost code to std code (#7123)
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisOSRM authored Feb 28, 2025
1 parent 88a17c1 commit 6b801c1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
52 changes: 32 additions & 20 deletions include/engine/api/base_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
#include "engine/hint.hpp"
#include "util/coordinate_calculation.hpp"

#include <boost/algorithm/string/join.hpp>
#include <boost/assert.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/algorithm/transform.hpp>

#include <boost/range/adaptor/filtered.hpp>
#include <memory>
#include <ranges>
#include <sstream>
#include <vector>

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

boost::range::transform(waypoint_candidates,
waypoints.values.begin(),
[this](const PhantomNodeCandidates &candidates)
{ return MakeWaypoint(candidates); });
std::ranges::transform(waypoint_candidates,
waypoints.values.begin(),
[this](const PhantomNodeCandidates &candidates)
{ return MakeWaypoint(candidates); });
return waypoints;
}

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

// At an intersection we may have multiple phantom node candidates.
// Combine them to represent the waypoint name.
std::string waypoint_name = boost::algorithm::join(
candidates | boost::adaptors::transformed(toName) | boost::adaptors::filtered(noEmpty),
INTERSECTION_DELIMITER);
std::string waypoint_name =
join(candidates | std::views::transform(toName) | std::views::filter(noEmpty),
INTERSECTION_DELIMITER);

const auto &snapped_location = candidatesSnappedLocation(candidates);
const auto &input_location = candidatesInputLocation(candidates);
Expand Down Expand Up @@ -109,8 +104,6 @@ class BaseAPI
return builder->CreateVector(waypoints);
}

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

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

flatbuffers::Offset<flatbuffers::String> hint_string;
Expand Down Expand Up @@ -163,6 +156,25 @@ class BaseAPI

const datafacade::BaseDataFacade &facade;
const BaseParameters &parameters;

private:
// Helper join function using std
template <typename Range> std::string join(Range &&range, const std::string &delimiter) const
{
std::ostringstream result;
auto it = std::begin(range);
const auto end = std::end(range);

if (it != end)
{
result << *it++;
while (it != end)
{
result << delimiter << *it++;
}
}
return result.str();
}
};

} // namespace osrm::engine::api
Expand Down
2 changes: 1 addition & 1 deletion include/engine/guidance/collapsing_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ inline bool areSameSide(const RouteStep &lhs, const RouteStep &rhs)
step.maneuver.waypoint_type == WaypointType::None;
};

boost::remove_erase_if(steps, not_is_valid);
steps.erase(std::remove_if(std::begin(steps), std::end(steps), not_is_valid), std::end(steps));

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

0 comments on commit 6b801c1

Please sign in to comment.