aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
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;
+ };
+}