summaryrefslogtreecommitdiffstats
path: root/util/generic/lazy_value.h
diff options
context:
space:
mode:
authordiver <[email protected]>2022-02-10 16:48:07 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:48:07 +0300
commit7629e1f9ef7f9d2a3c345c97e6a4e5a4b32ee786 (patch)
treec3371bfa47641a52244267b63009d16e4e7054ff /util/generic/lazy_value.h
parentcc573d2716c99ba22afc98753971cd97fd5283e0 (diff)
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'util/generic/lazy_value.h')
-rw-r--r--util/generic/lazy_value.h86
1 files changed, 43 insertions, 43 deletions
diff --git a/util/generic/lazy_value.h b/util/generic/lazy_value.h
index 3c720f76b5a..033b46eaf23 100644
--- a/util/generic/lazy_value.h
+++ b/util/generic/lazy_value.h
@@ -1,53 +1,53 @@
-#pragma once
-
-#include "maybe.h"
+#pragma once
+
+#include "maybe.h"
#include "function.h"
-
-template <class T>
+
+template <class T>
class TLazyValueBase {
-public:
+public:
using TInitializer = std::function<T()>;
-
+
TLazyValueBase() = default;
TLazyValueBase(TInitializer initializer)
: Initializer(std::move(initializer))
- {
- }
-
- explicit operator bool() const noexcept {
- return Defined();
- }
-
- bool Defined() const noexcept {
- return ValueHolder.Defined();
- }
-
- const T& GetRef() const {
- if (!Defined()) {
- InitDefault();
- }
- return *ValueHolder;
- }
-
- const T& operator*() const {
- return GetRef();
- }
-
- const T* operator->() const {
- return &GetRef();
- }
-
- void InitDefault() const {
+ {
+ }
+
+ explicit operator bool() const noexcept {
+ return Defined();
+ }
+
+ bool Defined() const noexcept {
+ return ValueHolder.Defined();
+ }
+
+ const T& GetRef() const {
+ if (!Defined()) {
+ InitDefault();
+ }
+ return *ValueHolder;
+ }
+
+ const T& operator*() const {
+ return GetRef();
+ }
+
+ const T* operator->() const {
+ return &GetRef();
+ }
+
+ void InitDefault() const {
Y_ASSERT(Initializer);
- ValueHolder = Initializer();
- }
-
-private:
- mutable TMaybe<T> ValueHolder;
- TInitializer Initializer;
-};
-
+ ValueHolder = Initializer();
+ }
+
+private:
+ mutable TMaybe<T> ValueHolder;
+ TInitializer Initializer;
+};
+
// we need this to get implicit construction TLazyValue from lambda
// and save default copy constructor and operator= for type TLazyValue
template <class T>
@@ -63,4 +63,4 @@ public:
template <typename F>
TLazyValue<TFunctionResult<F>> MakeLazy(F&& f) {
return {std::forward<F>(f)};
-}
+}