repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
pack.h
Go to the documentation of this file.
1#pragma once
2#include <cstddef>
3#include <utility>
4
6#include "pack_generated.h"
7
8
9namespace librepr::pack {
10
11template <typename T, typename T2>
12struct Merge;
13
14template <template <typename...> class List, typename... T1, typename... T2>
15struct Merge<List<T1...>, List<T2...>> {
16 using type = List<T1..., T2...>;
17};
18
19template <std::size_t Idx, typename T>
20struct Split;
21
22template <std::size_t Idx, template <typename...> class List, typename... Ts>
23 requires(Idx == sizeof...(Ts))
25 using head = List<Ts...>;
26 using tail = List<>;
27};
28
29template <std::size_t Idx, template <typename...> class List, typename... Ts>
30 requires(Idx > MAX_SPEC)
31struct Split<Idx, List<Ts...>> {
32#if LIBREPR_HAS_BUILTIN(__type_pack_element)
33 using type = __type_pack_element<Idx, Ts...>;
34
36 constexpr static auto do_slice(std::index_sequence<indices...>) noexcept
38
39 using head = decltype(do_slice<0>(std::make_index_sequence<Idx + 1>{}));
40 using tail = decltype(do_slice<Idx + 1>(std::make_index_sequence<sizeof...(Ts) - (Idx + 1)>{}));
41#else
43 using recurse = Split<Idx - (MAX_SPEC + 1), typename first_page::tail>;
44
45 using tail = typename recurse::tail;
46 using type = typename recurse::type;
47
49#endif
50};
51
52namespace detail {
53template <template <auto...> class List, typename T>
55
56template <template <auto...> class ValueList, template <typename...> class TypeList, typename... Ts>
58 using type = ValueList<Ts::value...>;
59};
60
61template <typename, template <typename...> class>
62struct ReBoxImpl;
63
64template <template <typename...> class From, typename... Args, template <typename...> class To>
65struct ReBoxImpl<From<Args...>, To> {
66 using type = To<Args...>;
67};
68
69template <typename, template <auto...> class>
71
72template <template <auto...> class From, auto... Args, template <auto...> class To>
73struct ReBoxVImpl<From<Args...>, To> {
74 using type = To<Args...>;
75};
76} // namespace detail
77
78template <auto V>
80 constexpr static decltype(V) value = V;
81};
82
83template <template <typename...> class List, auto... Vs>
85
86template <template <auto...> class List, typename T>
88
89template <typename T, template <typename...> class To>
91
92template <typename T, template <auto...> class To>
94
95template <std::size_t Idx, typename T>
96using get = typename Split<Idx, T>::type;
97} // namespace librepr::pack
Definition pack.h:9
typename detail::UnwrapValue< List, T >::type unwrap
Definition pack.h:87
List< ValueWrapper< Vs >... > wrap
Definition pack.h:84
typename detail::ReBoxVImpl< T, To >::type rebox_v
Definition pack.h:93
typename Split< Idx, T >::type get
Definition pack.h:96
typename detail::ReBoxImpl< T, To >::type rebox
Definition pack.h:90
constexpr auto MAX_SPEC
Definition pack_generated.h:259
std::string code_for()
Definition repr:39
Definition list.h:64
Definition list.h:121
List< T1..., T2... > type
Definition pack.h:16
Definition pack.h:12
typename recurse::type type
Definition pack.h:46
List< Ts... > head
Definition pack.h:25
Definition pack.h:20
Definition pack.h:79
static constexpr decltype(V) value
Definition pack.h:80