aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include/vcpkg_Util.h
blob: 4ebb2a80222ed6dc775e6e6217deb1e9659caa5b (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
#pragma once

#include <vector>
#include <utility>

namespace vcpkg::Util
{
    template<class Cont, class Func>
    using FmapOut = decltype(std::declval<Func>()(std::declval<Cont>()[0]));

    template<class Cont, class Func, class Out = FmapOut<Cont, Func>>
    std::vector<Out> fmap(const Cont& xs, Func&& f)
    {
        using O = decltype(f(xs[0]));

        std::vector<O> ret;
        ret.reserve(xs.size());

        for (auto&& x : xs)
            ret.push_back(f(x));

        return ret;
    }
}