Skip to content

Instantly share code, notes, and snippets.

@schaumb
schaumb / bxlx_memory.hpp
Created April 20, 2022 16:05
make_temporary_for_overwrite, make_function_scoped_for_overwrite
#include <type_traits>
#if __has_include(<alloca.h>)
#include <alloca.h>
#else
#define alloca _alloca
#endif
namespace bxlx {
@schaumb
schaumb / redirect.py
Last active December 29, 2023 02:16
streamlit redirect
import streamlit as st
import io
import contextlib
import sys
import re
import threading
class _Redirect:
class IOStuff(io.StringIO):
@schaumb
schaumb / limit_iterator.hpp
Last active July 28, 2020 21:00
limiting iterator maximum range. output_iterator too
#pragma once
#include <boost/iterator/iterator_categories.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
namespace bxlx {
namespace detail {
template<typename Proxy>
struct enable_proxy {
Proxy p;
@schaumb
schaumb / collection.hpp
Last active July 23, 2020 16:57
Create a function returnable range collection.
#include <boost/utility/base_from_member.hpp>
#include <boost/range/any_range.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <any>
#include <type_traits>
template<typename T, typename Traversal = boost::forward_traversal_tag>
struct collection : boost::base_from_member<std::any>,
boost::base_from_member<std::function<boost::any_range<T, Traversal>(std::any&)>>,
boost::any_range<T, Traversal> {
#include <iostream>
#include <tuple>
#include <boost/callable_traits.hpp>
#include <boost/type_index/ctti_type_index.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/variadic/to_seq.hpp>
template<template <typename> typename Base, std::size_t ...Dependents>
struct Depends : Base<Depends<Base, Dependents...>> {
@schaumb
schaumb / is_constant_evaluated.cpp
Last active May 17, 2023 10:56
>=gcc6.1 and >=c++11 is_constant_evaluated() function implementation with manual memory setting
#include <iostream>
#include <type_traits>
namespace {
unsigned char v{};
constexpr bool is_constant_evaluated(const unsigned char* e = &v) {
return e - 0x6017d2; // memory dependent constant value, check output first line
}
}