mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-11-25 13:31:48 +08:00
27 lines
463 B
C++
27 lines
463 B
C++
#pragma once
|
|
|
|
namespace vcpkg
|
|
{
|
|
template<typename T>
|
|
class Lazy
|
|
{
|
|
public:
|
|
Lazy() : value(T()), initialized(false) {}
|
|
|
|
template<class F>
|
|
T const& get_lazy(const F& f) const
|
|
{
|
|
if (!initialized)
|
|
{
|
|
value = f();
|
|
initialized = true;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
private:
|
|
mutable T value;
|
|
mutable bool initialized;
|
|
};
|
|
}
|