Created
November 10, 2013 02:09
-
-
Save kestred/7392726 to your computer and use it in GitHub Desktop.
Attempt two at coming up with decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <unordered_map> | |
#include <string> | |
#define DCLASS(cpp_class) \ | |
public std::unordered_map<std::string, void (cpp_class::*)(int)> s_atomics; | |
// note, "int" would actually be a datagram iterator | |
#define ATOMIC(field_name, cpp_class, cpp_fn) \ | |
cpp_class.s_atomics[field_name] = cpp_fn; | |
class Foo { | |
DCLASS(Foo) | |
void Fizz(int); | |
}; | |
ATOMIC("fizz", Foo, Foo::Fizz) | |
void Foo::Fizz(int a) { | |
// do stuff, for example: | |
std::cout << a << std::endl; | |
} | |
int main() | |
{ | |
Foo* k = new Foo(); | |
k->s_atomics["fizz"](3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment