Skip to content

A short version of Elbert Mai's lightweight delegates/callbacks in C++11

License

Notifications You must be signed in to change notification settings

kaidokert/cpp-delegate

Repository files navigation

Delegate

Travis Status Appveyor Status Coverage Status

Elbert Mai's generic callback/delegate, C++11 with no other dependencies except <utility>. 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 and https://github.com/reiver-dev/cppcallback

Use primarily through CREATE_DELEGATE macro:

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<bool(int)> call_me_maybe = delegate;
call_me_maybe(31337);

Built with maximum warnings on gcc, clang, msvc, full test coverage

TODO

  • Add Catch / Lest tests
  • add gcc/arm build
  • add cpplint

About

A short version of Elbert Mai's lightweight delegates/callbacks in C++11

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published