blob: 281614a1d62b62c380fa01d0bb24c652c0d0c854 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#pragma once
#include <util/generic/ptr.h>
#include <functional>
#include <utility>
namespace NYql {
template <class T>
class TLazyInitHolder
: public TPointerBase<TLazyInitHolder<T>, T>
{
public:
using TFactory = std::function<THolder<T>()>;
TLazyInitHolder(TFactory&& factory)
: Factory_(std::move(factory))
{
}
T* Get() const noexcept {
if (!Value_) {
Value_ = Factory_();
}
return Value_.Get();
}
inline explicit operator bool() const noexcept {
return !!Value_.Get();
}
private:
TFactory Factory_;
mutable THolder<T> Value_;
};
} // NYql
|