-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcharlist.hpp
60 lines (46 loc) · 1.48 KB
/
charlist.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
#pragma once
#include "typelist.hpp"
template <char val> struct char_t { static const constexpr char value {val}; };
template <char c, char ... chars>
struct char_tl;
template <char c, char ... chars>
struct char_tl {
using type = tl::tl<char_t<c>, typename char_tl<chars...>::type>;
};
template <char c>
struct char_tl<c> {
using type = tl::tl<char_t<c>, tl::null_t>;
};
template <char ... chars>
using char_tl_t = typename char_tl<chars...>::type;
template <class Str, size_t Pos, char C>
struct string_list;
template <class Str, size_t Pos, char C>
struct string_list {
using next_piece = typename string_list<
Str,
Pos + 1,
Str::str()[Pos + 1]
>::type;
using type = tl::tl<char_t<C>, next_piece>;
};
template <class Str, size_t Pos>
struct string_list<Str, Pos, '\0'> {
using type = tl::null_t;
};
template <class Str>
using string_list_t = typename string_list<Str, 0, Str::str()[0]>::type;
template <typename typelist, char ... chars>
struct tl_to_varlist;
template <char c, typename restlist, char ... chars>
struct tl_to_varlist<tl::tl<char_t<c>, restlist>, chars...>
: public tl_to_varlist<restlist, chars..., c>
{ };
template <char ... chars>
struct tl_to_varlist<tl::null_t, chars...> {
using list = char_tl<chars...>;
static const char * const str() {
static constexpr const char string[] = {chars..., '\0'};
return string;
}
};