Move-only, small-buffer-optimized function wrapper.
- Author
- Philip
FixedFunction is a lightweight alternative to std::function that avoids dynamic allocation for small callables by storing them inline (SBO).
Key properties:
- Small Buffer Optimization (SBO): Stores callable inline if it fits within StorageSize, otherwise falls back to heap allocation.
- Move-only: Copying is disabled since duplicating arbitrary lambdas (especially with captures) is expensive and rarely needed.
- Type-erased callable storage: Uses a minimal custom vtable containing Invoke, Destroy, and Move operations.
- No overhead during invocation. Just one vtable indirection, no heap traffic in the inline case.
Example:
if (fn) fn(42);
Type-erased callable wrapper with small buffer optimization (SBO).
Definition FixedFunction.h:54