Skip to content

Instantly share code, notes, and snippets.

@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
}
}
#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 / 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> {
@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 / 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 / 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 / pretty_function_processor.cpp
Created April 22, 2022 18:48
Pretty function processor.
#include <type_traits>
#include <string_view>
#include <iostream>
#include <atomic>
#include <utility>
#include <tuple>
#include <cassert>
template<char... Chars>
struct str {
@schaumb
schaumb / long_type_traits.hpp
Created April 26, 2022 17:11
add_long, remove_long, has_long type traits
#include <type_traits>
namespace bxlx {
namespace impl {
template<typename T, typename = void>
struct add_long {
using type = T;
};
template<>
@schaumb
schaumb / lambda_traits.hpp
Created May 2, 2022 20:19
lambda traits header only lib. min/max arity, has capture, is variadic etc
#include <tuple>
#include <limits>
#define BXLX_MAXIMUM_ARG_TEMPLATE_LAMBDA 100
namespace bxlx {
namespace impl {
template<std::size_t>
struct arg {
using type = arg;
@schaumb
schaumb / get_member_name.hpp
Last active May 14, 2024 18:58
c++ get member name from member pointer
// see at godbolt : https://godbolt.org/z/zMGEGs99v
#include <string_view>
template<auto V>
constexpr static auto n() noexcept {
#ifdef _MSC_VER
std::string_view sv = __FUNCSIG__;
auto to = sv.rfind('>')-1;
for (std::size_t close = sv[to] == ')'; close > 0; ) {