function2 icon indicating copy to clipboard operation
function2 copied to clipboard

Suggestion: Allow users of function2 to know easily whether their lambdas are stored inplace

Open romange opened this issue 5 years ago • 4 comments

@Naios Suggestion

For example,

using MyFunction =  fu2::function_base<...>;
auto cb = [foo, bar] {};
static_assert(MyFunction::is_inplace(cb), "Lambda too big!")

This could be useful to maintain code over time and not to break performance-related assumptions..

romange avatar Apr 18 '20 08:04 romange

This could be really useful indeed. Probably it will be implemented in the future.

Naios avatar Apr 19 '20 16:04 Naios

This could also be useful as a configuration option to disallow function objects that are too large for SFO.

using MyFunction =  fu2::function_base<...>;
auto cb1 = [foo, bar] {};
auto cb2 = [foo, bar, baz] {};
MyFunction f1{cb1}; // allowed
//MyFunction f2{cb2}; // too big for SFO, compile error

Ahajha avatar Aug 28 '22 17:08 Ahajha

Yes, that's right. Something like fu2::inplace_function (which itself could be a specialization of fu2::function_base) could be quite useful.

Naios avatar Aug 28 '22 18:08 Naios

I came here looking for an in-place move-only function, and I very much vote for both proposals. In some places I want my functions to be in-place only, with a possibility to increase the storage size as needed.

VioletGiraffe avatar Jan 23 '23 23:01 VioletGiraffe