Skip to content

Instantly share code, notes, and snippets.

@uhziel
Last active March 24, 2020 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhziel/5a48796faf1532c03c2105ad10bf6043 to your computer and use it in GitHub Desktop.
Save uhziel/5a48796faf1532c03c2105ad10bf6043 to your computer and use it in GitHub Desktop.
g++ -g -std=c++11 -o cpp-traverse-example cpp-traverse-example.cpp
#include "traverse.h"
struct Point {
int32_t x;
int32_t y;
};
TRAVERSE_STRUCT(Point, FIELD(x) FIELD(y))
/* Expand to
* void visit(traverse::CoutWriter& visitor, Point& obj) {
* visit_struct("Point", visitor)
* .field("x", obj.x)
* .field("y", obj.y);
* }
*/
int main() {
Point point;
point.x = 1;
point.y = 2;
traverse::CoutWriter writer;
visit(writer, point);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment