Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions include/cib/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
#include <stdx/compiler.hpp>

namespace cib {
/**
* List of arguments to configure compile-time initialization of components.
*
* @see cib::conditional
*/
template <auto... Args> constexpr static detail::args<Args...> args{};

/**
* Container for project and component configuration declarations.
*
Expand All @@ -32,13 +25,7 @@ template <auto... Args> constexpr static detail::args<Args...> args{};
*/
template <typename... Configs>
[[nodiscard]] CONSTEVAL auto config(Configs const &...configs) {
return detail::config{args<>, configs...};
}

template <auto... Args, typename... Configs>
[[nodiscard]] CONSTEVAL auto config(detail::args<Args...> config_args,
Configs const &...configs) {
return detail::config{config_args, configs...};
return detail::config{configs...};
}

/**
Expand All @@ -64,10 +51,6 @@ constexpr static detail::exports<Services...> exports{};
* @tparam Service
* Type name of the service to extend.
*
* @tparam ServiceTemplateArgs
* Template arguments to be passed to the service's
* builder add function.
*
* @param args
* Value arguments to be passed to the service's builder add function.
*/
Expand Down
10 changes: 4 additions & 6 deletions include/cib/detail/components.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
namespace cib::detail {
template <typename... Components>
struct components : public detail::config_item {
template <typename... Args>
[[nodiscard]] constexpr auto extends_tuple(Args const &...args) const {
return stdx::tuple_cat(Components::config.extends_tuple(args...)...);
[[nodiscard]] constexpr auto extends_tuple() const {
return stdx::tuple_cat(Components::config.extends_tuple()...);
}

template <typename... Args>
[[nodiscard]] constexpr auto exports_tuple(Args const &...args) const {
return stdx::tuple_cat(Components::config.exports_tuple(args...)...);
[[nodiscard]] constexpr auto exports_tuple() const {
return stdx::tuple_cat(Components::config.exports_tuple()...);
}
};
} // namespace cib::detail
18 changes: 8 additions & 10 deletions include/cib/detail/conditional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,22 @@ namespace cib::detail {
template <typename Pred, typename... Configs>
requires std::is_default_constructible_v<Pred>
struct conditional : config_item {
detail::config<detail::args<>, Configs...> body;
detail::config<Configs...> body;

CONSTEVAL explicit conditional(Configs const &...configs)
: body{{}, configs...} {}
: body{configs...} {}

template <typename... Args>
[[nodiscard]] constexpr auto extends_tuple(Args const &...) const {
if constexpr (Pred{}(Args{}...)) {
return body.extends_tuple(Args{}...);
[[nodiscard]] constexpr auto extends_tuple() const {
if constexpr (Pred{}()) {
return body.extends_tuple();
} else {
return stdx::tuple<>{};
}
}

template <typename... Args>
[[nodiscard]] constexpr auto exports_tuple(Args const &...) const {
if constexpr (Pred{}(Args{}...)) {
return body.exports_tuple(Args{}...);
[[nodiscard]] constexpr auto exports_tuple() const {
if constexpr (Pred{}()) {
return body.exports_tuple();
} else {
return stdx::tuple<>{};
}
Expand Down
21 changes: 6 additions & 15 deletions include/cib/detail/config_details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,21 @@ template <auto Value>
constexpr static auto as_constant_v =
std::integral_constant<std::remove_cvref_t<decltype(Value)>, Value>{};

template <auto... Args> struct args {};

template <typename...> struct config;

template <auto... ConfigArgs, typename... ConfigTs>
struct config<args<ConfigArgs...>, ConfigTs...> : public detail::config_item {
template <typename... ConfigTs> struct config : public detail::config_item {
stdx::tuple<ConfigTs...> configs_tuple;

CONSTEVAL explicit config(args<ConfigArgs...>, ConfigTs const &...configs)
CONSTEVAL explicit config(ConfigTs const &...configs)
: configs_tuple{configs...} {}

template <typename... Args>
[[nodiscard]] constexpr auto extends_tuple(Args const &...args) const {
[[nodiscard]] constexpr auto extends_tuple() const {
return configs_tuple.apply([&](auto const &...configs_pack) {
return stdx::tuple_cat(configs_pack.extends_tuple(
args..., as_constant_v<ConfigArgs>...)...);
return stdx::tuple_cat(configs_pack.extends_tuple()...);
});
}

template <typename... Args>
[[nodiscard]] constexpr auto exports_tuple(Args const &...args) const {
[[nodiscard]] constexpr auto exports_tuple() const {
return configs_tuple.apply([&](auto const &...configs_pack) {
return stdx::tuple_cat(configs_pack.exports_tuple(
args..., as_constant_v<ConfigArgs>...)...);
return stdx::tuple_cat(configs_pack.exports_tuple()...);
});
}
};
Expand Down
8 changes: 2 additions & 6 deletions include/cib/detail/config_item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

namespace cib::detail {
struct config_item {
template <typename... Args>
[[nodiscard]] constexpr auto
extends_tuple(Args const &...) const -> stdx::tuple<> {
[[nodiscard]] constexpr auto extends_tuple() const -> stdx::tuple<> {
return {};
}

template <typename... InitArgs>
[[nodiscard]] constexpr auto
exports_tuple(InitArgs const &...) const -> stdx::tuple<> {
[[nodiscard]] constexpr auto exports_tuple() const -> stdx::tuple<> {
return {};
}
};
Expand Down
8 changes: 3 additions & 5 deletions include/cib/detail/exports.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ template <typename ServiceT, typename BuilderT> struct service_entry {
};

template <typename... Services> struct exports : public detail::config_item {
template <typename... InitArgs>
[[nodiscard]] constexpr auto extends_tuple(InitArgs const &...) const
-> stdx::tuple<extend<Services>...> {
[[nodiscard]] constexpr auto
extends_tuple() const -> stdx::tuple<extend<Services>...> {
return {extend<Services>{}...};
}

template <typename... InitArgs>
[[nodiscard]] constexpr auto
exports_tuple(InitArgs const &...) const -> stdx::tuple<Services...> {
exports_tuple() const -> stdx::tuple<Services...> {
return {};
}
};
Expand Down
4 changes: 1 addition & 3 deletions include/cib/detail/extend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ struct extend : public config_item {

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

template <typename... InitArgs>
[[nodiscard]] constexpr auto
extends_tuple(InitArgs const &...) const -> stdx::tuple<extend> {
[[nodiscard]] constexpr auto extends_tuple() const -> stdx::tuple<extend> {
return {*this};
}
};
Expand Down
28 changes: 14 additions & 14 deletions test/cib/nexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,17 @@ TEST_CASE("configuration with multiple components, services, and features") {
}
}

struct SimpleConditionalComponent {
template <auto V> struct SimpleConditionalComponent {

constexpr static auto config = cib::config(cib::conditional(
[]<typename Arg>(Arg) { return Arg::value == 42; },
[]() { return V == 42; },
cib::extend<TestCallback<0>>([]() { is_callback_invoked<0> = true; })));
};

template <int ConditionalValue> struct ConditionalTestProject {
constexpr static auto config =
cib::config(cib::args<ConditionalValue>, cib::exports<TestCallback<0>>,
cib::components<SimpleConditionalComponent>);
constexpr static auto config = cib::config(
cib::exports<TestCallback<0>>,
cib::components<SimpleConditionalComponent<ConditionalValue>>);
};

TEST_CASE("configuration with one conditional component") {
Expand All @@ -131,21 +132,20 @@ TEST_CASE("configuration with one conditional component") {
}
}

template <int Id> struct ConditionalComponent {
constexpr static auto config = cib::config(
cib::conditional([]<typename Arg>(Arg) { return Arg::value == Id; },
cib::extend<TestCallback<Id>>(
[]() { is_callback_invoked<Id> = true; })));
template <int EnId, int Id> struct ConditionalComponent {
constexpr static auto config = cib::config(cib::conditional(
[]() { return EnId == Id; }, cib::extend<TestCallback<Id>>([]() {
is_callback_invoked<Id> = true;
})));
};

template <int EnabledId> struct ConditionalConfig {
constexpr static auto config = cib::config(
cib::args<EnabledId>,

cib::exports<TestCallback<0>, TestCallback<1>, TestCallback<2>>,

cib::components<ConditionalComponent<0>, ConditionalComponent<1>,
ConditionalComponent<2>>);
cib::components<ConditionalComponent<EnabledId, 0>,
ConditionalComponent<EnabledId, 1>,
ConditionalComponent<EnabledId, 2>>);
};

TEST_CASE("configuration with conditional features") {
Expand Down