27 lines
463 B
C
Raw Normal View History

2017-03-09 18:24:04 -08:00
#pragma once
namespace vcpkg
{
template<typename T>
2017-04-03 14:23:05 -07:00
class Lazy
2017-03-09 18:24:04 -08:00
{
public:
2017-04-03 14:23:05 -07:00
Lazy() : value(T()), initialized(false) {}
2017-03-09 18:24:04 -08:00
template<class F>
T const& get_lazy(const F& f) const
2017-03-09 18:24:04 -08:00
{
if (!initialized)
{
value = f();
initialized = true;
}
return value;
}
private:
mutable T value;
mutable bool initialized;
};
}