Skip to content

Commit 80d7679

Browse files
committed
router: replace boost fusion by c++17
1 parent 4b2573c commit 80d7679

File tree

2 files changed

+15
-36
lines changed

2 files changed

+15
-36
lines changed

include/cgimap/router.hpp

+10-31
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,14 @@
1616
#include <stdexcept>
1717
#include <string>
1818
#include <string_view>
19+
#include <tuple>
1920
#include <utility>
2021
#include <vector>
2122

22-
#include <boost/fusion/container/generation/make_cons.hpp>
23-
#include <boost/fusion/include/make_cons.hpp>
24-
#include <boost/fusion/container/list.hpp>
25-
#include <boost/fusion/include/list.hpp>
26-
#include <boost/fusion/algorithm/transformation/join.hpp>
27-
#include <boost/fusion/include/join.hpp>
28-
#include <boost/fusion/sequence/io.hpp>
29-
#include <boost/fusion/include/io.hpp>
30-
#include <boost/fusion/sequence/intrinsic/at.hpp>
31-
#include <boost/fusion/include/at.hpp>
32-
#include <boost/fusion/container/list/convert.hpp>
33-
#include <boost/fusion/include/as_list.hpp>
34-
#include <boost/algorithm/string.hpp>
35-
#include <boost/function_types/function_type.hpp>
36-
#include <boost/fusion/functional/invocation/invoke.hpp>
37-
#include <boost/functional/factory.hpp>
38-
3923
namespace match {
4024

41-
using boost::fusion::list;
42-
using boost::fusion::join;
43-
using boost::fusion::make_cons;
44-
using boost::fusion::as_list;
45-
namespace result_of = boost::fusion::result_of;
25+
template<typename ... input_t>
26+
using tuple_cat_t = decltype(std::tuple_cat(std::declval<input_t>()...));
4627

4728
// iterates over the split up parts of the item being matched.
4829
using part_iterator = std::vector<std::string_view>::const_iterator;
@@ -93,20 +74,18 @@ template <typename Self> struct ops {
9374
template <typename LeftType, typename RightType>
9475
struct match_and : public ops<match_and<LeftType, RightType> > {
9576

96-
using match_type = typename result_of::as_list<typename result_of::join<
97-
typename LeftType::match_type,
98-
typename RightType::match_type>::type>::type;
77+
using match_type = tuple_cat_t<typename LeftType::match_type, typename RightType::match_type>;
9978

10079
match_and(const LeftType &l, const RightType &r) : lhs(l), rhs(r) {}
10180

10281
std::pair<match_type, bool> match(part_iterator &begin, const part_iterator &end) const {
10382
auto [ lval, lerror ] = lhs.match(begin, end);
10483
if (lerror)
105-
return {as_list(join(typename LeftType::match_type(), typename RightType::match_type())), true};
84+
return {std::tuple_cat(typename LeftType::match_type(), typename RightType::match_type()), true};
10685
auto [ rval, rerror ] = rhs.match(begin, end);
10786
if (rerror)
108-
return {as_list(join(typename LeftType::match_type(), typename RightType::match_type())), true};
109-
return {as_list(join(lval, rval)), false};
87+
return {std::tuple_cat(typename LeftType::match_type(), typename RightType::match_type()), true};
88+
return {std::tuple_cat(lval, rval), false};
11089
}
11190

11291
private:
@@ -119,7 +98,7 @@ struct match_and : public ops<match_and<LeftType, RightType> > {
11998
*/
12099
struct match_string : public ops<match_string> {
121100
// doesn't return anything, simply fails if the string doesn't match.
122-
using match_type = list<>;
101+
using match_type = std::tuple<>;
123102

124103
// implicit constructor intended, so that the use of this class is
125104
// hidden and easier / nicer to read.
@@ -138,7 +117,7 @@ struct match_string : public ops<match_string> {
138117
* match an OSM ID, returning it in the match tuple.
139118
*/
140119
struct match_osm_id : public ops<match_osm_id> {
141-
using match_type = list<osm_nwr_id_t>;
120+
using match_type = std::tuple<osm_nwr_id_t>;
142121
match_osm_id() = default;
143122
std::pair<match_type, bool> match(part_iterator &begin, const part_iterator &end) const noexcept;
144123
};
@@ -149,7 +128,7 @@ struct match_osm_id : public ops<match_osm_id> {
149128
* without needing explicit constructors for the string literal matches.
150129
*/
151130
struct match_begin : public ops<match_begin> {
152-
using match_type = list<>;
131+
using match_type = std::tuple<>;
153132
match_begin() = default;
154133
inline std::pair<match_type, bool> match(part_iterator &begin, const part_iterator &end) const noexcept{
155134
return {match_type(), false};

src/routes.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ struct router {
9494
if (begin != parts.end())
9595
return false; // no match
9696

97-
// the function to call (used later as constructor factory)
98-
boost::factory<Handler *> func{};
99-
100-
ptr.reset(
101-
boost::fusion::invoke(func, boost::fusion::make_cons(std::ref(params), sequence)));
97+
ptr.reset(std::apply(
98+
[&params](auto &&...args) {
99+
return new Handler(params, std::forward<decltype(args)>(args)...);
100+
},
101+
sequence));
102102

103103
return true;
104104
}

0 commit comments

Comments
 (0)