vcpkg/toolsrc/include/lazy.h
2017-03-13 17:56:21 -07:00

27 lines
465 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;
};
}