-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.hpp
89 lines (68 loc) · 2.62 KB
/
pack.hpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include <cstddef>
#include <iostream>
#include <utility>
#include <tuple>
#include"get_nth_element.hpp"
#include"constant_parameter.hpp"
namespace mlib {
template <typename T>
struct type_holder {};
template <auto I>
struct index_pack {};
template <typename... Ts>
struct type_pack {
static constexpr auto pack_size = (sizeof(Ts) + ... + 0);
using start_type = decltype(mlib::get_nth_element<0>((Ts{})...));
using end_type = decltype(mlib::get_nth_element<(pack_size - (pack_size - 1)) / 2>((Ts{})...));
static constexpr auto start_value =
decltype(mlib::get_nth_element<0>((Ts{})...)){};
static constexpr auto end_value =
decltype(mlib::get_nth_element<(pack_size - (pack_size - 1)) / 2>((Ts{})...)){};
constexpr auto begin() { return start_value; }
constexpr auto end() { return end_value; }
template <auto I>
constexpr auto operator[](mlib::constexpr_parameter<I>) {
return mlib::get_nth_element<I>((Ts{})...);
}
template <auto T>
constexpr auto get() {
return mlib::get_nth_element<T>((Ts{})...);
}
constexpr type_pack() {}
};
template <auto... Ts>
struct value_pack {
static constexpr auto begin_value = mlib::get_nth_element<0>(Ts...);
static constexpr auto end_value =
mlib::get_nth_element<sizeof...(Ts) - 1>(Ts...);
static constexpr auto size_value = sizeof...(Ts) - 1;
constexpr auto size() { return size_value; }
constexpr auto begin() { return begin_value; }
constexpr auto end() { return end_value; };
template <auto I>
constexpr auto operator[](constexpr_parameter<I>) {
return mlib::get_nth_element<I>(Ts...);
}
template<auto... i>
constexpr auto for_each_helper(auto& lambda, std::index_sequence<i...>)
{
return mlib::value_pack<lambda(mlib::get_nth_element<i>(Ts...))...>{};
}
constexpr auto for_each(auto& lambda)
{
return for_each_helper(lambda, std::make_index_sequence < sizeof...(Ts)>{});
}
template <auto I>
constexpr auto get() {
return mlib::get_nth_element<I>(Ts...);
}
template<std::size_t... indexes>
constexpr auto select(std::index_sequence<indexes...> i_s)
{
return value_pack<(mlib::get_nth_element<indexes>(Ts...))...>{};
}
constexpr value_pack() { /*Does Nothing!*/}
constexpr auto tuple() { return std::tuple{Ts...}; }
};
} // namespace mlib