Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View XDracam's full-sized avatar
🕹️
Construction Process Planning framework development

Cameron XDracam

🕹️
Construction Process Planning framework development
  • BII GmBh
  • Würzburg
View GitHub Profile
@XDracam
XDracam / foreach.h
Last active November 4, 2019 10:18
C++ zero-cost varargs foreach - reduce code duplication while keeping the code expressive
// 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, _.foo());
// foreach(&&, a, b, c, sum += _);
#define _GET_FOR_EACH_MACRO(_0, _1, _2, _3, _4, _5, _6, NAME, ...) \
NAME
@XDracam
XDracam / sequence.h
Last active December 28, 2023 23:26
Constexpr range literals with optional type inference
// 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`).