Skip to content

Instantly share code, notes, and snippets.

@CyberDNIWE
CyberDNIWE / Poorly_AlignedStorage.h
Created November 22, 2022 06:57
poorly::aligned_storage
// Equivalent to std::aligned_storage (taken from https://gist.github.com/calebh/fd00632d9c616d4b0c14e7c2865f3085)
namespace poorly
{
template<unsigned int Length, unsigned int Alignment>
struct aligned_storage
{
struct type
{ alignas(Alignment) unsigned char data[Length]; };
};
@CyberDNIWE
CyberDNIWE / Poorly_StaticMax.h
Created November 21, 2022 17:41
poorly::static_max
// Poorly::static_max allows recursively calculating maximum value from size_t parameters/-packs at compile time
// Easily editable for any concrete parameters by replacing size_t to your desired type
namespace poorly
{
// Originally taken from: ( https://gist.github.com/tibordp/6909880 )
// Usage:
// template<typename Ts...>
// struct MyStruct { const size_t data_size = static_max<sizeof(Ts)...>::value };
@CyberDNIWE
CyberDNIWE / variant.cc
Created November 21, 2022 11:39 — forked from tibordp/variant.cc
A simple variant type implementation in C++
#include <iostream>
#include <utility>
#include <typeinfo>
#include <type_traits>
#include <string>
template <size_t arg1, size_t ... others>
struct static_max;
template <size_t arg>
@CyberDNIWE
CyberDNIWE / variant.cpp
Created November 16, 2022 17:29 — forked from calebh/variant.cpp
C++ variant indexed by integer with no standard library dependency
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
@CyberDNIWE
CyberDNIWE / Poorly_Midpoint.h
Created November 16, 2022 10:32
poorly::midpoint, poor man's std::midpoint that avoids overflow caveat
// Taken from Kevlin Henny video https://www.youtube.com/watch?v=YoaZzIZFErI
// poorly::midpoint is poor man's std::midpoint that avoids overflow caveat
namespace poorly
{
struct autoswap_range {};
template<typename T, typename T2 = T>
inline constexpr T midpoint(const T& low, const T2& high) noexcept
{
@CyberDNIWE
CyberDNIWE / Poorly_SizeofArray.h
Created November 16, 2022 08:55
poorly::sizeof_array, drop-in replacement for plain-c array size deduction during compile time
// poorly::sizeof_array is drop-in replacement for plain-c array size deduction
// to never have to worry about sizeof(arr)/sizeof(arr[0]) and similar ever again
// when needing to pass arrays as ptr and size
namespace poorly
{
template<typename T, typename SIZE_T = size_t, SIZE_T Size>
constexpr SIZE_T sizeof_array(T (&)[Size]) noexcept { return Size; }
};
@CyberDNIWE
CyberDNIWE / Circle.h
Created November 15, 2022 12:25
Type erasure example for dummies (free friend funcs)
#pragma once
#include <iostream>
class Circle
{
public:
Circle() : m_radius(0)
{};
@CyberDNIWE
CyberDNIWE / Poorly_Iterable.h
Created November 15, 2022 09:10
poorly::Iterable, make plain-c arrays "poorly" iterable
// poorly::Iterable: poor man's iterator provider that does not take ownership of underlying array
// Usage: copy-paste poorly namespace & use MAKE_POORLY_ITERABLE to make plain-c array iterable.
// (see examples for more info).
#pragma region COPY_PASTE_ITERABLE
#include <cstdint>
namespace poorly
{
template<typename T, size_t SIZE>
<!DOCTYPE html>
<html>
<head>
<title>Running Man</title>
<meta charset="utf-8" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
ImageFile = "https://gist.githubusercontent.com/IsoPippel/4dc459f44b353fcdf61ad6c42c449764/raw/e9431064ee651524ab916a28e72336abd103cc71/running.png"
ImageFileP2 = "https://gist.githubusercontent.com/IsoPippel/4dc459f44b353fcdf61ad6c42c449764/raw/e9431064ee651524ab916a28e72336abd103cc71/running2.png"