Raven Engine v0.1
Loading...
Searching...
No Matches
FixedFunction.h File Reference

Move-only, small-buffer-optimized function wrapper. More...

#include "Raven/Core/Types.h"
#include <type_traits>
#include <cassert>

Classes

class  Raven::FixedFunction< R(Args...), StorageSize >

Namespaces

namespace  Raven

Detailed Description

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:

Raven::FixedFunction<void(int)> fn = [](int x) { std::cout << x; };
if (fn) fn(42);
Type-erased callable wrapper with small buffer optimization (SBO).
Definition FixedFunction.h:54