2017-04-01 16:09:34 +08:00
|
|
|
#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;
|
|
|
|
}
|
2017-04-13 13:12:37 +08:00
|
|
|
|
|
|
|
template<class Container, class Pred>
|
2017-04-14 06:37:24 +08:00
|
|
|
void erase_remove_if(Container& cont, Pred pred)
|
2017-04-13 13:12:37 +08:00
|
|
|
{
|
|
|
|
cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end());
|
|
|
|
}
|
2017-04-14 08:53:09 +08:00
|
|
|
|
|
|
|
template<class Container, class Pred>
|
|
|
|
auto find_if(const Container& cont, Pred pred)
|
|
|
|
{
|
|
|
|
return std::find_if(cont.cbegin(), cont.cend(), pred);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Container, class Pred>
|
|
|
|
auto find_if_not(const Container& cont, Pred pred)
|
|
|
|
{
|
|
|
|
return std::find_if_not(cont.cbegin(), cont.cend(), pred);
|
|
|
|
}
|
2017-04-01 16:09:34 +08:00
|
|
|
}
|