Skip to content

Commit d80441b

Browse files
committed
remove cib config args, use template args instead
1 parent 924cab6 commit d80441b

File tree

8 files changed

+39
-77
lines changed

8 files changed

+39
-77
lines changed

include/cib/config.hpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
#include <stdx/compiler.hpp>
1212

1313
namespace cib {
14-
/**
15-
* List of arguments to configure compile-time initialization of components.
16-
*
17-
* @see cib::conditional
18-
*/
19-
template <auto... Args> constexpr static detail::args<Args...> args{};
20-
2114
/**
2215
* Container for project and component configuration declarations.
2316
*
@@ -32,13 +25,7 @@ template <auto... Args> constexpr static detail::args<Args...> args{};
3225
*/
3326
template <typename... Configs>
3427
[[nodiscard]] CONSTEVAL auto config(Configs const &...configs) {
35-
return detail::config{args<>, configs...};
36-
}
37-
38-
template <auto... Args, typename... Configs>
39-
[[nodiscard]] CONSTEVAL auto config(detail::args<Args...> config_args,
40-
Configs const &...configs) {
41-
return detail::config{config_args, configs...};
28+
return detail::config{configs...};
4229
}
4330

4431
/**
@@ -64,10 +51,6 @@ constexpr static detail::exports<Services...> exports{};
6451
* @tparam Service
6552
* Type name of the service to extend.
6653
*
67-
* @tparam ServiceTemplateArgs
68-
* Template arguments to be passed to the service's
69-
* builder add function.
70-
*
7154
* @param args
7255
* Value arguments to be passed to the service's builder add function.
7356
*/

include/cib/detail/components.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
namespace cib::detail {
88
template <typename... Components>
99
struct components : public detail::config_item {
10-
template <typename... Args>
11-
[[nodiscard]] constexpr auto extends_tuple(Args const &...args) const {
12-
return stdx::tuple_cat(Components::config.extends_tuple(args...)...);
10+
[[nodiscard]] constexpr auto extends_tuple() const {
11+
return stdx::tuple_cat(Components::config.extends_tuple()...);
1312
}
1413

15-
template <typename... Args>
16-
[[nodiscard]] constexpr auto exports_tuple(Args const &...args) const {
17-
return stdx::tuple_cat(Components::config.exports_tuple(args...)...);
14+
[[nodiscard]] constexpr auto exports_tuple() const {
15+
return stdx::tuple_cat(Components::config.exports_tuple()...);
1816
}
1917
};
2018
} // namespace cib::detail

include/cib/detail/conditional.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,22 @@ namespace cib::detail {
1010
template <typename Pred, typename... Configs>
1111
requires std::is_default_constructible_v<Pred>
1212
struct conditional : config_item {
13-
detail::config<detail::args<>, Configs...> body;
13+
detail::config<Configs...> body;
1414

1515
CONSTEVAL explicit conditional(Configs const &...configs)
16-
: body{{}, configs...} {}
16+
: body{configs...} {}
1717

18-
template <typename... Args>
19-
[[nodiscard]] constexpr auto extends_tuple(Args const &...) const {
20-
if constexpr (Pred{}(Args{}...)) {
21-
return body.extends_tuple(Args{}...);
18+
[[nodiscard]] constexpr auto extends_tuple() const {
19+
if constexpr (Pred{}()) {
20+
return body.extends_tuple();
2221
} else {
2322
return stdx::tuple<>{};
2423
}
2524
}
2625

27-
template <typename... Args>
28-
[[nodiscard]] constexpr auto exports_tuple(Args const &...) const {
29-
if constexpr (Pred{}(Args{}...)) {
30-
return body.exports_tuple(Args{}...);
26+
[[nodiscard]] constexpr auto exports_tuple() const {
27+
if constexpr (Pred{}()) {
28+
return body.exports_tuple();
3129
} else {
3230
return stdx::tuple<>{};
3331
}

include/cib/detail/config_details.hpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,21 @@ template <auto Value>
1313
constexpr static auto as_constant_v =
1414
std::integral_constant<std::remove_cvref_t<decltype(Value)>, Value>{};
1515

16-
template <auto... Args> struct args {};
17-
18-
template <typename...> struct config;
19-
20-
template <auto... ConfigArgs, typename... ConfigTs>
21-
struct config<args<ConfigArgs...>, ConfigTs...> : public detail::config_item {
16+
template <typename... ConfigTs> struct config : public detail::config_item {
2217
stdx::tuple<ConfigTs...> configs_tuple;
2318

24-
CONSTEVAL explicit config(args<ConfigArgs...>, ConfigTs const &...configs)
19+
CONSTEVAL explicit config(ConfigTs const &...configs)
2520
: configs_tuple{configs...} {}
2621

27-
template <typename... Args>
28-
[[nodiscard]] constexpr auto extends_tuple(Args const &...args) const {
22+
[[nodiscard]] constexpr auto extends_tuple() const {
2923
return configs_tuple.apply([&](auto const &...configs_pack) {
30-
return stdx::tuple_cat(configs_pack.extends_tuple(
31-
args..., as_constant_v<ConfigArgs>...)...);
24+
return stdx::tuple_cat(configs_pack.extends_tuple()...);
3225
});
3326
}
3427

35-
template <typename... Args>
36-
[[nodiscard]] constexpr auto exports_tuple(Args const &...args) const {
28+
[[nodiscard]] constexpr auto exports_tuple() const {
3729
return configs_tuple.apply([&](auto const &...configs_pack) {
38-
return stdx::tuple_cat(configs_pack.exports_tuple(
39-
args..., as_constant_v<ConfigArgs>...)...);
30+
return stdx::tuple_cat(configs_pack.exports_tuple()...);
4031
});
4132
}
4233
};

include/cib/detail/config_item.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44

55
namespace cib::detail {
66
struct config_item {
7-
template <typename... Args>
8-
[[nodiscard]] constexpr auto
9-
extends_tuple(Args const &...) const -> stdx::tuple<> {
7+
[[nodiscard]] constexpr auto extends_tuple() const -> stdx::tuple<> {
108
return {};
119
}
1210

13-
template <typename... InitArgs>
14-
[[nodiscard]] constexpr auto
15-
exports_tuple(InitArgs const &...) const -> stdx::tuple<> {
11+
[[nodiscard]] constexpr auto exports_tuple() const -> stdx::tuple<> {
1612
return {};
1713
}
1814
};

include/cib/detail/exports.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ template <typename ServiceT, typename BuilderT> struct service_entry {
1212
};
1313

1414
template <typename... Services> struct exports : public detail::config_item {
15-
template <typename... InitArgs>
16-
[[nodiscard]] constexpr auto extends_tuple(InitArgs const &...) const
17-
-> stdx::tuple<extend<Services>...> {
15+
[[nodiscard]] constexpr auto
16+
extends_tuple() const -> stdx::tuple<extend<Services>...> {
1817
return {extend<Services>{}...};
1918
}
2019

21-
template <typename... InitArgs>
2220
[[nodiscard]] constexpr auto
23-
exports_tuple(InitArgs const &...) const -> stdx::tuple<Services...> {
21+
exports_tuple() const -> stdx::tuple<Services...> {
2422
return {};
2523
}
2624
};

include/cib/detail/extend.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ struct extend : public config_item {
1515

1616
CONSTEVAL explicit extend(Args const &...args) : args_tuple{args...} {}
1717

18-
template <typename... InitArgs>
19-
[[nodiscard]] constexpr auto
20-
extends_tuple(InitArgs const &...) const -> stdx::tuple<extend> {
18+
[[nodiscard]] constexpr auto extends_tuple() const -> stdx::tuple<extend> {
2119
return {*this};
2220
}
2321
};

test/cib/nexus.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,17 @@ TEST_CASE("configuration with multiple components, services, and features") {
9999
}
100100
}
101101

102-
struct SimpleConditionalComponent {
102+
template <auto V> struct SimpleConditionalComponent {
103+
103104
constexpr static auto config = cib::config(cib::conditional(
104-
[]<typename Arg>(Arg) { return Arg::value == 42; },
105+
[]() { return V == 42; },
105106
cib::extend<TestCallback<0>>([]() { is_callback_invoked<0> = true; })));
106107
};
107108

108109
template <int ConditionalValue> struct ConditionalTestProject {
109-
constexpr static auto config =
110-
cib::config(cib::args<ConditionalValue>, cib::exports<TestCallback<0>>,
111-
cib::components<SimpleConditionalComponent>);
110+
constexpr static auto config = cib::config(
111+
cib::exports<TestCallback<0>>,
112+
cib::components<SimpleConditionalComponent<ConditionalValue>>);
112113
};
113114

114115
TEST_CASE("configuration with one conditional component") {
@@ -131,21 +132,20 @@ TEST_CASE("configuration with one conditional component") {
131132
}
132133
}
133134

134-
template <int Id> struct ConditionalComponent {
135-
constexpr static auto config = cib::config(
136-
cib::conditional([]<typename Arg>(Arg) { return Arg::value == Id; },
137-
cib::extend<TestCallback<Id>>(
138-
[]() { is_callback_invoked<Id> = true; })));
135+
template <int EnId, int Id> struct ConditionalComponent {
136+
constexpr static auto config = cib::config(cib::conditional(
137+
[]() { return EnId == Id; }, cib::extend<TestCallback<Id>>([]() {
138+
is_callback_invoked<Id> = true;
139+
})));
139140
};
140141

141142
template <int EnabledId> struct ConditionalConfig {
142143
constexpr static auto config = cib::config(
143-
cib::args<EnabledId>,
144-
145144
cib::exports<TestCallback<0>, TestCallback<1>, TestCallback<2>>,
146145

147-
cib::components<ConditionalComponent<0>, ConditionalComponent<1>,
148-
ConditionalComponent<2>>);
146+
cib::components<ConditionalComponent<EnabledId, 0>,
147+
ConditionalComponent<EnabledId, 1>,
148+
ConditionalComponent<EnabledId, 2>>);
149149
};
150150

151151
TEST_CASE("configuration with conditional features") {

0 commit comments

Comments
 (0)