Skip to content

Instantly share code, notes, and snippets.

@andyfriesen
Last active December 28, 2015 11:38
Show Gist options
  • Save andyfriesen/7494546 to your computer and use it in GitHub Desktop.
Save andyfriesen/7494546 to your computer and use it in GitHub Desktop.
#include <iostream>
#define DEFPROP(name, type_) type_ name;
#define S(_) \
_(foo, int); \
_(bar, float)
struct MyStruct {
S(DEFPROP)
};
void print(MyStruct& s) {
#define PRINTPROP(name, type) std::cout << "Name: " << #name << " value: " << s. name << std::endl
S(PRINTPROP);
#undef PRINTPROP
}
int main() {
MyStruct s = { 5, 3.141 };
print(s);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment