userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
lazy_prvalue.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/utils/lazy_prvalue.hpp
4
/// @brief @copybrief utils::LazyPrvalue
5
6
#
include
<
type_traits
>
7
#
include
<
utility
>
8
9
USERVER_NAMESPACE_BEGIN
10
11
namespace
utils
{
12
13
/// @ingroup userver_universal
14
///
15
/// @brief Can be used with various emplace functions to allow in-place
16
/// constructing a non-movable value using a callable.
17
///
18
/// @snippet universal/src/utils/lazy_prvalue_test.cpp LazyPrvalue sample
19
template
<
typename
Func>
20
class
LazyPrvalue final {
21
static_assert
(!std::is_reference_v<Func>);
22
23
public
:
24
constexpr
explicit
LazyPrvalue(
const
Func& func)
25
: func_(func)
26
{}
27
28
constexpr
explicit
LazyPrvalue(Func&& func)
29
: func_(std::move(func))
30
{}
31
32
LazyPrvalue(LazyPrvalue&&) =
delete
;
33
LazyPrvalue& operator=(LazyPrvalue&&) =
delete
;
34
35
constexpr
/* implicit */
operator std::invoke_result_t<Func&&>() && {
return
std::move(func_)(); }
36
37
private
:
38
[[no_unique_address]] Func func_;
39
};
40
41
}
// namespace utils
42
43
USERVER_NAMESPACE_END
userver
utils
lazy_prvalue.hpp
Generated on
for userver by
Doxygen
1.17.0