summaryrefslogtreecommitdiff
path: root/lib/collections.hpp
blob: c9b0127c79cef9c690a9670275f165f063f88a47 (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
27
28
29
30
31
32
33
34
35
#pragma once

#include <array>

template<typename T, std::size_t first, std::size_t second>
constexpr std::array<T, first + second>
operator+(const std::array<T, first> & a, const std::array<T, second> & b)
{
	std::array<T, first + second> r;
	auto out = r.begin();
	out = std::copy(a.begin(), a.end(), out);
	std::copy(b.begin(), b.end(), out);
	return r;
}

template<typename T, std::size_t N>
constexpr auto
operator*(const std::array<T, N> & in, auto && f)
{
	std::array<decltype(f(in[0])), N> out;

	for (auto outitr = out.begin(); const auto & v : in) {
		*outitr++ = f(v);
	}
	return out;
}

template<typename T, std::size_t N>
constexpr auto &
operator*=(std::array<T, N> & in, auto && f)
{
	for (const auto & v : in) {
		f(v);
	}
}