Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Add SBO support for lambdas and functors delegates
This commit adds 'Small Buffer Optimization' to functor and lambda functions with small footprint, i.e. the same size as 'void *' or less, and will therefore mimic the `std::function` behavior for these types, instead of being a reference to them as before. This means that the following operations are now allowed to delegate with deferred/out-of-scope calls: ``` etl::delegate<void()> Class::method() { etl::delegate<void()> d {[this](){ this->do_something(); }}; return d; } ``` A caveat is that the old behavior where everything became a reference instead of an object is changed and the user must now use a `reference_wrapper` to gain the same behavior, i.e. using `etl::ref` or `etl::cref`: ``` auto f = [&](){ /* ... */ }; etl::delegate<void()> d { etl::ref(d) }; d(); ``` This change of behavior also matches the C++ Core Guidelines for how to pass parameters [https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f15-prefer-simple-and-conventional-ways-of-passing-information] BREAKING CHANGE: functors and lambda capture will not be references to any longer.
- Loading branch information