EasyDelegate
2.0
Delegate and deferred callers for C++11.
|
EasyDelegate is, as the name implies, a delegate system. It is written for C++11 with the intention to allow C++ programmers to easily create references to static and member methods that may be passed around like any other variable and invoked at any point in the code. This is helpful for a variety of situations, such as an event/listener implementation.
This quick example below demonstrates how simple it is to utilize the EasyDelegate library, though for a more complete example, please refer to example.cpp.
The above code sample will output:
"MyCustomClass::myMemberMethod: Foo,3.14,3.14159"
"MyCustomClass::myMemberMethod: Foo,3.14,3.14159"
EasyDelegate also supports deferred call objects in C++ using the same implementations that the regular EasyDelegate library uses. They provide you with the ability to cache a call and later dispatch it completely anonymously if so desired. Take the following code sample:
The output of this code will be "Got float: 3.14".
EasyDelegate has been compiled and known to run on the following systems:
It should compile and run underneath of any compiler that at least supports variadic templates, std::tuple (used by CachedDelegate types), std::set, std::unordered_set but preferably has full C++11 support, though. If the use of the STL is not an option, then it should be relatively easy to switch EasyDelegate to the preferred container types for your project.
Note for MinGW/GCC Users:
EasyDelegate has been known to fail compilation (and possibly crash the compiler) on MinGW 4.7, and the same bugs probably exist in *nix native GCC. Please ensure that you are running at least GCC 4.8 when building a project with EasyDelegate.
Due to the nature of the library, there is one limitation which derives from the usage of templates which is the inability to work with variadic methods because the ellipses ('...') involved are interpreted as a variadic template argument expansion and thusly will fail to compile. A work around for this if such functionality is necessary to your project would be to use a void* declaration instead and use that to pass a struct in which is then casted to the proper struct type on the called method's end. There may be a way to properly implement variadic method support, but I have not come up with anything yet.
The vast majority of this library was written by Robert MacGregor, licensed under the MIT license for the open source community. There exists two small types that were pulled from StackOverflow which were quite imperative to the functioning of the deferred calling systems:
Other Links: