Skip to content

Repository files navigation

Fixed size function

Fixed size function wrapper like std::function to avoid dynamic memory allocation.

Usage:

#include"fixed_size_function.hpp"intf(int a)
{
std::cout << __FUNCTION__ << "\n";
return a; }
intg(int a, int b)
{
std::cout << __FUNCTION__ << "\n";
return a;
}
structX
{
intoperator()(int a) const
{
std::cout << __FUNCTION__ << "\n";
return a;
}
intmem_fun(int a)
{
std::cout << __FUNCTION__ << "\n";
return a;
}
};
intmain()
{
fixed_size_function<int(int), 256> fun;
// Functor
X x;
fun = x;
fun(1);
// Free function
fun = f;
fun(2);
// Bind function
fun = std::bind(g, std::placeholders::_1, 0);
fun(3);
// Bind member function
fun = std::bind(&X::mem_fun, x, std::placeholders::_1);
fun(4);
// Lambda
fun = [](int a) -> int
{
std::cout << __FUNCTION__ << "\n";
return a;
};
fun(5);
}

About

Fixed size function wrapper like std::function

Resources

Stars

72 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages