Skip to content

Commit f936842

Browse files
authored
Merge pull request #736 from elbeno/fix-extend-funcptr
🐛 Fix extending `callback::service` with a function
2 parents 4976c0e + ba3d285 commit f936842

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

include/cib/config.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <cib/detail/runtime_conditional.hpp>
1010

1111
#include <stdx/compiler.hpp>
12+
#include <stdx/type_traits.hpp>
1213

1314
namespace cib {
1415
/**
@@ -46,6 +47,12 @@ constexpr static detail::components<Components...> components{};
4647
template <typename... Services>
4748
constexpr static detail::exports<Services...> exports{};
4849

50+
namespace detail {
51+
template <typename T>
52+
using maybe_funcptr_t =
53+
stdx::conditional_t<stdx::is_function_v<T>, std::decay_t<T>, T>;
54+
}
55+
4956
/**
5057
* Extend a service with new functionality.
5158
*
@@ -57,7 +64,7 @@ constexpr static detail::exports<Services...> exports{};
5764
*/
5865
template <typename Service, typename... Args>
5966
[[nodiscard]] CONSTEVAL auto extend(Args const &...args) {
60-
return detail::extend<Service, Args...>{args...};
67+
return detail::extend<Service, detail::maybe_funcptr_t<Args>...>{args...};
6168
}
6269

6370
template <stdx::ct_string Name>

test/cib/nexus.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ struct Foo {
4646
cib::extend<TestCallback<2>>([]() { is_callback_invoked<2> = true; }));
4747
};
4848

49+
namespace {
50+
auto test_cb_1() { is_callback_invoked<1> = true; }
51+
} // namespace
52+
4953
struct Bar {
5054
constexpr static auto config = cib::config(
5155
cib::extend<TestCallback<0>>([]() { is_callback_invoked<0> = true; }),
52-
cib::extend<TestCallback<1>>([]() { is_callback_invoked<1> = true; }));
56+
cib::extend<TestCallback<1>>(test_cb_1));
5357
};
5458

5559
struct Gorp {

0 commit comments

Comments
 (0)