diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-03-09 18:24:04 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-03-10 17:04:28 -0800 |
| commit | 47b53b9015deaa2f569d788447254c8bc3de96a9 (patch) | |
| tree | c66c9c42a119eadc226f278abad0d48c198e07ff | |
| parent | 5ba6f1725da1d11fbe1103dbafb6729107cec629 (diff) | |
| download | vcpkg-47b53b9015deaa2f569d788447254c8bc3de96a9.tar.gz vcpkg-47b53b9015deaa2f569d788447254c8bc3de96a9.zip | |
Add lazy.h
| -rw-r--r-- | toolsrc/include/lazy.h | 26 | ||||
| -rw-r--r-- | toolsrc/vcpkglib/vcpkglib.vcxproj | 1 | ||||
| -rw-r--r-- | toolsrc/vcpkglib/vcpkglib.vcxproj.filters | 3 |
3 files changed, 30 insertions, 0 deletions
diff --git a/toolsrc/include/lazy.h b/toolsrc/include/lazy.h new file mode 100644 index 000000000..f9dbd8dc7 --- /dev/null +++ b/toolsrc/include/lazy.h @@ -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; + }; +} diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj b/toolsrc/vcpkglib/vcpkglib.vcxproj index b96dd1050..dd5dd124a 100644 --- a/toolsrc/vcpkglib/vcpkglib.vcxproj +++ b/toolsrc/vcpkglib/vcpkglib.vcxproj @@ -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" /> diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters index aefba7a49..d701321be 100644 --- a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters +++ b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters @@ -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>
\ No newline at end of file |
