vcpkg/toolsrc/include/lazy.h

27 lines
465 B
C
Raw Normal View History

2017-03-10 10:24:04 +08:00
#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
2017-03-10 10:24:04 +08:00
{
if (!initialized)
{
value = f();
initialized = true;
}
return value;
}
private:
mutable T value;
mutable bool initialized;
};
}