userver
C++ Async Framework
Toggle main menu visibility
Documentation
API Groups
Namespaces
Reference
Class List
Class Index
File List
Macros
All
e
i
l
r
t
u
Functions
Macros
e
i
l
r
t
u
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
Concepts
Loading...
Searching...
No Matches
optionals.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/utils/optionals.hpp
4
/// @brief Helper functions for std optionals
5
/// @ingroup userver_universal
6
7
#
include
<
optional
>
8
#
include
<
string
>
9
#
include
<
utility
>
10
11
#
include
<
fmt
/
compile
.
h
>
12
#
include
<
fmt
/
format
.
h
>
13
14
USERVER_NAMESPACE_BEGIN
15
16
namespace
utils
{
17
18
/// Converts std::optional to a string, empty value represented as "--"
19
template
<
class
T>
20
std::string
ToString
(
const
std::optional<T>& from) {
21
return
from ? fmt::format(FMT_COMPILE(
" {}"
), *from) :
"--"
;
22
}
20
std::string
ToString
(
const
std::optional<T>& from) {
…
}
23
24
/// A polyfill for C++23 monadic operations for `std::optional`.
25
template
<
typename
T,
typename
Func>
26
auto
OptionalTransform
(T&& opt, Func func) -> std::optional<
decltype
(std::move(func)(*std::forward<T>(opt)))> {
27
if
(opt)
return
std::move(func)(*std::forward<T>(opt));
28
return
std::nullopt;
29
}
26
auto
OptionalTransform
(T&& opt, Func func) -> std::optional<
decltype
(std::move(func)(*std::forward<T>(opt)))> {
…
}
30
31
}
// namespace utils
32
33
USERVER_NAMESPACE_END
userver
utils
optionals.hpp
Generated on Fri Apr 11 2025 14:26:10 for userver by
Doxygen
1.13.2