Skip to content

Instantly share code, notes, and snippets.

View dahmadjid's full-sized avatar

Dahmani Abdelmadjid dahmadjid

View GitHub Profile
@AndrewScheidecker
AndrewScheidecker / gist:930f4a6e0966b8421806
Created September 4, 2014 12:43
A stupid C++ trick for defining structs with metadata (serializers, printers, etc) without redundant declarations of members
#include <iostream>
#include <vector>
#include <string>
using std::string;
/*
These macros define a struct with an implicitly defined Show function that visits each member.
The trick is that a typedef is split between each STRUCT_MEMBER instance and the preceding macro,
which allows it to define an empty struct type that identifies the following struct member, while also
knowing the struct type that the preceding macro is using to identify the current member.