Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pmed/fixed_size_function
Fixed size function wrapper like std::function
https://github.com/pmed/fixed_size_function
Last synced: 11 days ago
JSON representation
Fixed size function wrapper like std::function
- Host: GitHub
- URL: https://github.com/pmed/fixed_size_function
- Owner: pmed
- License: mit
- Created: 2014-08-12T02:50:29.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-01T13:46:50.000Z (over 8 years ago)
- Last Synced: 2024-10-13T16:06:48.116Z (26 days ago)
- Language: C++
- Size: 8.79 KB
- Stars: 68
- Watchers: 6
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- AwesomeCppGameDev - fixed_size_function
README
Fixed size function
===================Fixed size function wrapper like [std::function](http://en.cppreference.com/w/cpp/utility/functional/function) to avoid dynamic memory allocation.
Usage:
```c++
#include "fixed_size_function.hpp"int f(int a)
{
std::cout << __FUNCTION__ << "\n";
return a;
}int g(int a, int b)
{
std::cout << __FUNCTION__ << "\n";
return a;
}struct X
{
int operator()(int a) const
{
std::cout << __FUNCTION__ << "\n";
return a;
}int mem_fun(int a)
{
std::cout << __FUNCTION__ << "\n";
return a;
}
};int main()
{
fixed_size_function 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);}
```