Skip to content

Instantly share code, notes, and snippets.

@kestred
Created November 10, 2013 02:09
Show Gist options
  • Save kestred/7392726 to your computer and use it in GitHub Desktop.
Save kestred/7392726 to your computer and use it in GitHub Desktop.
Attempt two at coming up with decorators
#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