Skip to content

Instantly share code, notes, and snippets.

View riogu's full-sized avatar
✏️
コンパイラ作成中

egas riogu

✏️
コンパイラ作成中
View GitHub Profile
@riogu
riogu / 1-printable-enum.md
Last active July 18, 2025 22:16
printable C++ enums with macros

a few lines of macros for making a printable enum.

@riogu
riogu / 1-match-construct.md
Last active September 15, 2025 00:05
match construct for std::variant using macros

using some templates with some hacky macros to allow matching on the contents of a std::variant, and getting the underlying value immediately.

@m1lkweed
m1lkweed / for_each.c
Last active June 27, 2025 08:10
`for each` macro in standard C that works on all types
#include <stdio.h>
// Enhances `for` to automatically iterate over an array. Item cannot be used to modify the contents of array.
#if __STDC_VERSION__ < 202311L
#define each(item, ...) \
(int no_loops = 1, break_p = 2; (no_loops >= 1) && (break_p == 2);) \
for(typeof(*(__VA_ARGS__)) *foreach_p = (__VA_ARGS__), *foreach_p2 = foreach_p, (item) = {}; \
(foreach_p < &((foreach_p2)[sizeof(__VA_ARGS__) / sizeof(*(__VA_ARGS__))])) && \
((break_p = (break_p == 2)?0:break_p), no_loops); ++foreach_p) \
if((__builtin_memcpy(&(item), foreach_p, sizeof(item))), 0){}else
#else
@csullivan
csullivan / cereal_polymorphic_serialization.cc
Last active March 13, 2025 22:44
polymorphic data serialization example with cereal
#include <iostream>
#include <vector>
#include <memory>
#include <cereal/archives/binary.hpp>
#include <cereal/types/vector.hpp>
#include <cereal/types/string.hpp>
#include <cereal/types/base_class.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/access.hpp>