![]() |
boost::taar::handler::with_default — Wrap an argument provider with a fallback value.
// In header: <boost/taar/handler/rest_arg.hpp> template<typename ArgProviderType, typename ValueType> struct with_default { // types typedef ArgProviderType arg_provider_type; typedef ValueType value_type; typedef unspecified arg_provider_request_type; typedef unspecified arg_provider_result_type; // public member functions with_default(arg_provider_type, value_type); std::string name() const; std::string description() const; decltype(auto) operator()(arg_provider_request_type const &, matcher::context const &) const; value_type const & default_value() const; // public data members arg_provider_type arg_provider_; value_type default_value_; };
When the wrapped provider fails with error::argument_not_found, default_value is substituted instead. Other errors are propagated unchanged. This is the idiomatic way to make an argument optional with a non-std::optional type.
taar::handler::rest( [](int page) { ... }, taar::handler::with_default(taar::handler::query_arg("page"), 1));
with_default public member functionswith_default(arg_provider_type arg_provider, value_type default_value);
std::string name() const;
std::string description() const;
decltype(auto) operator()(arg_provider_request_type const & request, matcher::context const & context) const;
value_type const & default_value() const;