Skip to content

Instantly share code, notes, and snippets.

View notfoundry's full-sized avatar

Mark Johnson notfoundry

  • Canada
View GitHub Profile
@notfoundry
notfoundry / addition.h
Last active August 9, 2020 17:42
Brainfuck interpreter written in the C preprocessor
#include "bf.h"
#define LHS 2
#define RHS 5
PPFUCK (
(LHS, RHS),
G // G ("get") is ,
R G // R ("right") is >
( // ( is [
@notfoundry
notfoundry / wtf.c
Created September 9, 2020 03:05
4-bit ALU metaprogrammed in C11's _Generic
const static struct _0 {} _0;
const static struct _1 {} _1;
#define G7_SPLICE(expr) __typeof__(expr)
#define G7_STRUCT(...) (struct { __VA_ARGS__ } ){}
#define G7_NAND(a, b) \
@notfoundry
notfoundry / example.hpp
Last active October 6, 2020 19:32
Universal type-level `apply` metafunction
#include <type_traits
#include "meta_invoke.hpp"
#define ASSERT_SAME(...) static_assert(std::is_same_v<__VA_ARGS__>)
struct f1 {
template <class T>
using f = T*;
};
ASSERT_SAME(META_INVOKE((f1), int), int*);
#define PPTS_BIT_BASE 32
#define PPTS_TOKEN_l (l)
#define PPTS_TOKEN_o (o)
#define PPTS_TOKEN_n (n)
#define PPTS_TOKEN_g (g)
#define ORDER_PP_DEF_1ppts_choose_type_for_width \
ORDER_PP_FN(8fn(8N, 8print(8(_ExtInt) 8lparen 8to_lit(8mul(PPTS_BIT_BASE, 8N)) 8rparen)))
@notfoundry
notfoundry / example.hpp
Created October 6, 2020 21:05
Lift heterogenous eager C++ metafunction
#include "lift.hpp"
constexpr auto make_array = META_LIFT(std::array, (class, int));
using array_of_5_ints = decltype(make_array.template operator()<int, 5>());