2017-03-09 18:24:04 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace vcpkg
|
|
|
|
{
|
2017-04-27 17:56:06 -07:00
|
|
|
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
|
|
|
|
2017-04-27 17:56:06 -07:00
|
|
|
template<class F>
|
2017-03-13 16:27:08 -07:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
}
|