vcpkg/toolsrc/include/lazy.h

27 lines
463 B
C
Raw Normal View History

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