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&,
25 To<boost::optional<std::nullptr_t>>) {
26 static_assert(!
sizeof(Value),
27 "optional<nullptr_t> is forbidden, check IsNull() instead");
31template <
class Value,
typename T>
32boost::optional<T> Convert(
const Value& value,
To<boost::optional<T>>) {
33 if (value.IsMissing() || value.IsNull()) {
36 return value.
template ConvertTo<T>();
40boost::optional<std::nullptr_t> Convert(
const Value&,
41 To<boost::optional<std::nullptr_t>>) {
42 static_assert(!
sizeof(Value),
43 "optional<nullptr_t> is forbidden, check IsNull() instead");