From ba3d285e7ecb8267f727e06561af3cb65cc50f31 Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Tue, 10 Jun 2025 11:00:16 -0600 Subject: [PATCH] :bug: Fix extending `callback::service` with a function Problem: - `extend(f)` works fine when `f` is a lambda expression, but doesn't compile when `f` is a function. Solution: - Decay functions to function pointers to properly store them. --- include/cib/config.hpp | 9 ++++++++- test/cib/nexus.cpp | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/cib/config.hpp b/include/cib/config.hpp index 18de5505..20c5504f 100644 --- a/include/cib/config.hpp +++ b/include/cib/config.hpp @@ -9,6 +9,7 @@ #include #include +#include namespace cib { /** @@ -46,6 +47,12 @@ constexpr static detail::components components{}; template constexpr static detail::exports exports{}; +namespace detail { +template +using maybe_funcptr_t = + stdx::conditional_t, std::decay_t, T>; +} + /** * Extend a service with new functionality. * @@ -57,7 +64,7 @@ constexpr static detail::exports exports{}; */ template [[nodiscard]] CONSTEVAL auto extend(Args const &...args) { - return detail::extend{args...}; + return detail::extend...>{args...}; } template diff --git a/test/cib/nexus.cpp b/test/cib/nexus.cpp index 05a2f157..11abe93b 100644 --- a/test/cib/nexus.cpp +++ b/test/cib/nexus.cpp @@ -46,10 +46,14 @@ struct Foo { cib::extend>([]() { 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>([]() { is_callback_invoked<0> = true; }), - cib::extend>([]() { is_callback_invoked<1> = true; })); + cib::extend>(test_cb_1)); }; struct Gorp {