C++ Logo

sg14

Advanced search

Re: [isocpp-sg14] Introducing `Embedded Function` - A Heap-Free Function Wrapper

From: Kim J. Smith <ycjin_kim_at_[hidden]>
Date: Sat, 15 Aug 2026 23:01:28 +0800 (CST)
Thanks for your feedback. I'm sorry that I misled you into thinking that I want to distribute this library.



In fact, I just want to use this library to talk about some insufficient parts of the previous standardization work and how I solve them.


First of all, I have to make sure we are talking about the same thing, the `stdext::inplace_function` in <https://github.com/WG21-SG14/SG14/blob/master/SG14/inplace_function.h>.


1. Now `class inplace_function<R(Args...), Capacity, Alignment>` does not support function signatures that are qualified with `const`, `&`, `&&`, or `noexcept`, which means it makes the same mistake that `std::function` has made and has been reported in N4159. Supporting them is my suggestion.


2. Since `std::copyable_function` and `std::move_only_function` have been added into the standard, the `inplace_function` and `inplace_move_only_function` are both necessary for semantic completeness. Providing them is my suggestion.


3. Now `inplace_function` does not use `std::invoke` to implement its `operator()` because C++11 didn't provide it. However, this is why `inplace_function<void()>` cannot be created from `int(*)()` and results in a different behavior compared to `std::function` or `std::copyable_function`. Using `std::invoke` or some way to keep the behavior consistent with `std::function` is my suggestion.


4. Now `inplace_function` uses `invoke_ptr{ [](storage_ptr_t, Args&&...) -> R { ... } }` and misses the passing‑parameters‑by‑register optimization. Implementing this optimization is my suggestion.


5. Now `inplace_function` puts `invoke_ptr` into the `vtable`, which can reduce the wrapper size and slightly enhance the performance of copy, move and swap. However, it reduces the performance of invocation because it adds one more memory access operation during each invocation. Removing it from the `vtable` is my suggestion.


I have to point out that the core file `embed_function.hpp` in `Embedded-Function` is 100% written by human. The only occasion where AI (LLM) was engaged is that I use it to review the documents and mark the outdated chapters before I release a new version.


I introduce `Embedded-Function` to prove that all my suggestions are not just ideas, but have been written into C++ code and checked by benchmarks.



At 2026-08-15 21:56:27, "Andre Kostur" <andre_at_[hidden]> wrote:
>There may be a misunderstanding as to the role of SG14, and WG21: we
>are not a mechanism for distributing libraries, we are trying to
>improve/extend the specification of the C++ language (and in the case
>of SG14, with a focus on embedded, financial, and gamedev). So what
>we'd want to see is a description of what the proposed thing is
>supposed to do. An implementation may be useful to exercise the
>proposal, but it is not the focus of this group. As you've
>mentioned, there has been previous standardization work in this area:
>it would probably be good to discuss why that previous work is
>insufficient, and how yours extends it.
>
>Also: please disclose the role/use of AI in this project.
>
>On Sat, Aug 15, 2026 at 5:32 AM ycjin_kim via SG14
><sg14_at_[hidden]> wrote:
>>
>> Hi SG14,
>>
>> My name is Kim, a developer interested in embedded systems. I'd like to share a project I've been working on called "Embedded Function" and get the group's feedback.
>>
>> **Project Introduction**
>> `Embedded Function` is a lightweight, header-only library that provides a collection of heap-free polymorphic function wrappers (like `ebd::fn`, `ebd::unique_fn`, `ebd::fn_ref`). It's designed for resource-constrained or high-performance environments like game development and embedded systems. The library is freestanding, supports C++11 through C++26, and offers several performance optimizations like branch elimination and zero-stack overhead. It contains only one header file, so it is Godbolt friendly.
>>
>> **Why I'm sharing this with SG14**
>> I understand that SG14 has been interested in a non-allocating `inplace_function` for a long time. While the `stdext::inplace_function` implementation exists in the SG14 repository, it seems the standardization effort has not progressed recently. My library aims to be a modern, production-ready alternative. It offers several variants (`fn`, `unique_fn`, `classic_fn`, `fn_ref`) to cover different use cases, similar to what `std::function`, `std::copyable_function`, and `std::function_ref` provide.
>>
>> I believe `Embedded Function` could serve as a valuable data point or even a potential reference implementation for any future standardization efforts in this area.
>>
>> **Questions for the group**
>> - Does the direction of `Embedded Function` align with what SG14 envisions for a standard `inplace_function`?
>> - Are there any features or design choices you think are missing or could be improved?
>> - What would be the best way to contribute this work to the ongoing discussion?
>>
>> The project is open-source on GitHub: https://github.com/Kim-J-Smith/Embedded-Function. I'd be very grateful for any feedback, suggestions, or criticism.
>>
>> Best regards,
>> Kim J. Smith
>>
>> _______________________________________________
>> SG14 mailing list
>> SG14_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/sg14

Received on 2026-08-15 15:01:47