Skip to content

Instantly share code, notes, and snippets.

Doing proprietary work related to VR simulations

Cameron XDracam

Doing proprietary work related to VR simulations
View GitHub Profile
XDracam / sequence.h
Last active Nov 28, 2019
Constexpr range literals with optional type inference
View sequence.h
// Requires C++17. Tested on Clang 9.0.0, but should be portable.
// Modern C++ code uses ranges for more expressive code, compared to begin- and end-iterators.
// When writing code that operators on ranges, you often end up with code like this (when not using concepts):
// template <typename TRange>
// auto foo(const TRange& range);
// So how do you call this with a fixed sequence of elements? You could pass an `std::vector`,
// but that incurs one heap allocation (potentially two, if using an `std::initializer_list`).
XDracam / foreach.h
Last active Nov 4, 2019
C++ zero-cost varargs foreach - reduce code duplication while keeping the code expressive
View foreach.h
// Written by Cameron Reuschel (XDracam), 2019
// Does not work on MSVC, since they use a different preprocessor algorithm than clang and gcc.
// Use like this:
// foreach(const &, myFoo1, myFoo2, myFoo3,;
// foreach(&&, a, b, c, sum += _);
#define _GET_FOR_EACH_MACRO(_0, _1, _2, _3, _4, _5, _6, NAME, ...) \