Skip to content

Commit 639cad9

Browse files
authored
moved cib::args from a cib::conditional arg to cib::config (#28)
1 parent 40531a0 commit 639cad9

File tree

6 files changed

+40
-34
lines changed

6 files changed

+40
-34
lines changed

benchmark/big_nexus.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ struct BigConfig {
125125
constexpr static auto config =
126126
cib::config(
127127
cib::components<
128-
cib::args<>,
129128
TestComponent<0>,
130129
TestComponent<1>,
131130
TestComponent<2>,

include/cib/config.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace cib {
2525
* @see cib::conditional
2626
*/
2727
template<auto... Args>
28-
using args = detail::args<Args...>;
28+
constexpr static detail::args<Args...> args{};
2929

3030
/**
3131
* Container for project and component configuration declarations.
@@ -41,7 +41,12 @@ namespace cib {
4141
*/
4242
template<typename... Configs>
4343
[[nodiscard]] CIB_CONSTEVAL auto config(Configs const & ... configs) {
44-
return detail::config{configs...};
44+
return detail::config{args<>, configs...};
45+
}
46+
47+
template<auto... Args, typename... Configs>
48+
[[nodiscard]] CIB_CONSTEVAL auto config(detail::args<Args...> config_args, Configs const & ... configs) {
49+
return detail::config{config_args, configs...};
4550
}
4651

4752
/**

include/cib/detail/components.hpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,25 @@
1212

1313

1414
namespace cib::detail {
15-
template<typename ComponentArgs, typename... Components>
15+
template<typename... Components>
1616
struct components : public detail::config_item {
1717
template<typename Builders, typename... Args>
1818
[[nodiscard]] CIB_CONSTEVAL auto init(
1919
Builders const & builders_tuple,
2020
Args const & ... args
2121
) const {
22-
return apply([&](auto const & ... component_args){
23-
return detail::fold_right(ordered_set{Components{}...}, builders_tuple, [&](auto const & c, auto const & builders){
24-
return c.config.init(builders, args..., component_args...);
25-
});
26-
}, ComponentArgs::value);
22+
return detail::fold_right(ordered_set{Components{}...}, builders_tuple, [&](auto const & c, auto const & builders){
23+
return c.config.init(builders, args...);
24+
});
2725
}
2826

2927
template<typename... Args>
3028
[[nodiscard]] CIB_CONSTEVAL auto exports_tuple(
3129
Args const & ... args
3230
) const {
33-
return apply([&](auto const & ... component_args){
34-
return type_list_cat(Components::config.exports_tuple(args..., component_args...)...);
35-
}, ComponentArgs::value);
31+
return type_list_cat(Components::config.exports_tuple(args...)...);
3632
}
3733
};
38-
39-
template<auto Value>
40-
CIB_CONSTEXPR static auto as_constant_v = std::integral_constant<std::remove_cv_t<std::remove_reference_t<decltype(Value)>>, Value>{};
41-
42-
template<auto... Args>
43-
struct args {
44-
static CIB_CONSTEXPR auto value = ordered_set{as_constant_v<Args>...};
45-
};
4634
}
4735

4836

include/cib/detail/conditional.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "compiler.hpp"
22
#include "config_item.hpp"
3+
#include "config_details.hpp"
34
#include "ordered_set.hpp"
45
#include "type_list.hpp"
56

@@ -16,13 +17,13 @@ namespace cib::detail {
1617
typename... Configs>
1718
struct conditional : public config_item {
1819
CIB_CONSTEXPR static Condition condition{};
19-
detail::config<Configs...> body;
20+
detail::config<detail::args<>, Configs...> body;
2021

2122
CIB_CONSTEVAL explicit conditional(
2223
Condition,
2324
Configs const & ... configs
2425
)
25-
: body{configs...}
26+
: body{{}, configs...}
2627
{}
2728

2829
template<

include/cib/detail/config_details.hpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,20 @@
1212

1313

1414
namespace cib::detail {
15-
template<typename... ConfigTs>
15+
template<auto Value>
16+
CIB_CONSTEXPR static auto as_constant_v = std::integral_constant<std::remove_cv_t<std::remove_reference_t<decltype(Value)>>, Value>{};
17+
18+
template<auto... Args>
19+
struct args {
20+
static CIB_CONSTEXPR auto value = ordered_set{as_constant_v<Args>...};
21+
};
22+
23+
template<typename ConfigArgs, typename... ConfigTs>
1624
struct config : public detail::config_item {
1725
std::tuple<ConfigTs...> configs_tuple;
1826

1927
CIB_CONSTEVAL explicit config(
28+
ConfigArgs,
2029
ConfigTs const & ... configs
2130
)
2231
: configs_tuple{configs...}
@@ -29,18 +38,22 @@ namespace cib::detail {
2938
BuildersT const & builders_tuple,
3039
Args const & ... args
3140
) const {
32-
return fold_right(configs_tuple, builders_tuple, [&](auto const & c, auto builders){
33-
return c.init(builders, args...);
34-
});
41+
return apply([&](auto const & ... config_args){
42+
return fold_right(configs_tuple, builders_tuple, [&](auto const & c, auto builders){
43+
return c.init(builders, args..., config_args...);
44+
});
45+
}, ConfigArgs::value);
3546
}
3647

3748
template<typename... Args>
3849
[[nodiscard]] CIB_CONSTEVAL auto exports_tuple(
3950
Args const & ... args
4051
) const {
41-
return apply([&](auto const & ... configs_pack){
42-
return type_list_cat(configs_pack.exports_tuple(args...)...);
43-
}, configs_tuple);
52+
return apply([&](auto const & ... config_args){
53+
return apply([&](auto const & ... configs_pack){
54+
return type_list_cat(configs_pack.exports_tuple(args..., config_args...)...);
55+
}, configs_tuple);
56+
}, ConfigArgs::value);
4457
}
4558
};
4659
}

test/nexus.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct Gorp {
8686
struct MediumConfig {
8787
constexpr static auto config =
8888
cib::config(
89-
cib::components<cib::args<>, Foo, Bar, Gorp>
89+
cib::components<Foo, Bar, Gorp>
9090
);
9191
};
9292

@@ -161,10 +161,9 @@ template<int ConditionalValue>
161161
struct ConditionalTestProject {
162162
constexpr static auto config =
163163
cib::config(
164+
cib::args<ConditionalValue>,
164165
cib::exports<TestCallback<0>>,
165-
cib::components<
166-
cib::args<ConditionalValue>,
167-
SimpleConditionalComponent>
166+
cib::components<SimpleConditionalComponent>
168167
);
169168
};
170169

@@ -204,14 +203,15 @@ template<int EnabledId>
204203
struct ConditionalConfig {
205204
constexpr static auto config =
206205
cib::config(
206+
cib::args<EnabledId>,
207+
207208
cib::exports<
208209
TestCallback<0>,
209210
TestCallback<1>,
210211
TestCallback<2>
211212
>,
212213

213214
cib::components<
214-
cib::args<EnabledId>,
215215
ConditionalComponent<0>,
216216
ConditionalComponent<1>,
217217
ConditionalComponent<2>

0 commit comments

Comments
 (0)