aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include/lazy.h
blob: 58c11c002fd6161ede42cc8039563de8f66517e4 (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(const F& f) const
        {
            if (!initialized)
            {
                value = f();
                initialized = true;
            }
            return value;
        }

    private:
        mutable T value;
        mutable bool initialized;
    };
}