Skip to content

Commit d5e04f4

Browse files
committed
flat_router is default constructible
1 parent 79381e1 commit d5e04f4

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

include/boost/http/server/flat_router.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class BOOST_HTTP_DECL
4747
std::shared_ptr<impl> impl_;
4848

4949
public:
50+
/** Default constructor.
51+
52+
Creates a flat_router in an empty state. The only valid
53+
operations on a default-constructed router are assignment
54+
and destruction.
55+
*/
56+
flat_router() = default;
57+
5058
flat_router(
5159
detail::router_base&&);
5260

test/unit/server/flat_router.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,31 @@ struct flat_router_test
8080
BOOST_TEST_EQ(*counter, 2);
8181
}
8282

83+
void testDefaultConstruction()
84+
{
85+
auto counter = std::make_shared<int>(0);
86+
test_router r;
87+
r.all("/", [counter](params&) -> route_task
88+
{
89+
++(*counter);
90+
co_return route_result{};
91+
});
92+
93+
flat_router fr1; // default construct
94+
flat_router fr2(std::move(r));
95+
fr1 = fr2; // assign to default-constructed
96+
97+
params req;
98+
capy::test::run_blocking()(fr1.dispatch(
99+
http::method::get, urls::url_view("/"), req));
100+
BOOST_TEST_EQ(*counter, 1);
101+
}
102+
83103
void run()
84104
{
85105
testCopyConstruction();
86106
testCopyAssignment();
107+
testDefaultConstruction();
87108
}
88109
};
89110

0 commit comments

Comments
 (0)