Skip to content

Commit 0cdb25e

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

File tree

8 files changed

+34
-68
lines changed

8 files changed

+34
-68
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: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,22 @@ 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>
17+
struct config : public detail::config_item {
2218
stdx::tuple<ConfigTs...> configs_tuple;
2319

24-
CONSTEVAL explicit config(args<ConfigArgs...>, ConfigTs const &...configs)
20+
CONSTEVAL explicit config(ConfigTs const &...configs)
2521
: configs_tuple{configs...} {}
2622

27-
template <typename... Args>
28-
[[nodiscard]] constexpr auto extends_tuple(Args const &...args) const {
23+
[[nodiscard]] constexpr auto extends_tuple() const {
2924
return configs_tuple.apply([&](auto const &...configs_pack) {
30-
return stdx::tuple_cat(configs_pack.extends_tuple(
31-
args..., as_constant_v<ConfigArgs>...)...);
25+
return stdx::tuple_cat(configs_pack.extends_tuple()...);
3226
});
3327
}
3428

35-
template <typename... Args>
36-
[[nodiscard]] constexpr auto exports_tuple(Args const &...args) const {
29+
[[nodiscard]] constexpr auto exports_tuple() const {
3730
return configs_tuple.apply([&](auto const &...configs_pack) {
38-
return stdx::tuple_cat(configs_pack.exports_tuple(
39-
args..., as_constant_v<ConfigArgs>...)...);
31+
return stdx::tuple_cat(configs_pack.exports_tuple()...);
4032
});
4133
}
4234
};

include/cib/detail/config_item.hpp

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

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

13-
template <typename... InitArgs>
1412
[[nodiscard]] constexpr auto
15-
exports_tuple(InitArgs const &...) const -> stdx::tuple<> {
13+
exports_tuple() const -> stdx::tuple<> {
1614
return {};
1715
}
1816
};

include/cib/detail/exports.hpp

Lines changed: 2 additions & 4 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
15+
[[nodiscard]] constexpr auto extends_tuple() const
1716
-> 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ struct extend : public config_item {
1515

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

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

test/cib/nexus.cpp

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

102+
template<auto V>
102103
struct SimpleConditionalComponent {
104+
103105
constexpr static auto config = cib::config(cib::conditional(
104-
[]<typename Arg>(Arg) { return Arg::value == 42; },
106+
[]() { return V == 42; },
105107
cib::extend<TestCallback<0>>([]() { is_callback_invoked<0> = true; })));
106108
};
107109

108110
template <int ConditionalValue> struct ConditionalTestProject {
109111
constexpr static auto config =
110-
cib::config(cib::args<ConditionalValue>, cib::exports<TestCallback<0>>,
111-
cib::components<SimpleConditionalComponent>);
112+
cib::config(cib::exports<TestCallback<0>>,
113+
cib::components<SimpleConditionalComponent<ConditionalValue>>);
112114
};
113115

114116
TEST_CASE("configuration with one conditional component") {
@@ -131,21 +133,19 @@ TEST_CASE("configuration with one conditional component") {
131133
}
132134
}
133135

134-
template <int Id> struct ConditionalComponent {
136+
template <int EnId, int Id> struct ConditionalComponent {
135137
constexpr static auto config = cib::config(
136-
cib::conditional([]<typename Arg>(Arg) { return Arg::value == Id; },
138+
cib::conditional([]() { return EnId == Id; },
137139
cib::extend<TestCallback<Id>>(
138140
[]() { is_callback_invoked<Id> = true; })));
139141
};
140142

141143
template <int EnabledId> struct ConditionalConfig {
142144
constexpr static auto config = cib::config(
143-
cib::args<EnabledId>,
144-
145145
cib::exports<TestCallback<0>, TestCallback<1>, TestCallback<2>>,
146146

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

151151
TEST_CASE("configuration with conditional features") {

0 commit comments

Comments
 (0)