7#include <userver/formats/parse/to.hpp>
9#include <boost/optional.hpp>
11USERVER_NAMESPACE_BEGIN
15template <
class Value,
typename T>
16boost::optional<T> Parse(
const Value& value,
To<boost::optional<T>>) {
17 if (value.IsMissing() || value.IsNull()) {
20 return value.
template As<T>();
24boost::optional<std::nullptr_t> Parse(
const Value&,
To<boost::optional<std::nullptr_t>>) {
25 static_assert(!
sizeof(Value),
"optional<nullptr_t> is forbidden, check IsNull() instead");
29template <
class Value,
typename T>
30boost::optional<T> Convert(
const Value& value,
To<boost::optional<T>>) {
31 if (value.IsMissing() || value.IsNull()) {
34 return value.
template ConvertTo<T>();
38boost::optional<std::nullptr_t> Convert(
const Value&,
To<boost::optional<std::nullptr_t>>) {
39 static_assert(!
sizeof(Value),
"optional<nullptr_t> is forbidden, check IsNull() instead");