Add lazy.h

This commit is contained in:
Alexander Karatarakis 2017-03-09 18:24:04 -08:00
parent 5ba6f1725d
commit 47b53b9015
3 changed files with 30 additions and 0 deletions

26
toolsrc/include/lazy.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
namespace vcpkg
{
template <typename T>
class lazy
{
public:
lazy() : value(T()), initialized(false) {}
template <class F>
T const& get_lazy(F& f) const
{
if (!initialized)
{
value = f();
initialized = true;
}
return value;
}
private:
mutable T value;
mutable bool initialized;
};
}

View File

@ -137,6 +137,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\include\BinaryParagraph.h" />
<ClInclude Include="..\include\lazy.h" />
<ClInclude Include="..\include\PostBuildLint_BuildInfo.h" />
<ClInclude Include="..\include\PostBuildLint_BuildPolicies.h" />
<ClInclude Include="..\include\coff_file_reader.h" />

View File

@ -293,5 +293,8 @@
<ClInclude Include="..\include\vcpkg_Chrono.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\lazy.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>