Github   Telegram
Loading...
Searching...
No Matches
lazy_prvalue.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <type_traits>
7#include <utility>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace utils {
12
17template <typename Func>
18class LazyPrvalue final {
19 static_assert(!std::is_reference_v<Func>);
20
21 public:
22 constexpr explicit LazyPrvalue(const Func& func) : func_(func) {}
23
24 constexpr explicit LazyPrvalue(Func&& func) : func_(std::move(func)) {}
25
26 LazyPrvalue(LazyPrvalue&&) = delete;
27 LazyPrvalue& operator=(LazyPrvalue&&) = delete;
28
29 constexpr /* implicit */ operator std::invoke_result_t<Func&&>() && {
30 return std::move(func_)();
31 }
32
33 private:
34 Func func_;
35};
36
37} // namespace utils
38
39USERVER_NAMESPACE_END