Skip to content

Instantly share code, notes, and snippets.

@sagunb
sagunb / gist:377cbecf0a4e6772b6b27788b0559063
Created January 24, 2022 17:48 — forked from AndrewScheidecker/gist:930f4a6e0966b8421806
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.

Keybase proof

I hereby claim:

  • I am sagunb on github.
  • I am sagun (https://keybase.io/sagun) on keybase.
  • I have a public key ASAtXfvPNDAfDVaTK45H4bYSQWqn9SCgmtTh-R9dYEO07Qo

To claim this, I am signing this object:

import sys
import pandas as pd
import ujson as json
from collections import defaultdict
def item_info(item):
if (item["status"] == 1) and (item["visibility"] in [2, 3, 4]):
return dict(id=item["id"], level=item["level"], name=item["name"], status=item["status"],
visibility=item["visibility"], parent_id=None)