From a5287d83aca741f6ceb3136ddc3955d6f7f47c7c Mon Sep 17 00:00:00 2001 From: Kim-J-Smith <3440910457@qq.com> Date: Fri, 15 May 2026 14:11:23 +0800 Subject: [PATCH 01/15] style: use function pointer size instead of pointer size. --- include/embed/embed_function.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/embed/embed_function.hpp b/include/embed/embed_function.hpp index 0193d99..4872cad 100644 --- a/include/embed/embed_function.hpp +++ b/include/embed/embed_function.hpp @@ -1105,7 +1105,7 @@ inline namespace fn_traits { // Get aligned size. Rounds up to the nearest word. template struct get_aligned_size { - static constexpr std::size_t min_aligned = sizeof(void*); + static constexpr std::size_t min_aligned = sizeof(void (*) ()); static constexpr std::size_t aligned_size = ((Size - 1) / min_aligned + 1) * min_aligned; static constexpr std::size_t value = Size == 0 ? min_aligned : aligned_size; }; From e7e6b2e396665b98875aa1fef29f974e8c0d91cb Mon Sep 17 00:00:00 2001 From: Kim-J-Smith <3440910457@qq.com> Date: Fri, 15 May 2026 14:24:42 +0800 Subject: [PATCH 02/15] perf: enhance the make_fn performance. See --- include/embed/embed_function.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/embed/embed_function.hpp b/include/embed/embed_function.hpp index 4872cad..c3cce96 100644 --- a/include/embed/embed_function.hpp +++ b/include/embed/embed_function.hpp @@ -2863,7 +2863,8 @@ namespace crtp_mixins { // Make a function. template - inline Fn make_function_impl(CArgs&&... args) noexcept(NoThrow) { + EMBED_CXX20_CONSTEXPR inline + Fn make_function_impl(CArgs&&... args) noexcept(NoThrow) { static_assert(is_ebd_fn::value, "Fn must be the alias of `ebd::detail::function`."); return Fn{std::forward(args)...}; @@ -3264,7 +3265,8 @@ EMBED_DETAIL_REQUIRES_END( detail::is_ebd_fn::value && detail::unwrap_signature::isSignature ) -EMBED_NODISCARD inline FnWrapper make_fn(Functor&& functor) noexcept(NoThrow) { +EMBED_NODISCARD EMBED_CXX20_CONSTEXPR inline +FnWrapper make_fn(Functor&& functor) noexcept(NoThrow) { return detail::make_function_impl< /* Fn = */ FnWrapper, /* NoThrow = */ NoThrow >(std::forward(functor)); From 19001e96b3ef2caa0dddc0e7fd528e699472e42c Mon Sep 17 00:00:00 2001 From: Kim-J-Smith <3440910457@qq.com> Date: Fri, 15 May 2026 15:48:41 +0800 Subject: [PATCH 03/15] feat: add make_fn_log_error to provide better error log for make_fn. --- include/embed/embed_function.hpp | 34 ++++++++++++------- .../fn_ref/conformance.addition.pass.cpp | 5 +-- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/include/embed/embed_function.hpp b/include/embed/embed_function.hpp index c3cce96..5a8b772 100644 --- a/include/embed/embed_function.hpp +++ b/include/embed/embed_function.hpp @@ -1589,6 +1589,20 @@ inline namespace fn_traits { template struct is_std_op_wrapper> : std::true_type {}; template struct is_std_op_wrapper> : std::true_type {}; + // Log error for make_fn. + template + EMBED_INLINE EMBED_CXX14_CONSTEXPR void make_fn_log_error() noexcept { + static_assert(always_false::value, + "[Embedded Function]: The make_fn() cannot automatically deduce an" + " appropriate function wrapper based on your input parameters." + " This might be because the parameters you passed are ambiguous," + " such as overloaded free functions, member functions, objects" + " that overload multiple operator() functions, nullptr, or just" + " non-parameters. If so, you can use 'make_fn(...)' to" + " specify the signature of target callable object to disambiguate." + " The 'Signature' is like 'void()', 'float(int,int)'." + ); + }; } // end namespace fn_traits // In the namespace "erasure_type", we define a series of @@ -3275,19 +3289,13 @@ FnWrapper make_fn(Functor&& functor) noexcept(NoThrow) { // When all other make_fn() fail to match the input parameters, // this function will be called as the fall back to avoid the // awful template error flood. -template -EMBED_INLINE void make_fn(...) noexcept { - static_assert(detail::always_false::value, - "[Embedded Function]: The make_fn() cannot automatically deduce an" - " appropriate function wrapper based on your input parameters." - " This might be because the parameters you passed are ambiguous," - " such as overloaded free functions, member functions, objects" - " that overload multiple operator() functions, nullptr, or just" - " non-parameters. If so, you can use 'make_fn()' to" - " specify the signature of target callable object to disambiguate." - " The 'Signature' is like 'void()', 'float(int,int)'." - ); -} +template ::isSignature)> +EMBED_INLINE EMBED_CXX14_CONSTEXPR void make_fn(...) noexcept +{ detail::make_fn_log_error(); } +template