Skip to content

Instantly share code, notes, and snippets.

@gatchamix
gatchamix / spiral_generator.cpp
Last active March 12, 2020 15:49
scalable cache friendly spiral sequence generation (SNSystems)
#include <cstddef>
#include <algorithm>
#include <array>
#include <iostream>
using std::size_t;
auto constexpr calculate(size_t row, size_t column, size_t width, size_t height, size_t value = 0)
{
--width;
@gatchamix
gatchamix / signature_detection.cpp
Last active August 18, 2017 09:40
member function exact signature matching
#include <type_traits>
#include <functional>
//
struct validator
{
template <template <class...> class, class...>
static auto constexpr is_valid(...)
-> std::false_type;
@gatchamix
gatchamix / jump_list.cpp
Last active August 28, 2017 23:18
hard jump-list generator
#include <array>
#include <type_traits>
#include <utility>
//
template <auto... Vs>
struct auto_t
{ static auto constexpr size = sizeof...(Vs); };
@gatchamix
gatchamix / constexpr_map.cpp
Last active May 12, 2021 14:52
constexpr map
#include <utility>
#include <array>
template <auto...>
struct value_list
{};
template <class T, auto... Keys>
struct map_
{
@gatchamix
gatchamix / constexpr_switch.cpp
Last active October 11, 2021 10:58
constexpr switch/case/default
#include <type_traits>
#include <utility>
#include <limits>
#include <array>
//
template <auto V_>
struct auto_t
{
@gatchamix
gatchamix / template_list.cpp
Last active August 27, 2017 16:59
template type and non-type list and manipulation functions (type_t/auto_t)
#include <type_traits>
#include <limits>
#include <utility>
//
template <class... Ts>
struct type_t
{ static auto constexpr size = sizeof...(Ts); };
@gatchamix
gatchamix / meta17.cpp
Last active August 31, 2017 21:21
meta-programming types and algorithms using C++17/2a
#include <type_traits>
#include <utility>
#include <cstddef>
#include <string_view>
#include <iterator>
#include <limits>
#include <tuple>
//
@gatchamix
gatchamix / tuple17.cpp
Last active July 24, 2018 13:35
simple tuple container using C++17
template <std::size_t N, class T>
struct tuple_elem
{
constexpr tuple_elem(T&& val)
: val_{ std::forward<T>(val) }
{}
template <auto I, std::enable_if_t<I == N>* = nullptr>
auto constexpr& operator[](constant<I>)
{ return val_; }
@gatchamix
gatchamix / static_class_2a.cpp
Created September 7, 2017 16:07
improvement to static class design using hana::is_valid + C++2a explicit lambda templates
#include <utility>
//
template <class F, class... Args,
class = decltype(std::declval<F&&>()(std::declval<Args&&>()...))>
auto constexpr is_valid_impl(int)
{ return true; }
template <class F, class... Args>
@gatchamix
gatchamix / to_list.cpp
Created October 13, 2017 13:57
helper macro to convert applicable data into an auto_list equivalent
#include <utility>
#include <iterator>
#include <array>
#include <string_view>
//
template <auto...>
struct auto_list
{};