Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::Function< FuncType > Struct Template Reference

Wraps function pointers, member functions and lambdas without ever allocating. More...

Detailed Description

template<typename FuncType>
struct SC::Function< FuncType >

Wraps function pointers, member functions and lambdas without ever allocating.


Example:

struct MyClass
{
float memberValue = 2.0;
int memberFunc(float a) { return static_cast<int>(a + memberValue); }
};
int someFunc(float a) { return static_cast<int>(a * 2); }
struct BigClass
{
uint64_t values[4];
};
// ... somewhere later
MyClass myClass;
Function<int(float)> func;
func = &someFunc; // Bind free func
func.bind<MyClass, &MyClass::memberFunc>(myClass); // Bind member func
func = [](float a) -> int { return static_cast<int>(a + 1.5); }; // Bind lambda func
BigClass bigClass;
// This will static_assert because sizeof(BigClass) (grabbed by copy) exceeds LAMBDA_SIZE
// func = [bigClass](float a) -> int { return static_cast<int>(a);};
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition: PrimitiveTypes.h:42

Size of lambdas or less than LAMBDA_SIZE (currently 2 * sizeof(void*)).
If lambda is bigger than LAMBDA_SIZE the constructor will static assert.

Template Parameters
FuncTypeType of function to be wrapped (Lambda, free function or pointer to member function)

The documentation for this struct was generated from the following file: