userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
boost_optional.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/formats/parse/boost_optional.hpp
4
/// @brief Parsers and converters for boost::optional
5
/// @ingroup userver_universal userver_formats_parse
6
7
#
include
<
userver
/
formats
/
parse
/
to
.
hpp
>
8
9
#
include
<
boost
/
optional
.
hpp
>
10
11
USERVER_NAMESPACE_BEGIN
12
13
/// @brief Generic parsing helpers (`formats::parse::To` and friends).
14
namespace
formats::
parse
{
15
16
template
<
class
Value,
typename
T>
17
boost::optional<T> Parse(
const
Value& value,
To
<boost::optional<T>>) {
18
if
(value.IsMissing() || value.IsNull()) {
19
return
boost::none;
20
}
21
return
value.
template
As<T>();
22
}
23
24
template
<
class
Value>
25
boost::optional<std::nullptr_t> Parse(
const
Value&,
To
<boost::optional<std::nullptr_t>>) {
26
static_assert
(!
sizeof
(Value),
"optional<nullptr_t> is forbidden, check IsNull() instead"
);
27
return
nullptr
;
28
}
29
30
template
<
class
Value,
typename
T>
31
boost::optional<T> Convert(
const
Value& value,
To
<boost::optional<T>>) {
32
if
(value.IsMissing() || value.IsNull()) {
33
return
boost::none;
34
}
35
return
value.
template
ConvertTo<T>();
36
}
37
38
template
<
class
Value>
39
boost::optional<std::nullptr_t> Convert(
const
Value&,
To
<boost::optional<std::nullptr_t>>) {
40
static_assert
(!
sizeof
(Value),
"optional<nullptr_t> is forbidden, check IsNull() instead"
);
41
return
nullptr
;
42
}
43
44
}
// namespace formats::parse
45
46
USERVER_NAMESPACE_END
userver
formats
parse
boost_optional.hpp
Generated on
for userver by
Doxygen
1.17.0