1 | #ifndef TUPLE_SUBSCRIPT_H
|
---|
2 | #define TUPLE_SUBSCRIPT_H
|
---|
3 |
|
---|
4 | #include <tuple>
|
---|
5 |
|
---|
6 | template< std::size_t > struct Number2Type { };
|
---|
7 |
|
---|
8 | template< class... Ts >
|
---|
9 | class tupless: public std::tuple<Ts...>
|
---|
10 | {
|
---|
11 | public:
|
---|
12 | template< class... ARGS >
|
---|
13 | tupless(ARGS... args): std::tuple<Ts...>(args...)
|
---|
14 | {
|
---|
15 | }
|
---|
16 | template< std::size_t N >
|
---|
17 | auto operator[](Number2Type<N>) const ->
|
---|
18 | decltype(std::get<N>(std::tuple<Ts...>())) const&
|
---|
19 | {
|
---|
20 | return std::get<N>(*this);
|
---|
21 | }
|
---|
22 | template< std::size_t N >
|
---|
23 | auto operator[](Number2Type<N>) ->
|
---|
24 | decltype(std::get<N>(std::tuple<Ts...>())) &
|
---|
25 | {
|
---|
26 | return std::get<N>(*this);
|
---|
27 | }
|
---|
28 | };
|
---|
29 |
|
---|
30 | template< int N >
|
---|
31 | constexpr std::size_t chars_to_int(const char (&array)[N], int current = 0, std::size_t acc = 0)
|
---|
32 | {
|
---|
33 | return (current >= N || array[current] == 0) ?
|
---|
34 | acc
|
---|
35 | : chars_to_int(array, current + 1, 10 * acc + array[current] - '0');
|
---|
36 | };
|
---|
37 |
|
---|
38 | template<char... Cs>
|
---|
39 | constexpr auto operator "" _t() -> Number2Type<chars_to_int((const char[1 + sizeof...(Cs)]){Cs..., '\0'})>
|
---|
40 | {
|
---|
41 | return {};
|
---|
42 | };
|
---|
43 |
|
---|
44 |
|
---|
45 | #endif //TUPLE_SUBSCRIPT_H
|
---|