-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuple.hpp
69 lines (55 loc) · 1.22 KB
/
tuple.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
#pragma once
#include<utility> // std::forward
#include"get.hpp" // mlib::get
namespace mlib
{
template<std::size_t i>
struct index {};
template<typename T, typename... Ts>
struct tuple
{
T first{};
tuple<Ts...> second{};
auto operator==(tuple<T, Ts...>& t)
{
return first == t.first && second == t.second;
}
auto operator==(auto& t)
{
return false;
}
template <std::size_t I>
decltype(auto) operator[](index<I>)
{
return mlib::get<I>(*this);
}
};
template<typename T>
struct tuple<T>
{
T first{};
};
template<typename... Types>
constexpr auto make_tuple(Types... types)
{
return tuple<Types...>{std::forward<Types...>(types...)};
}
template<typename Type>
constexpr auto make_tuple(Type type)
{
return tuple<Type>{std::forward<Type>(type)};
}
template< int I, typename T >
struct tuple_element;
template< int I, typename Head, typename... Tail >
struct tuple_element<I, tuple<Head, Tail...>> : tuple_element<I - 1, tuple<Tail...>>
{
};
template< typename Head, typename... Tail >
struct tuple_element<0, tuple<Head, Tail...>>
{
using type = Head;
};
template<int I, typename... Ts>
using tuple_element_t = tuple_element<I, Ts...>::type;
} // namespace mlib