-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoinArray.h
More file actions
58 lines (43 loc) · 1.3 KB
/
JoinArray.h
File metadata and controls
58 lines (43 loc) · 1.3 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//code from github: https://gist.github.com/klemens-morgenstern/b75599292667a4f53007
//klemens-morgenstern
#ifndef JOINARRAY
#define JOINARRAY
namespace detail
{
template<std::size_t ... Size>
struct num_tuple
{
};
template<std::size_t Prepend, typename T>
struct appender {};
template<std::size_t Prepend, std::size_t ... Sizes>
struct appender<Prepend, num_tuple<Sizes...>>
{
using type = num_tuple<Prepend, Sizes...>;
};
template<std::size_t Size, std::size_t Counter = 0>
struct counter_tuple
{
using type = typename appender<Counter, typename counter_tuple<Size, Counter+1>::type>::type;
};
template<std::size_t Size>
struct counter_tuple<Size, Size>
{
using type = num_tuple<>;
};
}
namespace thirdparty
{
template<typename T, std::size_t LL, std::size_t RL, std::size_t ... LLs, std::size_t ... RLs>
constexpr std::array<T, LL+RL> join(const std::array<T, LL> rhs, const std::array<T, RL> lhs, detail::num_tuple<LLs...>, detail::num_tuple<RLs...>)
{
return {rhs[LLs]..., lhs[RLs]... };
};
template<typename T, std::size_t LL, std::size_t RL>
constexpr std::array<T, LL+RL> join(std::array<T, LL> rhs, std::array<T, RL> lhs)
{
//using l_t = typename detail::counter_tuple<LL>::type;
return join(rhs, lhs, typename detail::counter_tuple<LL>::type(), typename detail::counter_tuple<RL>::type());
}
}
#endif