C++ Logo

std-proposals

Advanced search

[std-proposals] Query "SOO" from std::function and/or std::inplace_function

From: Robin Savonen Söderholm <robinsavonensoderholm_at_[hidden]>
Date: Mon, 18 Nov 2024 16:23:06 +0100
Hi!

In certain embedded situations, you may want to avoid needless heap
allocations. Since the major compiler makers apply "small object
optimisation", it would be nice to somehow query if a type satisfies the
SOO or if std::function would do a heap allocation (something that we could
maybe static_assert in the very least if no other options are automatically
available).
 I believe that whether an object satisfies SOO or not may depend on both
size and alignment of the type, so the most straight-forward API I can
think of is something along the lines of
`std::function_is_inplace_v<FUNCTION, TYPE>` or something like that.
It would also be nice to have a "std::inplace_function" that is a stand-in
replacement for std::function when it is unfit for similar reasons. I see a
"SG14" inplace_function, but I am unsure if inplace_function has been up
for discussion before and shot down for some reason.

// Robin

Received on 2024-11-18 15:23:20