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
9 changes: 8 additions & 1 deletion include/cib/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cib/detail/runtime_conditional.hpp>

#include <stdx/compiler.hpp>
#include <stdx/type_traits.hpp>

namespace cib {
/**
Expand Down Expand Up @@ -46,6 +47,12 @@ constexpr static detail::components<Components...> components{};
template <typename... Services>
constexpr static detail::exports<Services...> exports{};

namespace detail {
template <typename T>
using maybe_funcptr_t =
stdx::conditional_t<stdx::is_function_v<T>, std::decay_t<T>, T>;
}

/**
* Extend a service with new functionality.
*
Expand All @@ -57,7 +64,7 @@ constexpr static detail::exports<Services...> exports{};
*/
template <typename Service, typename... Args>
[[nodiscard]] CONSTEVAL auto extend(Args const &...args) {
return detail::extend<Service, Args...>{args...};
return detail::extend<Service, detail::maybe_funcptr_t<Args>...>{args...};
}

template <stdx::ct_string Name>
Expand Down
6 changes: 5 additions & 1 deletion test/cib/nexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ struct Foo {
cib::extend<TestCallback<2>>([]() { is_callback_invoked<2> = true; }));
};

namespace {
auto test_cb_1() { is_callback_invoked<1> = true; }
} // namespace

struct Bar {
constexpr static auto config = cib::config(
cib::extend<TestCallback<0>>([]() { is_callback_invoked<0> = true; }),
cib::extend<TestCallback<1>>([]() { is_callback_invoked<1> = true; }));
cib::extend<TestCallback<1>>(test_cb_1));
};

struct Gorp {
Expand Down
Loading