diff --git a/include/helpers.hpp b/include/helpers.hpp index 19f9ff6f..9718737b 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -96,7 +96,8 @@ static inline int clz(unsigned int x) { #define EXPAND_AND_CAT(x, y) CAT(x, y) // For lack of , this adds some more brevity -#define RANGE(s) std::begin(s), std::end(s) +#define RANGE(s) std::begin(s), std::end(s) +#define RRANGE(s) std::rbegin(s), std::rend(s) // MSVC does not inline `strlen()` or `.length()` of a constant string template diff --git a/src/asm/lexer.cpp b/src/asm/lexer.cpp index 4a657f8b..a4dff1de 100644 --- a/src/asm/lexer.cpp +++ b/src/asm/lexer.cpp @@ -1955,10 +1955,9 @@ static Token yylex_NORMAL() { static Token yylex_RAW() { // This is essentially a highly modified `readString` std::string str; - size_t parenDepth = 0; int c; - for (;;) { + for (size_t parenDepth = 0;;) { c = peek(); switch (c) { @@ -2075,7 +2074,7 @@ append: finish: // Can't `break` out of a nested `for`-`switch` // Trim left and right blank space str.erase(str.begin(), std::find_if_not(RANGE(str), isBlankSpace)); - str.erase(std::find_if_not(str.rbegin(), str.rend(), isBlankSpace).base(), str.end()); + str.erase(std::find_if_not(RRANGE(str), isBlankSpace).base(), str.end()); // Returning COMMAs to the parser would mean that two consecutive commas // (i.e. an empty argument) need to return two different tokens (STRING diff --git a/src/gfx/main.cpp b/src/gfx/main.cpp index c35c7d9f..7aa54356 100644 --- a/src/gfx/main.cpp +++ b/src/gfx/main.cpp @@ -918,21 +918,17 @@ auto Palette::begin() -> decltype(colors)::iterator { auto Palette::end() -> decltype(colors)::iterator { // Return an iterator pointing past the last non-empty element. // Since the palette may contain gaps, we must scan from the end. - return std::find_if( - colors.rbegin(), colors.rend(), [](uint16_t c) { return c != UINT16_MAX; } - ).base(); + return std::find_if(RRANGE(colors), [](uint16_t c) { return c != UINT16_MAX; }).base(); } auto Palette::begin() const -> decltype(colors)::const_iterator { - // Skip the first slot if reserved for transparency + // Same as the non-const begin(). return colors.begin() + options.hasTransparentPixels; } auto Palette::end() const -> decltype(colors)::const_iterator { // Same as the non-const end(). - return std::find_if( - colors.rbegin(), colors.rend(), [](uint16_t c) { return c != UINT16_MAX; } - ).base(); + return std::find_if(RRANGE(colors), [](uint16_t c) { return c != UINT16_MAX; }).base(); } uint8_t Palette::size() const {