NcEngine
Algorithm.h
1#pragma once
2
3#include "detail/EnumerateDetail.h"
4
5#include <algorithm>
6#include <type_traits>
7#include <vector>
8
9namespace nc::algo
10{
12template<class T, std::invocable<const T&> UnaryOperation>
13auto Transform(const std::vector<T>& container, UnaryOperation op)
14{
15 using transformed_t = std::remove_cvref_t<std::invoke_result_t<UnaryOperation, const T&>>;
16 auto out = std::vector<transformed_t>{};
17 out.reserve(container.size());
18 std::transform(std::cbegin(container), std::cend(container), std::back_inserter(out), op);
19 return out;
20}
21
23inline detail::enumerate_view_fn Enumerate;
24} // namespace nc::algo