Skip to content

Commit

Permalink
Get rid of boost::optional leftovers (#6977)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiarheiFedartsou authored Jul 2, 2024
1 parent d0ed29a commit 57b792c
Show file tree
Hide file tree
Showing 49 changed files with 232 additions and 218 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Checks: >
-bugprone-incorrect-enable-if,
-bugprone-switch-missing-default-case,
-bugprone-empty-catch,
-bugprone-unchecked-optional-access,
-clang-analyzer-*,
-clang-diagnostic-deprecated-declarations,
-clang-diagnostic-constant-conversion,
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- NodeJS:
- CHANGED: Use node-api instead of NAN. [#6452](/~https://github.com/Project-OSRM/osrm-backend/pull/6452)
- Misc:
- CHANGED: Get rid of boost::optional leftovers. [#6977](/~https://github.com/Project-OSRM/osrm-backend/pull/6977)
- CHANGED: Use Link Time Optimisation whenever possible. [#6967](/~https://github.com/Project-OSRM/osrm-backend/pull/6967)
- CHANGED: Use struct instead of tuple to define UnpackedPath. [#6974](/~https://github.com/Project-OSRM/osrm-backend/pull/6974)
- CHANGED: Micro performance optimisation in map matching. [#6976](/~https://github.com/Project-OSRM/osrm-backend/pull/6976)
Expand Down
22 changes: 11 additions & 11 deletions include/engine/api/base_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "engine/hint.hpp"
#include "util/coordinate.hpp"

#include <boost/optional.hpp>
#include <optional>

#include <algorithm>
#include <vector>
Expand Down Expand Up @@ -74,12 +74,12 @@ struct BaseParameters
};

std::vector<util::Coordinate> coordinates;
std::vector<boost::optional<Hint>> hints;
std::vector<boost::optional<double>> radiuses;
std::vector<boost::optional<Bearing>> bearings;
std::vector<boost::optional<Approach>> approaches;
std::vector<std::optional<Hint>> hints;
std::vector<std::optional<double>> radiuses;
std::vector<std::optional<Bearing>> bearings;
std::vector<std::optional<Approach>> approaches;
std::vector<std::string> exclude;
boost::optional<OutputFormatType> format = OutputFormatType::JSON;
std::optional<OutputFormatType> format = OutputFormatType::JSON;

// Adds hints to response which can be included in subsequent requests, see `hints` above.
bool generate_hints = true;
Expand All @@ -90,10 +90,10 @@ struct BaseParameters
SnappingType snapping = SnappingType::Default;

BaseParameters(std::vector<util::Coordinate> coordinates_ = {},
std::vector<boost::optional<Hint>> hints_ = {},
std::vector<boost::optional<double>> radiuses_ = {},
std::vector<boost::optional<Bearing>> bearings_ = {},
std::vector<boost::optional<Approach>> approaches_ = {},
std::vector<std::optional<Hint>> hints_ = {},
std::vector<std::optional<double>> radiuses_ = {},
std::vector<std::optional<Bearing>> bearings_ = {},
std::vector<std::optional<Approach>> approaches_ = {},
bool generate_hints_ = true,
std::vector<std::string> exclude = {},
const SnappingType snapping_ = SnappingType::Default)
Expand All @@ -112,7 +112,7 @@ struct BaseParameters
(approaches.empty() || approaches.size() == coordinates.size()) &&
std::all_of(bearings.begin(),
bearings.end(),
[](const boost::optional<Bearing> &bearing_and_range)
[](const std::optional<Bearing> &bearing_and_range)
{
if (bearing_and_range)
{
Expand Down
4 changes: 2 additions & 2 deletions include/engine/api/json_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "util/coordinate.hpp"
#include "util/json_container.hpp"

#include <boost/optional.hpp>
#include <optional>

#include <algorithm>
#include <iterator>
Expand Down Expand Up @@ -90,7 +90,7 @@ util::json::Object makeRouteStep(guidance::RouteStep step, util::json::Value geo

util::json::Object makeRoute(const guidance::Route &route,
util::json::Array legs,
boost::optional<util::json::Value> geometry,
std::optional<util::json::Value> geometry,
const char *weight_name);

// Creates a Waypoint without Hint, see the Hint overload below
Expand Down
2 changes: 1 addition & 1 deletion include/engine/api/nearest_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class NearestAPI final : public BaseAPI
flatbuffers::FlatBufferBuilder &fb_result) const
{
auto data_timestamp = facade.GetTimestamp();
boost::optional<flatbuffers::Offset<flatbuffers::String>> data_version_string = boost::none;
std::optional<flatbuffers::Offset<flatbuffers::String>> data_version_string = std::nullopt;
if (!data_timestamp.empty())
{
data_version_string = fb_result.CreateString(data_timestamp);
Expand Down
13 changes: 6 additions & 7 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ class RouteAPI : public BaseAPI
return builder.CreateVectorOfStructs(coordinates);
}

boost::optional<util::json::Value>
MakeGeometry(boost::optional<std::vector<Coordinate>> &&annotations) const
std::optional<util::json::Value>
MakeGeometry(std::optional<std::vector<Coordinate>> &&annotations) const
{
boost::optional<util::json::Value> json_geometry;
std::optional<util::json::Value> json_geometry;
if (annotations)
{
auto begin = annotations->begin();
Expand Down Expand Up @@ -720,8 +720,7 @@ class RouteAPI : public BaseAPI
std::vector<guidance::LegGeometry> &leg_geometries = legs_info.second;

auto route = guidance::assembleRoute(legs);
boost::optional<util::json::Value> json_overview =
MakeGeometry(MakeOverview(leg_geometries));
std::optional<util::json::Value> json_overview = MakeGeometry(MakeOverview(leg_geometries));

std::vector<util::json::Value> step_geometries;
const auto total_step_count =
Expand Down Expand Up @@ -997,10 +996,10 @@ class RouteAPI : public BaseAPI
return result;
}

boost::optional<std::vector<Coordinate>>
std::optional<std::vector<Coordinate>>
MakeOverview(const std::vector<guidance::LegGeometry> &leg_geometries) const
{
boost::optional<std::vector<Coordinate>> overview;
std::optional<std::vector<Coordinate>> overview;
if (parameters.overview != RouteParameters::OverviewType::False)
{
const auto use_simplification =
Expand Down
12 changes: 6 additions & 6 deletions include/engine/api/route_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct RouteParameters : public BaseParameters
const bool alternatives_,
const GeometriesType geometries_,
const OverviewType overview_,
const boost::optional<bool> continue_straight_,
const std::optional<bool> continue_straight_,
Args &&...args_)
// Once we perfectly-forward `args` (see #2990) this constructor can delegate to the one
// below.
Expand All @@ -100,7 +100,7 @@ struct RouteParameters : public BaseParameters
const bool annotations_,
const GeometriesType geometries_,
const OverviewType overview_,
const boost::optional<bool> continue_straight_,
const std::optional<bool> continue_straight_,
Args &&...args_)
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_},
Expand All @@ -118,7 +118,7 @@ struct RouteParameters : public BaseParameters
const AnnotationsType annotations_,
const GeometriesType geometries_,
const OverviewType overview_,
const boost::optional<bool> continue_straight_,
const std::optional<bool> continue_straight_,
Args &&...args_)
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
number_of_alternatives{alternatives_ ? 1u : 0u},
Expand All @@ -135,7 +135,7 @@ struct RouteParameters : public BaseParameters
const bool annotations_,
const GeometriesType geometries_,
const OverviewType overview_,
const boost::optional<bool> continue_straight_,
const std::optional<bool> continue_straight_,
std::vector<std::size_t> waypoints_,
const Args &&...args_)
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
Expand All @@ -153,7 +153,7 @@ struct RouteParameters : public BaseParameters
const AnnotationsType annotations_,
const GeometriesType geometries_,
const OverviewType overview_,
const boost::optional<bool> continue_straight_,
const std::optional<bool> continue_straight_,
std::vector<std::size_t> waypoints_,
Args &&...args_)
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
Expand All @@ -172,7 +172,7 @@ struct RouteParameters : public BaseParameters
AnnotationsType annotations_type = AnnotationsType::None;
GeometriesType geometries = GeometriesType::Polyline;
OverviewType overview = OverviewType::Simplified;
boost::optional<bool> continue_straight;
std::optional<bool> continue_straight;
std::vector<std::size_t> waypoints;

bool IsValid() const
Expand Down
2 changes: 1 addition & 1 deletion include/engine/api/trip_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "engine/api/route_parameters.hpp"

#include <boost/optional.hpp>
#include <optional>
#include <vector>

namespace osrm::engine::api
Expand Down
12 changes: 6 additions & 6 deletions include/engine/datafacade/contiguous_internalmem_datafacade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const double max_distance,
const boost::optional<Bearing> bearing,
const std::optional<Bearing> bearing,
const Approach approach,
const bool use_all_edges) const override final
{
Expand All @@ -382,20 +382,20 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::Coordinate input_coordinate,
const size_t max_results,
const boost::optional<double> max_distance,
const boost::optional<Bearing> bearing,
const std::optional<double> max_distance,
const std::optional<Bearing> bearing,
const Approach approach) const override final
{
BOOST_ASSERT(m_geospatial_query.get());

return m_geospatial_query->NearestPhantomNodes(
input_coordinate, approach, max_results, max_distance, bearing, boost::none);
input_coordinate, approach, max_results, max_distance, bearing, std::nullopt);
}

PhantomCandidateAlternatives
NearestCandidatesWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const boost::optional<double> max_distance,
const boost::optional<Bearing> bearing,
const std::optional<double> max_distance,
const std::optional<Bearing> bearing,
const Approach approach,
const bool use_all_edges) const override final
{
Expand Down
11 changes: 6 additions & 5 deletions include/engine/datafacade/datafacade_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <cstddef>

#include <engine/bearing.hpp>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
Expand Down Expand Up @@ -126,21 +127,21 @@ class BaseDataFacade
virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const double max_distance,
const boost::optional<Bearing> bearing,
const std::optional<Bearing> bearing,
const Approach approach,
const bool use_all_edges) const = 0;

virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::Coordinate input_coordinate,
const size_t max_results,
const boost::optional<double> max_distance,
const boost::optional<Bearing> bearing,
const std::optional<double> max_distance,
const std::optional<Bearing> bearing,
const Approach approach) const = 0;

virtual PhantomCandidateAlternatives
NearestCandidatesWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const boost::optional<double> max_distance,
const boost::optional<Bearing> bearing,
const std::optional<double> max_distance,
const std::optional<Bearing> bearing,
const Approach approach,
const bool use_all_edges) const = 0;

Expand Down
2 changes: 1 addition & 1 deletion include/engine/engine_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct EngineConfig final
int max_locations_map_matching = -1;
double max_radius_map_matching = -1.0;
int max_results_nearest = -1;
boost::optional<double> default_radius = -1.0;
double default_radius = -1.0;
int max_alternatives = 3; // set an arbitrary upper bound; can be adjusted by user
bool use_shared_memory = true;
std::filesystem::path memory_file;
Expand Down
18 changes: 9 additions & 9 deletions include/engine/geospatial_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "osrm/coordinate.hpp"

#include <boost/optional.hpp>
#include <optional>

#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -53,8 +53,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
NearestPhantomNodes(const util::Coordinate input_coordinate,
const Approach approach,
const double max_distance,
const boost::optional<Bearing> bearing_with_range,
const boost::optional<bool> use_all_edges) const
const std::optional<Bearing> bearing_with_range,
const std::optional<bool> use_all_edges) const
{
auto results = rtree.SearchInRange(
input_coordinate,
Expand Down Expand Up @@ -85,9 +85,9 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
NearestPhantomNodes(const util::Coordinate input_coordinate,
const Approach approach,
const size_t max_results,
const boost::optional<double> max_distance,
const boost::optional<Bearing> bearing_with_range,
const boost::optional<bool> use_all_edges) const
const std::optional<double> max_distance,
const std::optional<Bearing> bearing_with_range,
const std::optional<bool> use_all_edges) const
{
auto results = rtree.Nearest(
input_coordinate,
Expand Down Expand Up @@ -121,9 +121,9 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
PhantomCandidateAlternatives NearestCandidatesWithAlternativeFromBigComponent(
const util::Coordinate input_coordinate,
const Approach approach,
const boost::optional<double> max_distance,
const boost::optional<Bearing> bearing_with_range,
const boost::optional<bool> use_all_edges) const
const std::optional<double> max_distance,
const std::optional<Bearing> bearing_with_range,
const std::optional<bool> use_all_edges) const
{
bool has_nearest = false;
bool has_big_component = false;
Expand Down
2 changes: 1 addition & 1 deletion include/engine/guidance/assemble_steps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include "util/guidance/turn_lanes.hpp"
#include "util/typedefs.hpp"

#include <boost/optional.hpp>
#include <cstddef>
#include <guidance/turn_bearing.hpp>
#include <optional>
#include <vector>

namespace osrm::engine::guidance
Expand Down
2 changes: 1 addition & 1 deletion include/engine/guidance/route_leg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "engine/guidance/route_step.hpp"

#include <boost/optional.hpp>
#include <optional>

#include <string>
#include <vector>
Expand Down
4 changes: 2 additions & 2 deletions include/engine/internal_route_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "util/integer_range.hpp"
#include "util/typedefs.hpp"

#include <boost/optional.hpp>
#include <optional>
#include <vector>

namespace osrm::engine
Expand All @@ -42,7 +42,7 @@ struct PathData
// Source of the speed value on this road segment
DatasourceID datasource_id;
// If segment precedes a turn, ID of the turn itself
boost::optional<EdgeID> turn_edge;
std::optional<EdgeID> turn_edge;
};

struct InternalRouteResult
Expand Down
2 changes: 1 addition & 1 deletion include/engine/plugins/match.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MatchPlugin : public BasePlugin

MatchPlugin(const int max_locations_map_matching,
const double max_radius_map_matching,
const boost::optional<double> default_radius)
const std::optional<double> default_radius)
: BasePlugin(default_radius), max_locations_map_matching(max_locations_map_matching),
max_radius_map_matching(max_radius_map_matching)
{
Expand Down
2 changes: 1 addition & 1 deletion include/engine/plugins/nearest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace osrm::engine::plugins
class NearestPlugin final : public BasePlugin
{
public:
explicit NearestPlugin(const int max_results, const boost::optional<double> default_radius);
explicit NearestPlugin(const int max_results, const std::optional<double> default_radius);

Status HandleRequest(const RoutingAlgorithmsInterface &algorithms,
const api::NearestParameters &params,
Expand Down
Loading

0 comments on commit 57b792c

Please sign in to comment.