https://github.com/kaidokert/cpp-delegate
A short version of Elbert Mai's lightweight delegates/callbacks in C++11
https://github.com/kaidokert/cpp-delegate
cpp cpp11 delegate header-only
Last synced: 3 months ago
JSON representation
A short version of Elbert Mai's lightweight delegates/callbacks in C++11
- Host: GitHub
- URL: https://github.com/kaidokert/cpp-delegate
- Owner: kaidokert
- License: mit
- Created: 2016-01-11T01:15:52.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-01-18T13:31:30.000Z (about 8 years ago)
- Last Synced: 2025-10-10T10:26:08.931Z (5 months ago)
- Topics: cpp, cpp11, delegate, header-only
- Language: C++
- Size: 37.1 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Delegate
[](https://travis-ci.org/kaidokert/cpp-delegate) [](https://ci.appveyor.com/project/kaidokert/cpp-delegate) [](https://coveralls.io/github/kaidokert/cpp-delegate)
Elbert Mai's [generic callback/delegate](http://www.codeproject.com/Articles/136799/Lightweight-Generic-C-Callbacks-or-Yet-Another-Del), C++11 with no other dependencies except ````. No exceptions/rtti/heap usage, and just about 100 lines of single header template code.
This is effectively a raw function pointer wrapped in a typesafe template and has no runtime code size or processing overhead with any of the compilers.
Implementation patterned after version from this [smart function pointer article](http://www.codeproject.com/Articles/995916/A-Smart-Function-Pointer) and https://github.com/reiver-dev/cppcallback
Use primarily through CREATE_DELEGATE macro:
```cpp
struct foo {
bool bar(int param) { }
};
bool baz(int param) { }
foo foo_instance;
auto delegate = CREATE_DELEGATE(&foo::bar, &foo_instance);
delegate(42);
delegate = CREATE_DELEGATE(&baz);
delegate(90210);
Delegate call_me_maybe = delegate;
call_me_maybe(31337);
```
Built with maximum warnings on gcc, clang, msvc, full test coverage
### TODO
* Add [Catch](https://github.com/philsquared/Catch) / [Lest](https://github.com/martinmoene/lest) tests
* add gcc/arm build
* add cpplint