Skip to content

Commit a728437

Browse files
committed
Avoid using indirect C++ types
1 parent 762e231 commit a728437

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/gfx/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <stdlib.h>
1313
#include <string.h>
1414
#include <string_view>
15-
#include <type_traits>
1615
#include <vector>
1716

1817
#include "extern/getopt.hpp"
@@ -283,8 +282,8 @@ static std::vector<size_t> readAtFile(std::string const &path, std::vector<char>
283282

284283
// We only filter out `EOF`, but calling `isblank()` on anything else is UB!
285284
static_assert(
286-
std::remove_reference_t<decltype(*file)>::traits_type::eof() == EOF,
287-
"isblank(char_traits<...>::eof()) is UB!"
285+
std::streambuf::traits_type::eof() == EOF,
286+
"isblank(std::streambuf::traits_type::eof()) is UB!"
288287
);
289288
std::vector<size_t> argvOfs;
290289

src/gfx/pal_spec.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ constexpr uint8_t singleToHex(char c) {
4545
}
4646

4747
template<typename Str> // Should be std::string or std::string_view
48-
static void skipWhitespace(Str const &str, typename Str::size_type &pos) {
48+
static void skipWhitespace(Str const &str, size_t &pos) {
4949
pos = std::min(str.find_first_not_of(" \t"sv, pos), str.length());
5050
}
5151

@@ -54,9 +54,8 @@ void parseInlinePalSpec(char const * const rawArg) {
5454
// Palettes are separated by colons.
5555

5656
std::string_view arg(rawArg);
57-
using size_type = decltype(arg)::size_type;
5857

59-
auto parseError = [&rawArg, &arg](size_type ofs, size_type len, char const *msg) {
58+
auto parseError = [&rawArg, &arg](size_t ofs, size_t len, char const *msg) {
6059
(void)arg; // With NDEBUG, `arg` is otherwise not used
6160
assume(ofs <= arg.length());
6261
assume(len <= arg.length());
@@ -80,7 +79,7 @@ void parseInlinePalSpec(char const * const rawArg) {
8079
options.palSpec.clear();
8180
options.palSpec.emplace_back(); // Value-initialized, not default-init'd, so we get zeros
8281

83-
size_type n = 0; // Index into the argument
82+
size_t n = 0; // Index into the argument
8483
// TODO: store max `nbColors` ever reached, and compare against palette size later
8584
size_t nbColors = 0; // Number of colors in the current palette
8685
for (;;) {
@@ -222,7 +221,7 @@ static bool readLine(std::filebuf &file, std::string &buffer) {
222221

223222
// Parses the initial part of a string_view, advancing the "read index" as it does
224223
template<typename U> // Should be uint*_t
225-
static std::optional<U> parseDec(std::string const &str, std::string::size_type &n) {
224+
static std::optional<U> parseDec(std::string const &str, size_t &n) {
226225
uintmax_t value = 0;
227226
auto result = std::from_chars(str.data() + n, str.data() + str.size(), value);
228227
if (static_cast<bool>(result.ec)) {
@@ -233,7 +232,7 @@ static std::optional<U> parseDec(std::string const &str, std::string::size_type
233232
}
234233

235234
static std::optional<Rgba>
236-
parseColor(std::string const &str, std::string::size_type &n, uint16_t i) {
235+
parseColor(std::string const &str, size_t &n, uint16_t i) {
237236
std::optional<uint8_t> r = parseDec<uint8_t>(str, n);
238237
if (!r) {
239238
error("Failed to parse color #%d (\"%s\"): invalid red component", i + 1, str.c_str());
@@ -281,7 +280,7 @@ static void parsePSPFile(std::filebuf &file) {
281280

282281
line.clear();
283282
requireLine("PSP", file, line);
284-
std::string::size_type n = 0;
283+
size_t n = 0;
285284
std::optional<uint16_t> nbColors = parseDec<uint16_t>(line, n);
286285
if (!nbColors || n != line.length()) {
287286
error("Invalid \"number of colors\" line in PSP file (%s)", line.c_str());
@@ -347,7 +346,7 @@ static void parseGPLFile(std::filebuf &file) {
347346
continue;
348347
}
349348

350-
std::string::size_type n = 0;
349+
size_t n = 0;
351350
skipWhitespace(line, n);
352351
// Skip empty lines, or lines that contain just a comment.
353352
if (line.length() == n || line[n] == '#') {
@@ -604,7 +603,7 @@ void parseExternalPalSpec(char const *arg) {
604603
};
605604

606605
auto iter =
607-
std::find_if(RANGE(parsers), [&arg, &ptr](decltype(parsers)::value_type const &parser) {
606+
std::find_if(RANGE(parsers), [&arg, &ptr](auto const &parser) {
608607
return strncasecmp(arg, std::get<0>(parser), ptr - arg) == 0;
609608
});
610609
if (iter == parsers.end()) {

src/gfx/process.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ImagePalette {
3636
// color), then the other color is returned. Otherwise, `nullptr` is returned.
3737
[[nodiscard]]
3838
Rgba const *registerColor(Rgba const &rgba) {
39-
decltype(_colors)::value_type &slot = _colors[rgba.cgbColor()];
39+
std::optional<Rgba> &slot = _colors[rgba.cgbColor()];
4040

4141
if (rgba.cgbColor() == Rgba::transparent) {
4242
options.hasTransparentPixels = true;
@@ -52,7 +52,7 @@ class ImagePalette {
5252
}
5353

5454
size_t size() const {
55-
return std::count_if(RANGE(_colors), [](decltype(_colors)::value_type const &slot) {
55+
return std::count_if(RANGE(_colors), [](std::optional<Rgba> const &slot) {
5656
return slot.has_value() && !slot->isTransparent();
5757
});
5858
}

0 commit comments

Comments
 (0)