Use const std::string& as argument to route() (#684)

This commit is contained in:
Corentin Schreiber 2024-01-29 17:10:20 +00:00 committed by GitHub
parent 973d5fa1cd
commit df756fed45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 18 deletions

View File

@ -97,25 +97,25 @@ namespace crow
}
/// Create a dynamic route using a rule (**Use CROW_ROUTE instead**)
DynamicRule& route_dynamic(std::string&& rule)
DynamicRule& route_dynamic(const std::string& rule)
{
return router_.new_rule_dynamic(std::move(rule));
return router_.new_rule_dynamic(rule);
}
///Create a route using a rule (**Use CROW_ROUTE instead**)
/// Create a route using a rule (**Use CROW_ROUTE instead**)
template<uint64_t Tag>
#ifdef CROW_GCC83_WORKAROUND
auto& route(std::string&& rule)
auto& route(const std::string& rule)
#else
auto route(std::string&& rule)
auto route(const std::string& rule)
#endif
#if defined CROW_CAN_USE_CPP17 && !defined CROW_GCC83_WORKAROUND
-> typename std::invoke_result<decltype(&Router::new_rule_tagged<Tag>), Router, std::string&&>::type
-> typename std::invoke_result<decltype(&Router::new_rule_tagged<Tag>), Router, const std::string&>::type
#elif !defined CROW_GCC83_WORKAROUND
-> typename std::result_of<decltype (&Router::new_rule_tagged<Tag>)(Router, std::string&&)>::type
-> typename std::result_of<decltype (&Router::new_rule_tagged<Tag>)(Router, const std::string&)>::type
#endif
{
return router_.new_rule_tagged<Tag>(std::move(rule));
return router_.new_rule_tagged<Tag>(rule);
}
/// Create a route for any requests without a proper route (**Use CROW_CATCHALL_ROUTE instead**)
@ -187,7 +187,7 @@ namespace crow
bindaddr_ = bindaddr;
return *this;
}
/// Get the address that Crow will handle requests on
std::string bindaddr()
{
@ -208,7 +208,7 @@ namespace crow
concurrency_ = concurrency;
return *this;
}
/// Get the number of threads that server is using
std::uint16_t concurrency()
{

View File

@ -1154,11 +1154,10 @@ namespace crow
return static_dir_;
}
DynamicRule& new_rule_dynamic(std::string&& rule)
DynamicRule& new_rule_dynamic(const std::string& rule)
{
std::string new_rule = std::move(rule);
new_rule = '/' + prefix_ + new_rule;
auto ruleObject = new DynamicRule(new_rule);
std::string new_rule = '/' + prefix_ + rule;
auto ruleObject = new DynamicRule(std::move(new_rule));
ruleObject->custom_templates_base = templates_dir_;
all_rules_.emplace_back(ruleObject);
@ -1166,13 +1165,12 @@ namespace crow
}
template<uint64_t N>
typename black_magic::arguments<N>::type::template rebind<TaggedRule>& new_rule_tagged(std::string&& rule)
typename black_magic::arguments<N>::type::template rebind<TaggedRule>& new_rule_tagged(const std::string& rule)
{
std::string new_rule = std::move(rule);
new_rule = '/' + prefix_ + new_rule;
std::string new_rule = '/' + prefix_ + rule;
using RuleT = typename black_magic::arguments<N>::type::template rebind<TaggedRule>;
auto ruleObject = new RuleT(new_rule);
auto ruleObject = new RuleT(std::move(new_rule));
ruleObject->custom_templates_base = templates_dir_;
all_rules_.emplace_back(ruleObject);