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
// 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 |
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
// 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`). |