Skip to content

Instantly share code, notes, and snippets.

@Eczbek
Eczbek / public_cast.hpp
Last active July 9, 2026 17:08
public_cast
#include <cstddef>
#include <meta>
#include <string_view>
#include <utility>
#define FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
#define ARROW(...) \
noexcept(noexcept(__VA_ARGS__)) \
-> decltype(auto) \
@Eczbek
Eczbek / meta_map.h
Created June 18, 2026 05:44
generic hashmap
#ifndef DETAIL_META_HEADER_MAP
#define DETAIL_META_HEADER_MAP
#include <stdbit.h>
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#define meta_map_header(MAP) \
(*(union meta_map_header*)(MAP))
@Eczbek
Eczbek / as.hpp
Last active October 9, 2026 10:18
as
struct as{template<class as>struct final{
as defined;template<class final>decltype(
static_cast<final>(as(defined)))constexpr
operator->*(final(::as::*)())noexcept(
noexcept(final(as(defined)))){return(final
)as(defined);}};template<class as>operator
as(){throw;}template<class as>constexpr
friend final<as&&>operator->*(as&&final
,::as)noexcept{return{(as&&)final};}};
#define as ->*::as()->*&::as::operator
@Eczbek
Eczbek / lambdas.md
Last active September 12, 2025 02:14
article on lambdas

Lambdas

A lambda expression is a shorthand notation for creating an unnamed callable object (also called a closure, or an anonymous function). A lambda can "capture" variables from its surrounding scope by value or by reference, allowing the body of the lambda to access or modify those variables without having to pass them as parameters. Unlike regular functions, lambdas are typically written in-line, combining the reusability of functions with direct access to local context. The lambda retains captured variables' state (for captures by value) or dynamically references them (for captures by reference), making lambdas ideal for short, context-dependent operations like custom comparisons, filters, or event handlers.

Example:

bool is_even(int x) {
	return x % 2 == 0;
}

int main() {
std::string vtable_inator(const auto& any) {
struct h { void** name; };
return std::string(reinterpret_cast<char*>(reinterpret_cast<void**>(reinterpret_cast<const h*>(&any)->name[-1])[1]));
}
struct vtable_inator_able { virtual void nothing() final {}; };
struct Hello_world : vtable_inator_able {};
int main() {
const a=-3/80,e=1,f=5,g=8/3,h=9/10,i=1,l=11/3,n=3,o=1/3,r=1,s=7/3,t=10/3,u=12/5,v=1,w=9/5,x=18/7,z=0;
z*e*r*o // 0
o*n*e // 1
t*w*o // 2
t*h*r*e*e // 3
f*o*u*r // 4
f*i*v*e // 5
s*i*x // 6
s*e*v*e*n // 7
@Eczbek
Eczbek / jsfck.h
Last active June 1, 2026 21:43
jsfck using the preprocessor (unoptimizing)
#define SPACE (NaN+[][a+t])[_1+[_1]]
#define EXCLAMATION atob((Infinity+[])[0]+false)[0]
#define QUOTE string[f+o+n+t+c+o+l+o+r]()[_1+[_2]]
#define HASH atob(_0+i+(NaN)+false)[_1]
#define DOLLAR atob(_0+i+S)[_1]
#define PERCENT atob(_0+[_0]+(_0)+l)[_2]
#define AND string[f+o+n+t+c+o+l+o+r](string[f+o+n+t+c+o+l+o+r]([]))[_3+[_1]]
#define APOS atob(_0+i+false)[_1]
#define LPAREN ([][a+t]+[])[_1+[_1]]
#define RPAREN ([][a+t]+[])[_1+[_2]]
@Eczbek
Eczbek / operators.hpp
Last active June 3, 2026 17:13
more logical and bitwise operators
template<auto f>struct A{template<class T>struct B{T x;
constexpr T operator&&(T y ){return static_cast<T>(f( x,y));}
constexpr T operator||(T y ){return static_cast<T>(f( x,y));}
constexpr T operator& (T y ){return static_cast<T>(f( x,y));}
constexpr T operator| (T y ){return static_cast<T>(f( x,y));}
constexpr T operator^ (T y ){return static_cast<T>(f( x,y));}
friend constexpr T operator&=(T y,B b){return static_cast<T>(f(b.x,y));}
friend constexpr T operator|=(T y,B b){return static_cast<T>(f(b.x,y));}
friend constexpr T operator^=(T y,B b){return static_cast<T>(f(b.x,y));}};
template<class T>friend constexpr B<T>operator&&(T x,A ){return{ x };}
@Eczbek
Eczbek / resources.md
Last active January 27, 2026 14:39
C++ resources and a rearrangement of `learncpp.com`
@Eczbek
Eczbek / nowindows.h
Last active July 19, 2026 01:34
Macros to disable generally unwanted stuff from <windows.h> (from Veeloxfire)
#define NOATOM
#define NOCLIPBOARD
#define NOCOLOR
#define NOCOMM
#define NOCTLMGR
#define NODEFERWINDOWPOS
#define NODRAWTEXT
#define NOGDI
#define NOGDICAPMASKS
#define NOICONS