15 template <invocable F>
17 requires (convertible_to<invoke_result_t<F>, T>)
18 : fOneTimeGetter_{forward<F> (oneTimeGetter)}
25 call_once (fOnceFlag_, [&] () {
27 construct_at (&fValue_, v);
31 constexpr LazyInitialized<T>::~LazyInitialized ()
33 bool wasOneTimeGetterCalled =
true;
34 call_once (fOnceFlag_, [&] () { wasOneTimeGetterCalled =
false; });
35 if (wasOneTimeGetterCalled) {
36 destroy_at (&fValue_);
39 destroy_at (&fOneTimeGetter_);
43 inline LazyInitialized<T>& LazyInitialized<T>::operator= (
const T& rhs)
45 bool wasOneTimeGetterCalled =
true;
46 call_once (fOnceFlag_, [&] () { wasOneTimeGetterCalled =
false; });
47 if (wasOneTimeGetterCalled) {
51 destroy_at (&fOneTimeGetter_);
52 construct_at (&fValue_, rhs);
77 inline T& LazyInitialized<T>::Getter_ ()
80 return const_cast<T&
> (
const_cast<const LazyInitialized<T>*
> (
this)->Getter_ ());
83 inline const T& LazyInitialized<T>::Getter_ ()
const
85 call_once (fOnceFlag_, [&] () {
87 auto tmp = fOneTimeGetter_ ();
88 destroy_at (&fOneTimeGetter_);
89 construct_at (&fValue_, move (tmp));
value-object, where the value construction is delayed until first needed (can be handy to avoid c++ i...
nonvirtual const T operator()() const
nonvirtual T * operator->()