aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include/lazy.h
blob: f9dbd8dc7c334c0fdc640a27c9a380ca2a950107 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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;
    };
}