This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A C++11 constexpr implementation of xxhash32 | |
// Jonathan Adamczewski / https://twitter.com/twoscomplement | |
// A reimplementation of code from https://github.com/Cyan4973/xxHash | |
// Foundation functions / commonly used patterns | |
// Read four chars and construct uint32_t (little endian) | |
constexpr uint32_t xxh_read32(const char* input) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CRC tables, generated at compile time using C++11 constexpr, C++14 utility library, variadic template, initializer list | |
// Compiled and tested using msvc 2015, gcc 6.2, and clang 3.9.0. | |
// clang requires -std=c++14 -ftemplate-depth=512 | |
#include <stdint.h> | |
#include <utility> | |
template<typename T, T Poly> | |
struct CrcTable { | |
static constexpr T Generate(T v, int r = 8) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate CRC tables at compile time. With slices. | |
// Based on http://create.stephan-brumme.com/crc32/#slicing-by-8-overview | |
// | |
// C++11, C++14 utility library, constexpr, variadic templates, initializer lists. | |
// | |
// Tested using gcc-6.2, clang-3.9.0, and latest msvc 2015 compilers. | |
// clang: -std=c++14 -ftemplate-depth=512 | |
// | |
// @twoscomplement 2016-09-26 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
todo.h | |
TODO(): | |
A macro that will fire a static assert if compiled on or after | |
a specified date. | |
Requires C++11 constexpr support. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TransientFuction: A light-weight alternative to std::function [C++11] | |
// Pass any callback - including capturing lambdas - cheaply and quickly as a | |
// function argument | |
// | |
// Based on: | |
// https://deplinenoise.wordpress.com/2014/02/23/using-c11-capturing-lambdas-w-vanilla-c-api-functions/ | |
// | |
// - No instantiation of called function at each call site | |
// - Simple to use - use TransientFunction<> as the function argument | |
// - Low cost: cheap setup, one indirect function call to invoke |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Watch as the OS rewrites my buggy program. | |
Compile with: | |
cl //Ox movoops.cpp | |
Output: | |
0f 28 01 | |
xxxxxxxxxxxxxxx1 | |
0f 10 01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <random> | |
#include <stdlib.h> | |
#include <cstdint> | |
#include <limits> | |
#include <type_traits> | |
#include <algorithm> | |
#include <string> | |
namespace __detail { | |
template<typename _UIntType, size_t __w, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ARRAY_SIZE(a) | |
A macro to compute the number of elements in an array a. | |
Features & considerations: | |
- Will not compile if a is not an array (error message is not elegant). | |
- Able to be used with non-const a. | |
- Happens to produce very few (false-positive) compile-time warnings with msvc 19 when | |
the result is used in signed and truncating arithmetic - unlike std::size() | |
(see also https://t.co/NvhjvMUhA1) |