-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
39 lines (28 loc) · 831 Bytes
/
utils.h
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
36
37
38
39
#ifndef UTILS_H
#define UTILS_H
#include <array>
namespace util
{
// sequence generation stuff
template <size_t... I>
struct seq {};
template <size_t N, size_t... I>
struct gen_seq : gen_seq<N-1, N-1, I...> {};
template <size_t... I>
struct gen_seq<0, I...> : seq<I...> {};
// array shifting
namespace impl
{
template <class T, size_t N, size_t K, size_t... I>
constexpr std::array<T, N> shift(const std::array<T, N> &a, const std::array<T, K> &b, seq<I...>)
{
return std::array<T, N> { (I < (N-K) ? a[I+K] : b[I-N+K])... };
}
}
template <class T, size_t N, size_t K>
constexpr std::array<T, N> shift(const std::array<T, N> &a, const std::array<T, K> &b)
{
return impl::shift(a, b, gen_seq<N>());
}
}
#endif