Skip to content

Instantly share code, notes, and snippets.

@schaumb
schaumb / dynamic_implementation.cpp
Created August 3, 2022 18:49
C++ interface dynamic implementation
#include <iostream>
#include <stdexcept>
template<typename T>
struct Mock {
void** mfptr = funptrs + 5;
void* funptrs[15] = {{}, {}, {}, {}, {}};
#include <type_traits>
#include <utility>
namespace Impl {
// <e> <e> <e> <e>
// const
// volatile
@schaumb
schaumb / bitest_like_iterator_helper.hpp
Last active October 17, 2022 21:33
optimalized bitset like true value iterator helper, like std::bitset and std::vector<bool>
#ifndef BITSET_ITERATOR_HELPER_HPP
#define BITSET_ITERATOR_HELPER_HPP
#include <utility>
#include <limits>
#include <functional>
#include <cstdint>
template<class T>
struct bitset_like_iterator_helper {
@schaumb
schaumb / access_private.cpp
Last active March 16, 2023 21:06
access private c++17
#ifndef ACCESS_PRIVATE_CPP17
#define ACCESS_PRIVATE_CPP17
#include <functional>
#define ACCESS_PRIVATE_IMPL(CLASS, NAME, CASTER, TYPE) \
namespace { \
namespace access_tag::CLASS {\
template<class T>\
struct NAME; \
@schaumb
schaumb / WORKING_AROUND_OFFSETOF_LIMITATIONS.MD
Last active March 16, 2023 15:58 — forked from graphitemaster/WORKING_AROUND_OFFSETOF_LIMITATIONS.MD
Working around offsetof limitations in C++

Working around offsetof limitations in C++:

There is sometimes a situation in which one needs to get the relative offset of a structure field, common examples of this include serialization frameworks which aid to serialize objects, vertex attributes for rendering (D3D, GL.), etc.

The most common technique for getting this information is through the offsetof macro defined in stddef.h. Unfortunately using the macro in C++ comes with a new set of restrictions that prevent some (subjectively valid) uses of it.

@schaumb
schaumb / st_route.py
Last active June 30, 2025 19:54
Streamlit - Support custom HTTP requests
import functools
import gc
import weakref
from typing import Optional, Callable, Union
from weakref import WeakSet
from streamlit import config
from streamlit.runtime import Runtime
from streamlit.runtime.scriptrunner import get_script_run_ctx, add_script_run_ctx
from streamlit.web.server.server_util import make_url_path_regex