Skip to content

Commit c1ed731

Browse files
Use std::variant instead of mapbox::util::variant (#6903)
1 parent 01b1673 commit c1ed731

File tree

117 files changed

+472
-17601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+472
-17601
lines changed

.github/workflows/osrm-backend.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,6 @@ jobs:
274274
CXXCOMPILER: g++-12
275275
CXXFLAGS: '-Wno-array-bounds -Wno-uninitialized'
276276

277-
- name: gcc-11-release
278-
continue-on-error: false
279-
node: 20
280-
runs-on: ubuntu-22.04
281-
BUILD_TOOLS: ON
282-
BUILD_TYPE: Release
283-
CCOMPILER: gcc-11
284-
CXXCOMPILER: g++-11
285-
286277
- name: conan-linux-release-node
287278
build_node_package: true
288279
continue-on-error: false

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- NodeJS:
2323
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
2424
- Misc:
25+
- CHANGED: Use std::variant instead of mapbox::util::variant. [#6903](https://github.com/Project-OSRM/osrm-backend/pull/6903)
2526
- CHANGED: Bump rapidjson to version f9d53419e912910fd8fa57d5705fa41425428c35 [#6906](https://github.com/Project-OSRM/osrm-backend/pull/6906)
2627
- CHANGED: Bump mapbox/variant to version 1.2.0 [#6898](https://github.com/Project-OSRM/osrm-backend/pull/6898)
2728
- CHANGED: Avoid copy of std::function-based callback in path unpacking [#6895](https://github.com/Project-OSRM/osrm-backend/pull/6895)

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ endif()
121121
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/include/)
122122
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include/)
123123
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/third_party/sol2-3.3.0/include)
124-
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/third_party/variant/include)
125124

126125
set(BOOST_COMPONENTS date_time chrono filesystem iostreams program_options regex system thread unit_test_framework)
127126

@@ -607,7 +606,6 @@ if (BUILD_ROUTED)
607606
set_property(TARGET osrm-routed PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
608607
endif()
609608

610-
file(GLOB VariantGlob third_party/variant/include/mapbox/*.hpp)
611609
file(GLOB FlatbuffersGlob third_party/flatbuffers/include/flatbuffers/*.h)
612610
file(GLOB LibraryGlob include/osrm/*.hpp)
613611
file(GLOB ParametersGlob include/engine/api/*_parameters.hpp)
@@ -627,7 +625,6 @@ install(FILES ${ContractorHeader} DESTINATION include/osrm/contractor)
627625
install(FILES ${LibraryGlob} DESTINATION include/osrm)
628626
install(FILES ${ParametersGlob} DESTINATION include/osrm/engine/api)
629627
install(FILES ${ApiHeader} DESTINATION include/osrm/engine/api)
630-
install(FILES ${VariantGlob} DESTINATION include/mapbox)
631628
install(FILES ${FlatbuffersGlob} DESTINATION include/flatbuffers)
632629
install(TARGETS osrm-extract DESTINATION bin)
633630
install(TARGETS osrm-partition DESTINATION bin)

example/example.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ int main(int argc, const char *argv[])
5757
// Execute routing request, this does the heavy lifting
5858
const auto status = osrm.Route(params, result);
5959

60-
auto &json_result = result.get<json::Object>();
60+
auto &json_result = std::get<json::Object>(result);
6161
if (status == Status::Ok)
6262
{
63-
auto &routes = json_result.values["routes"].get<json::Array>();
63+
auto &routes = std::get<json::Array>(json_result.values["routes"]);
6464

6565
// Let's just use the first route
66-
auto &route = routes.values.at(0).get<json::Object>();
67-
const auto distance = route.values["distance"].get<json::Number>().value;
68-
const auto duration = route.values["duration"].get<json::Number>().value;
66+
auto &route = std::get<json::Object>(routes.values.at(0));
67+
const auto distance = std::get<json::Number>(route.values["distance"]).value;
68+
const auto duration = std::get<json::Number>(route.values["duration"]).value;
6969

7070
// Warn users if extract does not contain the default coordinates from above
7171
if (distance == 0 || duration == 0)
@@ -80,8 +80,8 @@ int main(int argc, const char *argv[])
8080
}
8181
else if (status == Status::Error)
8282
{
83-
const auto code = json_result.values["code"].get<json::String>().value;
84-
const auto message = json_result.values["message"].get<json::String>().value;
83+
const auto code = std::get<json::String>(json_result.values["code"]).value;
84+
const auto message = std::get<json::String>(json_result.values["message"]).value;
8585

8686
std::cout << "Code: " << code << "\n";
8787
std::cout << "Message: " << code << "\n";

include/engine/api/base_result.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
#define ENGINE_API_BASE_RESULT_HPP
33

44
#include <flatbuffers/flatbuffers.h>
5-
#include <mapbox/variant.hpp>
5+
#include <variant>
66

77
#include <string>
88

99
#include "util/json_container.hpp"
1010

1111
namespace osrm::engine::api
1212
{
13-
using ResultT =
14-
mapbox::util::variant<util::json::Object, std::string, flatbuffers::FlatBufferBuilder>;
13+
using ResultT = std::variant<util::json::Object, std::string, flatbuffers::FlatBufferBuilder>;
1514
} // namespace osrm::engine::api
1615

1716
#endif

include/engine/api/json_factory.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ inline bool hasValidLanes(const guidance::IntermediateIntersection &intersection
4141
return intersection.lanes.lanes_in_turn > 0;
4242
}
4343

44-
util::json::Array coordinateToLonLat(const util::Coordinate &coordinate);
44+
util::json::Value coordinateToLonLat(const util::Coordinate &coordinate);
4545

4646
/**
4747
* Ensures that a bearing value is a whole number, and clamped to the range 0-359
@@ -79,7 +79,7 @@ util::json::Object makeGeoJSONGeometry(ForwardIter begin, ForwardIter end)
7979
coordinates.values.push_back(location);
8080
coordinates.values.push_back(location);
8181
}
82-
geojson.values["coordinates"] = std::move(coordinates);
82+
geojson.values["coordinates"] = util::json::Value{std::move(coordinates)};
8383

8484
return geojson;
8585
}

include/engine/api/match_api.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class MatchAPI final : public RouteAPI
3030
osrm::engine::api::ResultT &response) const
3131
{
3232
BOOST_ASSERT(sub_matchings.size() == sub_routes.size());
33-
if (response.is<flatbuffers::FlatBufferBuilder>())
33+
if (std::holds_alternative<flatbuffers::FlatBufferBuilder>(response))
3434
{
35-
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
35+
auto &fb_result = std::get<flatbuffers::FlatBufferBuilder>(response);
3636
MakeResponse(sub_matchings, sub_routes, fb_result);
3737
}
3838
else
3939
{
40-
auto &json_result = response.get<util::json::Object>();
40+
auto &json_result = std::get<util::json::Object>(response);
4141
MakeResponse(sub_matchings, sub_routes, json_result);
4242
}
4343
}

include/engine/api/nearest_api.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ class NearestAPI final : public BaseAPI
2929
BOOST_ASSERT(phantom_nodes.size() == 1);
3030
BOOST_ASSERT(parameters.coordinates.size() == 1);
3131

32-
if (response.is<flatbuffers::FlatBufferBuilder>())
32+
if (std::holds_alternative<flatbuffers::FlatBufferBuilder>(response))
3333
{
34-
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
34+
auto &fb_result = std::get<flatbuffers::FlatBufferBuilder>(response);
3535
MakeResponse(phantom_nodes, fb_result);
3636
}
3737
else
3838
{
39-
auto &json_result = response.get<util::json::Object>();
39+
auto &json_result = std::get<util::json::Object>(response);
4040
MakeResponse(phantom_nodes, json_result);
4141
}
4242
}

include/engine/api/route_api.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ class RouteAPI : public BaseAPI
5050
{
5151
BOOST_ASSERT(!raw_routes.routes.empty());
5252

53-
if (response.is<flatbuffers::FlatBufferBuilder>())
53+
if (std::holds_alternative<flatbuffers::FlatBufferBuilder>(response))
5454
{
55-
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
55+
auto &fb_result = std::get<flatbuffers::FlatBufferBuilder>(response);
5656
MakeResponse(raw_routes, waypoint_candidates, fb_result);
5757
}
5858
else
5959
{
60-
auto &json_result = response.get<util::json::Object>();
60+
auto &json_result = std::get<util::json::Object>(response);
6161
MakeResponse(raw_routes, waypoint_candidates, json_result);
6262
}
6363
}
@@ -158,8 +158,8 @@ class RouteAPI : public BaseAPI
158158
}
159159

160160
template <typename ForwardIter>
161-
mapbox::util::variant<flatbuffers::Offset<flatbuffers::String>,
162-
flatbuffers::Offset<flatbuffers::Vector<const fbresult::Position *>>>
161+
std::variant<flatbuffers::Offset<flatbuffers::String>,
162+
flatbuffers::Offset<flatbuffers::Vector<const fbresult::Position *>>>
163163
MakeGeometry(flatbuffers::FlatBufferBuilder &builder, ForwardIter begin, ForwardIter end) const
164164
{
165165
if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
@@ -408,8 +408,8 @@ class RouteAPI : public BaseAPI
408408

409409
// Fill geometry
410410
auto overview = MakeOverview(leg_geometries);
411-
mapbox::util::variant<flatbuffers::Offset<flatbuffers::String>,
412-
flatbuffers::Offset<flatbuffers::Vector<const fbresult::Position *>>>
411+
std::variant<flatbuffers::Offset<flatbuffers::String>,
412+
flatbuffers::Offset<flatbuffers::Vector<const fbresult::Position *>>>
413413
geometry;
414414
if (overview)
415415
{
@@ -426,8 +426,7 @@ class RouteAPI : public BaseAPI
426426
routeObject.add_legs(legs_vector);
427427
if (overview)
428428
{
429-
mapbox::util::apply_visitor(GeometryVisitor<fbresult::RouteObjectBuilder>(routeObject),
430-
geometry);
429+
std::visit(GeometryVisitor<fbresult::RouteObjectBuilder>(routeObject), geometry);
431430
}
432431

433432
return routeObject.Finish();
@@ -644,7 +643,7 @@ class RouteAPI : public BaseAPI
644643
stepBuilder.add_rotary_pronunciation(rotary_pronunciation_string);
645644
stepBuilder.add_intersections(intersections_vector);
646645
stepBuilder.add_maneuver(maneuver_buffer);
647-
mapbox::util::apply_visitor(GeometryVisitor<fbresult::StepBuilder>(stepBuilder), geometry);
646+
std::visit(GeometryVisitor<fbresult::StepBuilder>(stepBuilder), geometry);
648647
return stepBuilder.Finish();
649648
};
650649

include/engine/api/table_api.hpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ class TableAPI final : public BaseAPI
5050
const std::vector<TableCellRef> &fallback_speed_cells,
5151
osrm::engine::api::ResultT &response) const
5252
{
53-
if (response.is<flatbuffers::FlatBufferBuilder>())
53+
if (std::holds_alternative<flatbuffers::FlatBufferBuilder>(response))
5454
{
55-
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
55+
auto &fb_result = std::get<flatbuffers::FlatBufferBuilder>(response);
5656
MakeResponse(tables, candidates, fallback_speed_cells, fb_result);
5757
}
5858
else
5959
{
60-
auto &json_result = response.get<util::json::Object>();
60+
auto &json_result = std::get<util::json::Object>(response);
6161
MakeResponse(tables, candidates, fallback_speed_cells, json_result);
6262
}
6363
}
@@ -377,7 +377,8 @@ class TableAPI final : public BaseAPI
377377
return util::json::Value(
378378
util::json::Number(from_alias<double>(duration) / 10.));
379379
});
380-
json_table.values.push_back(std::move(json_row));
380+
381+
json_table.values.push_back(util::json::Value{json_row});
381382
}
382383
return json_table;
383384
}
@@ -406,7 +407,7 @@ class TableAPI final : public BaseAPI
406407
return util::json::Value(util::json::Number(
407408
std::round(from_alias<double>(distance) * 10) / 10.));
408409
});
409-
json_table.values.push_back(std::move(json_row));
410+
json_table.values.push_back(util::json::Value{json_row});
410411
}
411412
return json_table;
412413
}
@@ -415,15 +416,18 @@ class TableAPI final : public BaseAPI
415416
MakeEstimatesTable(const std::vector<TableCellRef> &fallback_speed_cells) const
416417
{
417418
util::json::Array json_table;
418-
std::for_each(fallback_speed_cells.begin(),
419-
fallback_speed_cells.end(),
420-
[&](const auto &cell)
421-
{
422-
util::json::Array row;
423-
row.values.push_back(util::json::Number(cell.row));
424-
row.values.push_back(util::json::Number(cell.column));
425-
json_table.values.push_back(std::move(row));
426-
});
419+
std::for_each(
420+
fallback_speed_cells.begin(),
421+
fallback_speed_cells.end(),
422+
[&](const auto &cell)
423+
{
424+
util::json::Array row;
425+
util::json::Value jCellRow{util::json::Number(static_cast<double>(cell.row))};
426+
util::json::Value jCellColumn{util::json::Number(static_cast<double>(cell.column))};
427+
row.values.push_back(jCellRow);
428+
row.values.push_back(jCellColumn);
429+
json_table.values.push_back(util::json::Value{row});
430+
});
427431
return json_table;
428432
}
429433

0 commit comments

Comments
 (0)