aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2017-03-09 18:24:04 -0800
committerAlexander Karatarakis <alkarata@microsoft.com>2017-03-10 17:04:28 -0800
commit47b53b9015deaa2f569d788447254c8bc3de96a9 (patch)
treec66c9c42a119eadc226f278abad0d48c198e07ff /toolsrc/include
parent5ba6f1725da1d11fbe1103dbafb6729107cec629 (diff)
downloadvcpkg-47b53b9015deaa2f569d788447254c8bc3de96a9.tar.gz
vcpkg-47b53b9015deaa2f569d788447254c8bc3de96a9.zip
Add lazy.h
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/lazy.h26
1 files changed, 26 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;
+ };
+}