-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.hpp
51 lines (50 loc) · 923 Bytes
/
node.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
#pragma once
namespace cxl {
struct NoneType
{
constexpr const static bool is_none = true;
template <int i>
constexpr auto get()
{
return NoneType{};
}
};
template <typename next, auto val>
struct Node
{
constexpr const static bool is_none = false;
using next_t = next;
constexpr const static auto node_v = val;
using node_t = decltype(val);
template <int i>
constexpr auto get() const noexcept
{
if constexpr (i <= 0)
return node_v;
else {
next_t tmp{};
auto a = next_t{}.template get<i-1>();
return a;
}
}
};
template <typename T>
constexpr auto first(T v)
{
return T::node_v;
}
template <typename T, auto v>
constexpr auto last(Node<T, v> val)
{
return last(T{});
}
template <auto v>
constexpr auto last(Node<NoneType, v> val)
{
return v;
}
constexpr auto empty_list()
{
return NoneType{};
}
}