value_or.hpp
Go to the documentation of this file.
/*
restinio
*/
#pragma once
#include <type_traits>
#include <restinio/cast_to.hpp>
#include <restinio/uri_helpers.hpp>
#include <restinio/router/express.hpp>
namespace restinio
{
template < typename Value_Type, typename Parameter_Container >
typename std::enable_if<
std::is_same< Parameter_Container, query_string_params_t >::value ||
std::is_same< Parameter_Container, router::route_params_t >::value,
Value_Type >::type
value_or( const Parameter_Container & params, string_view_t key, Value_Type default_value )
{
const auto value = params.get_param( key );
if( value )
{
return cast_to< Value_Type >( *value );
}
return default_value;
}
template < typename Value_Type, typename Parameter_Container >
typename std::enable_if<
std::is_same< Parameter_Container, query_string_params_t >::value ||
std::is_same< Parameter_Container, router::route_params_t >::value,
optional_t< Value_Type > >::type
opt_value( const Parameter_Container & params, string_view_t key )
{
optional_t< Value_Type > result{};
const auto value = params.get_param( key );
if( value )
{
result = cast_to< Value_Type >( *value );
}
return result;
}
} /* namespace restinio */
cast_to.hpp
nonstd::optional_lite::optional
class optional
Definition: optional.hpp:919
express.hpp
restinio
Definition: asio_include.hpp:21
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
restinio::value_or
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, Value_Type >::type value_or(const Parameter_Container &params, string_view_t key, Value_Type default_value)
Get parameter value or a given default.
Definition: value_or.hpp:36
restinio::opt_value
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, optional_t< Value_Type > >::type opt_value(const Parameter_Container &params, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...
Definition: value_or.hpp:64
uri_helpers.hpp