diff --git a/examples/example.cpp b/examples/example.cpp index a2739a827..7915e469e 100644 --- a/examples/example.cpp +++ b/examples/example.cpp @@ -13,12 +13,11 @@ struct ExampleMiddleware { std::string message; - ExampleMiddleware() + ExampleMiddleware() : message(std::string("foo")) { - message = "foo"; } - void setMessage(std::string newMsg) + void setMessage(const std::string &newMsg) { message = newMsg; } diff --git a/examples/example_vs.cpp b/examples/example_vs.cpp index dbc4d3101..87e344011 100644 --- a/examples/example_vs.cpp +++ b/examples/example_vs.cpp @@ -13,12 +13,11 @@ struct ExampleMiddleware { std::string message; - ExampleMiddleware() + ExampleMiddleware() : message(std::string("foo")) { - message = "foo"; } - void setMessage(std::string newMsg) + void setMessage(const std::string &newMsg) { message = newMsg; } diff --git a/include/crow/http_response.h b/include/crow/http_response.h index 0b46aaecb..ad479ccf6 100644 --- a/include/crow/http_response.h +++ b/include/crow/http_response.h @@ -124,6 +124,11 @@ namespace crow } } + void end(const int& _code) { + code = _code; + end(); + } + /// Same as end() except it adds a body part right before ending. void end(const std::string& body_part) { diff --git a/include/crow/routing.h b/include/crow/routing.h index 0ddf72dfa..2403d10a0 100644 --- a/include/crow/routing.h +++ b/include/crow/routing.h @@ -516,7 +516,33 @@ namespace crow template typename std::enable_if< !black_magic::CallHelper>::value && - !black_magic::CallHelper>::value, + !black_magic::CallHelper>::value && + black_magic::CallHelper>::value, + void>::type + operator()(Func&& f) + { + static_assert(black_magic::CallHelper>::value || + black_magic::CallHelper>::value + , + "Handle type is mismatched with URL parameters"); + static_assert(std::is_same(), std::declval()...))>::value, + "Handler function with response argument should have void return type"); + + handler_ = ( + #ifdef CROW_CAN_USE_CPP14 + [f = std::move(f)] + #else + [f] + #endif + (const crow::request& req, crow::response& res, Args ... args) { + f(res, args...); + }); + } + template + typename std::enable_if< + !black_magic::CallHelper>::value&& + !black_magic::CallHelper>::value && + !black_magic::CallHelper>::value, void>::type operator()(Func&& f) {