Use std::ranges::subrange instead of boost::iterator_range

This commit is contained in:
Siarhei Fedartsou 2024-07-13 18:42:15 +02:00
parent 8ae9abaa63
commit 01ab85192f
11 changed files with 27 additions and 31 deletions

View File

@ -14,7 +14,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <boost/range/iterator_range.hpp> #include <ranges>
namespace osrm::engine::guidance namespace osrm::engine::guidance
{ {
@ -220,14 +220,14 @@ inline auto RouteStep::LanesToTheLeft() const
{ {
const auto &description = intersections.front().lane_description; const auto &description = intersections.front().lane_description;
LaneID num_lanes_left = NumLanesToTheLeft(); LaneID num_lanes_left = NumLanesToTheLeft();
return boost::make_iterator_range(description.begin(), description.begin() + num_lanes_left); return std::ranges::subrange(description.begin(), description.begin() + num_lanes_left);
} }
inline auto RouteStep::LanesToTheRight() const inline auto RouteStep::LanesToTheRight() const
{ {
const auto &description = intersections.front().lane_description; const auto &description = intersections.front().lane_description;
LaneID num_lanes_right = NumLanesToTheRight(); LaneID num_lanes_right = NumLanesToTheRight();
return boost::make_iterator_range(description.end() - num_lanes_right, description.end()); return std::ranges::subrange(description.end() - num_lanes_right, description.end());
} }
} // namespace osrm::engine::guidance } // namespace osrm::engine::guidance

View File

@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <cstdint> #include <cstdint>
#include <string>
namespace osrm::extractor namespace osrm::extractor
{ {

View File

@ -26,7 +26,7 @@ template <typename RestrictionFilter> class NodeRestrictionMap
// Find all restrictions applicable to (from,via,*) turns // Find all restrictions applicable to (from,via,*) turns
auto Restrictions(NodeID from, NodeID via) const auto Restrictions(NodeID from, NodeID via) const
{ {
return getRange(from, via) | boost::adaptors::filtered(index_filter); return getRange(from, via) | std::views::filter(index_filter);
}; };
// Find all restrictions applicable to (from,via,to) turns // Find all restrictions applicable to (from,via,to) turns
@ -34,7 +34,7 @@ template <typename RestrictionFilter> class NodeRestrictionMap
{ {
const auto turnFilter = [this, to](const auto &restriction) const auto turnFilter = [this, to](const auto &restriction)
{ return index_filter(restriction) && restriction->IsTurnRestricted(to); }; { return index_filter(restriction) && restriction->IsTurnRestricted(to); };
return getRange(from, via) | boost::adaptors::filtered(turnFilter); return getRange(from, via) | std::views::filter(turnFilter);
}; };
private: private:

View File

@ -6,7 +6,7 @@
#include "util/node_based_graph.hpp" #include "util/node_based_graph.hpp"
#include "util/std_hash.hpp" #include "util/std_hash.hpp"
#include "util/typedefs.hpp" #include "util/typedefs.hpp"
#include <ranges>
#include <unordered_map> #include <unordered_map>
namespace osrm::extractor namespace osrm::extractor
@ -102,9 +102,9 @@ struct RestrictionGraph
friend restriction_graph_details::transferBuilder; friend restriction_graph_details::transferBuilder;
friend RestrictionGraph constructRestrictionGraph(const std::vector<TurnRestriction> &); friend RestrictionGraph constructRestrictionGraph(const std::vector<TurnRestriction> &);
using EdgeRange = boost::iterator_range<std::vector<RestrictionEdge>::const_iterator>; using EdgeRange = std::ranges::subrange<std::vector<RestrictionEdge>::const_iterator>;
using RestrictionRange = using RestrictionRange =
boost::iterator_range<std::vector<const TurnRestriction *>::const_iterator>; std::ranges::subrange<std::vector<const TurnRestriction *>::const_iterator>;
using EdgeKey = std::pair<NodeID, NodeID>; using EdgeKey = std::pair<NodeID, NodeID>;
// Helper functions for iterating over node restrictions and edges // Helper functions for iterating over node restrictions and edges

View File

@ -5,7 +5,7 @@
#include <boost/iterator/filter_iterator.hpp> #include <boost/iterator/filter_iterator.hpp>
#include <boost/iterator/iterator_facade.hpp> #include <boost/iterator/iterator_facade.hpp>
#include <boost/range/iterator_range.hpp> #include <ranges>
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
@ -40,7 +40,7 @@ class BisectionGraphView
// Iteration over all nodes (direct access into the node) // Iteration over all nodes (direct access into the node)
ConstNodeIterator Begin() const; ConstNodeIterator Begin() const;
ConstNodeIterator End() const; ConstNodeIterator End() const;
auto Nodes() const { return boost::make_iterator_range(begin, end); } auto Nodes() const { return std::ranges::subrange(begin, end); }
// Re-Construct the ID of a node from a reference // Re-Construct the ID of a node from a reference
NodeID GetID(const NodeT &node) const; NodeID GetID(const NodeT &node) const;

View File

@ -4,7 +4,7 @@
#include "util/msb.hpp" #include "util/msb.hpp"
#include <boost/iterator/iterator_facade.hpp> #include <boost/iterator/iterator_facade.hpp>
#include <boost/range/iterator_range.hpp> #include <ranges>
namespace osrm::util namespace osrm::util
{ {
@ -88,7 +88,7 @@ class BitIterator : public boost::iterator_facade<BitIterator<DataT>,
// Returns range over all 1 bits of value // Returns range over all 1 bits of value
template <typename T> auto makeBitRange(const T value) template <typename T> auto makeBitRange(const T value)
{ {
return boost::make_iterator_range(BitIterator<T>{value}, BitIterator<T>{}); return std::ranges::subrange(BitIterator<T>{value}, BitIterator<T>{});
} }
} // namespace osrm::util } // namespace osrm::util

View File

@ -2,7 +2,7 @@
#include "engine/routing_algorithms/routing_base_ch.hpp" #include "engine/routing_algorithms/routing_base_ch.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/range/iterator_range_core.hpp> #include <ranges>
#include <limits> #include <limits>
#include <memory> #include <memory>
@ -106,7 +106,7 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
search_space_with_buckets.end(), search_space_with_buckets.end(),
heapNode.node, heapNode.node,
NodeBucket::Compare()); NodeBucket::Compare());
for (const auto &current_bucket : boost::make_iterator_range(bucket_list)) for (const auto &current_bucket : std::ranges::subrange(bucket_list.first, bucket_list.second))
{ {
// Get target id from bucket entry // Get target id from bucket entry
const auto column_index = current_bucket.column_index; const auto column_index = current_bucket.column_index;

View File

@ -2,7 +2,7 @@
#include "engine/routing_algorithms/routing_base_mld.hpp" #include "engine/routing_algorithms/routing_base_mld.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/range/iterator_range_core.hpp> #include <ranges>
#include <limits> #include <limits>
#include <memory> #include <memory>
@ -428,7 +428,7 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
search_space_with_buckets.end(), search_space_with_buckets.end(),
heapNode.node, heapNode.node,
NodeBucket::Compare()); NodeBucket::Compare());
for (const auto &current_bucket : boost::make_iterator_range(bucket_list)) for (const auto &current_bucket : std::ranges::subrange(bucket_list.first, bucket_list.second))
{ {
// Get target id from bucket entry // Get target id from bucket entry
const auto column_idx = current_bucket.column_index; const auto column_idx = current_bucket.column_index;

View File

@ -968,11 +968,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
buffer->continuous_data.push_back(edge_with_data); buffer->continuous_data.push_back(edge_with_data);
// get conditional restrictions that apply to this turn // get conditional restrictions that apply to this turn
const auto &restrictions = auto restrictions = conditional_node_restriction_map.Restrictions(
conditional_node_restriction_map.Restrictions( incoming_edge.node, outgoing_edge.node, outgoing_edge_target);
incoming_edge.node,
outgoing_edge.node,
outgoing_edge_target);
for (const auto &restriction : restrictions) for (const auto &restriction : restrictions)
{ {
buffer->conditionals.push_back( buffer->conditionals.push_back(

View File

@ -424,13 +424,11 @@ double findEdgeLength(const IntersectionEdgeGeometries &geometries, const EdgeID
} }
template <typename RestrictionsRange> template <typename RestrictionsRange>
bool isTurnRestricted(const RestrictionsRange &restrictions, const NodeID to) bool isTurnRestricted(RestrictionsRange restrictions, const NodeID to)
{ {
// Check if any of the restrictions would prevent a turn to 'to' // Check if any of the restrictions would prevent a turn to 'to'
return std::any_of(restrictions.begin(), return std::ranges::any_of(
restrictions.end(), restrictions, [&to](const auto &restriction) { return restriction->IsTurnRestricted(to); });
[&to](const auto &restriction)
{ return restriction->IsTurnRestricted(to); });
} }
bool isTurnAllowed(const util::NodeBasedDynamicGraph &graph, bool isTurnAllowed(const util::NodeBasedDynamicGraph &graph,

View File

@ -276,7 +276,7 @@ RestrictionGraph constructRestrictionGraph(const std::vector<TurnRestriction> &t
RestrictionGraph::RestrictionRange RestrictionGraph::GetRestrictions(RestrictionID id) const RestrictionGraph::RestrictionRange RestrictionGraph::GetRestrictions(RestrictionID id) const
{ {
const auto &node = nodes[id]; const auto &node = nodes[id];
return boost::make_iterator_range(restrictions.begin() + node.restrictions_begin_idx, return std::ranges::subrange(restrictions.begin() + node.restrictions_begin_idx,
restrictions.begin() + node.restrictions_begin_idx + restrictions.begin() + node.restrictions_begin_idx +
node.num_restrictions); node.num_restrictions);
} }
@ -284,7 +284,7 @@ RestrictionGraph::RestrictionRange RestrictionGraph::GetRestrictions(Restriction
RestrictionGraph::EdgeRange RestrictionGraph::GetEdges(RestrictionID id) const RestrictionGraph::EdgeRange RestrictionGraph::GetEdges(RestrictionID id) const
{ {
const auto &node = nodes[id]; const auto &node = nodes[id];
return boost::make_iterator_range(edges.begin() + node.edges_begin_idx, return std::ranges::subrange(edges.begin() + node.edges_begin_idx,
edges.begin() + node.edges_begin_idx + node.num_edges); edges.begin() + node.edges_begin_idx + node.num_edges);
} }