capydi
Loading...
Searching...
No Matches
ConfigClassifier.hpp
Go to the documentation of this file.
1#ifndef CONFIG_EXTRACTOR_HPP_
2#define CONFIG_EXTRACTOR_HPP_
3
9#include <utility>
10
11namespace capy::di
12{
13
15
17{
18 template<auto... Values>
19 struct NormalizedIntegerSequence {};
20
21 template<typename StdIndexSequence>
22 struct Normalize;
23
24 template<auto... Values>
25 struct Normalize<
26 std::integer_sequence<
27 std::size_t,
28 Values...
29 >
30 >
31 {
32 using type = NormalizedIntegerSequence<Values...>;
33 };
34
35 template<typename StdIndexSequence>
36 using normalize_t = typename Normalize<StdIndexSequence>::type;
37
38 template<
39 template<typename> typename Predicate
40 >
41 struct ConfigToIndexMapper
42 {
43 template<typename T>
44 struct Mapper;
45
46 template<typename Config, std::size_t Index>
47 struct Mapper<meta::Pack<Config, meta::ValueUnit<Index>>>
48 {
49 using type = std::conditional_t<
50 Predicate<Config>::value,
51 meta::ValueUnit<Index>,
52 meta::None
53 >;
54 };
55 };
56
57 template<
58 template<typename> typename Predicate,
59 typename... Configs
60 >
61 struct ConfigsToIndexSequence
62 {
63 using ConfigsPack = meta::Pack<Configs...>;
64
65 using ConfigsIndexSequence = std::index_sequence_for<Configs...>;
66 using NormalizedConfigsIndexSequence = normalize_t<ConfigsIndexSequence>;
67 using ConfigsIndicesPack = meta::rebind_valued_as_typed_t<
68 NormalizedConfigsIndexSequence,
69 NormalizedIntegerSequence,
70 meta::Pack
71 >;
72 using ConfigsToIndicesPack = meta::pack_zip_t<ConfigsPack, ConfigsIndicesPack>;
73
74 using type = meta::pack_filter_map_t<
75 ConfigsToIndicesPack,
76 meta::template_ft<
77 ConfigToIndexMapper<Predicate>::template Mapper,
78 meta::MetaArity::N1
79 >
80 >;
81 };
82
83 template<
84 template<typename> typename Predicate,
85 typename... Configs
86 >
87 using configs_to_index_sequence_pack_t = typename ConfigsToIndexSequence<
88 Predicate,
89 Configs...
90 >::type;
91
92
93 template<std::size_t... Idx, typename... Configs>
94 [[nodiscard]] constexpr auto
95 extract_config_tuple(
96 meta::Pack<meta::ValueUnit<Idx>...>&&,
97 Configs&... configs
98 )
99 {
100 std::tuple<Configs&...> configs_tuple = { configs... };
101 return std::tuple { std::move(std::get<Idx>(configs_tuple))... };
102 }
103}
104
106
107template<
108 template<typename> typename Predicate,
109 typename... Configs
110>
111[[nodiscard]] constexpr auto /* std::tuple<FiltratedConfigs...> */
114 Configs&... configs
115 ) noexcept
116{
117 using ConfigsIndexSequencePack =
118 implementation_details_::configs_to_index_sequence_pack_t<
119 Predicate,
120 Configs...
121 >;
122
123 return implementation_details_::extract_config_tuple(
124 ConfigsIndexSequencePack{},
125 configs...
126 );
127}
128
129}
130
131#endif // !CONFIG_EXTRACTOR_HPP_
Compile-time type pack utilities and metaprogramming foundations.
Definition DependencyTags.hpp:18
Definition Decorator.hpp:19
constexpr auto filter_configs(meta::UnaryMetaFunction< Predicate > &&predicates, Configs &... configs) noexcept
Definition ConfigClassifier.hpp:112
A tag for template template parameters representing unary predicates.
Definition Pack.hpp:131