repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1#pragma once
2#include <utility>
3#include <cstddef>
4#include "pack.h"
5
6namespace librepr {
7
8template <template <typename...> class List, typename... Ts>
10private:
11 template <std::size_t Idx>
12 using do_split = pack::Split<Idx, List<Ts...>>;
13
14public:
15 constexpr static std::size_t size = sizeof...(Ts);
16
17 template <template <typename> class F>
18 using map = List<F<Ts>...>;
19
20 template <template <typename> class F>
22
23 template <std::size_t Idx>
24 requires(sizeof...(Ts) > 0 && Idx < sizeof...(Ts))
25 using get = typename pack::Split<Idx, List<Ts...>>::type;
26
27 template <std::size_t Idx>
29
30 template <std::size_t Idx>
31 using head = typename do_split<Idx>::head;
32
33 template <std::size_t Idx>
34 using tail = typename do_split<Idx>::tail;
35
36 template <typename T>
37 using append = List<Ts..., T>;
38
39 template <typename T>
40 using prepend = List<T, Ts...>;
41
42 template <template <typename...> class T>
43 using to = T<Ts...>;
44
45 template <typename F, typename... Args>
46 constexpr static decltype(auto) invoke(F&& callable, Args&&... args) {
47 return callable.template operator()<Ts...>(std::forward<Args>(args)...);
48 }
49
50 template <typename F, typename... Args>
51 constexpr static void for_each(F&& callable, Args&&... args) {
52 (callable.template operator()<Ts>(std::forward<Args>(args)...), ...);
53 }
54
55 template <typename F, typename... Args>
56 constexpr static void enumerate(F&& callable, Args&&... args) {
58 (callable.template operator()<get<Idx>, Idx>(std::forward<Args>(args)...), ...);
60 }
61};
62
63template <typename... Ts>
64struct TypeList : TypeListBase<TypeList, Ts...> {};
65
66template <template <auto...> class List, auto... Vs>
68 constexpr static std::size_t size = sizeof...(Vs);
69
70 template <template <typename...> class T = TypeList>
71 using wrap = pack::wrap<T, Vs...>;
72
73 template <template <typename...> class T = TypeList>
74 using types = T<decltype(Vs)...>;
75
76 template <std::size_t Idx>
77 requires(sizeof...(Vs) > 0 && Idx < sizeof...(Vs))
78 constexpr static auto get = wrap<>::template get<Idx>::type::value;
79
80 template <std::size_t Idx>
82
83 template <std::size_t Idx>
86
87 template <std::size_t Idx>
88 using head = typename do_split<Idx>::head;
89
90 template <std::size_t Idx>
91 using tail = typename do_split<Idx>::tail;
92
93 template <auto V>
94 using append = List<Vs..., V>;
95
96 template <auto V>
97 using prepend = List<V, Vs...>;
98
99 template <template <auto...> class T>
100 using to = T<Vs...>;
101
102 template <typename F, typename... Args>
103 constexpr static decltype(auto) invoke(F&& callable, Args&&... args) {
104 return callable.template operator()<Vs...>(std::forward<Args>(args)...);
105 }
106
107 template <typename F, typename... Args>
108 constexpr static void for_each(F&& callable, Args&&... args) {
109 (callable.template operator()<Vs>(std::forward<Args>(args)...), ...);
110 }
111
112 template <typename F, typename... Args>
113 constexpr static void enumerate(F&& callable, Args&&... args) {
115 (callable.template operator()<get<Idx>, Idx>(std::forward<Args>(args)...), ...);
116 }(std::make_index_sequence<sizeof...(Vs)>{});
117 }
118};
119
120template <auto... Vs>
121struct ValueList : ValueListBase<ValueList, Vs...> {};
122
123} // namespace librepr
typename detail::UnwrapValue< List, T >::type unwrap
Definition pack.h:87
List< ValueWrapper< Vs >... > wrap
Definition pack.h:84
Definition ctvi/ctvi.h:9
std::string code_for()
Definition repr:39
Definition list.h:9
static constexpr void enumerate(F &&callable, Args &&... args)
Definition list.h:56
List< F< Ts >... > map
Definition list.h:18
List< Ts..., T > append
Definition list.h:37
T< Ts... > to
Definition list.h:43
typename pack::Split< Idx, List< Ts... > >::type get
Definition list.h:25
List< typename F< Ts >::type... > map_t
Definition list.h:21
List< typename do_split< Idx >::head, typename do_split< Idx >::tail > split
Definition list.h:28
List< T, Ts... > prepend
Definition list.h:40
static constexpr decltype(auto) invoke(F &&callable, Args &&... args)
Definition list.h:46
typename do_split< Idx >::head head
Definition list.h:31
typename do_split< Idx >::tail tail
Definition list.h:34
static constexpr void for_each(F &&callable, Args &&... args)
Definition list.h:51
static constexpr std::size_t size
Definition list.h:15
Definition list.h:64
Definition list.h:67
T< decltype(Vs)... > types
Definition list.h:74
List< V, Vs... > prepend
Definition list.h:97
static constexpr void for_each(F &&callable, Args &&... args)
Definition list.h:108
static constexpr std::size_t size
Definition list.h:68
typename do_split< Idx >::tail tail
Definition list.h:91
pack::wrap< T, Vs... > wrap
Definition list.h:71
List< Vs..., V > append
Definition list.h:94
static constexpr auto get
Definition list.h:78
static constexpr void enumerate(F &&callable, Args &&... args)
Definition list.h:113
T< Vs... > to
Definition list.h:100
static constexpr decltype(auto) invoke(F &&callable, Args &&... args)
Definition list.h:103
typename do_split< Idx >::head head
Definition list.h:88
Definition list.h:121
List< Ts... > head
Definition pack.h:25
Definition pack.h:20