-
Notifications
You must be signed in to change notification settings - Fork 0
/
pair.h
133 lines (120 loc) · 3.03 KB
/
pair.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once
#ifndef KIGU_PAIR_H
#define KIGU_PAIR_H
//base case, never instantiated
template<typename... Dummy> struct pair;
template<typename T, typename U>
struct pair<T,U> {
T first;
U second;
pair(){ first={}; second={}; }
pair(T first, U second) {
this->first = first;
this->second = second;
}
};
template<typename T, typename U, typename V>
struct pair<T,U,V> {
T first;
U second;
V third;
pair(){ first={}; second={}; third={}; }
pair(T first, U second, V third) {
this->first = first;
this->second = second;
this->third = third;
}
};
template<typename T, typename U, typename V, typename W>
struct pair<T,U,V,W> {
T first;
U second;
V third;
W fourth;
pair(){ first={}; second={}; third={}; fourth={}; }
pair(T first, U second, V third, W fourth) {
this->first = first;
this->second = second;
this->third = third;
this->fourth = fourth;
}
};
template<typename T, typename U, typename V, typename W, typename X>
struct pair<T,U,V,W,X> {
T first;
U second;
V third;
W fourth;
X fifth;
pair(){ first={}; second={}; third={}; fourth={}; fifth={}; }
pair(T first, U second, V third, W fourth, X fifth) {
this->first = first;
this->second = second;
this->third = third;
this->fourth = fourth;
this->fifth = fifth;
}
};
template<typename T, typename U>
static pair<T, U> make_pair(const T& first, const U& second) {
return pair<T, U>(first, second);
}
//TODO make an index sequence thing of our own
#include <utility>
//TODO(sushi) for some reason cl started fussing about this when i updated MSVC, so figure out why if this struct is ever used again.
////from https://ldionne.com/2015/11/29/efficient-parameter-pack-indexing/
//template <std::size_t n, typename = std::make_index_sequence<n>>
//struct nth_element_impl;
//
//template <std::size_t n, std::size_t ...ignore>
//struct nth_element_impl<n, std::index_sequence<ignore...>> {
// template <typename Tn>
// static Tn f(decltype((void*)ignore)..., Tn*, ...);
//};
//
//template <typename T>
//struct wrapper { using type = T; };
//
//template <std::size_t n, typename ...T>
//using nth_element = typename decltype(
// nth_element_impl<n>::f(static_cast<wrapper<T>*>(0)...)
// )::type;
//
//template<typename... T>
//constexpr u64 Sum(){
// return (sizeof(T) + ...);
//}
//
//template<typename T, typename... Args>
//constexpr T RunConstructor(Args... args){
// return T(args...);
//}
//
//template<typename... T>
//struct tuple {
// u8 raw[Sum<T...>()];
// u64 offsets[sizeof...(T)];
// tuple(){
// u64 sum = 0, idx = 0;
// ((offsets[idx++] = sum,
// memcpy(((T*)&raw[sum]),
// &RunConstructor<T>(),
// sizeof(T)), sum+=sizeof(T)), ...);
// }
//
// tuple(T...args){
// u64 sum = 0, idx = 0;
// ((offsets[idx++] = sum, memcpy(((T*)&raw[sum]), &args, sizeof(T)), sum+=sizeof(T)), ...);
// }
//
// template<upt n>
// decltype(auto) get(){
// return *(nth_element<n, T...>*)&raw[offsets[n]];
// }
//
// template<upt n>
// decltype(auto) getptr(){
// return (nth_element<n, T...>*)&raw[offsets[n]];
// }
//};
#endif //KIGU_PAIR_H