diff --git a/include/file.hpp b/include/file.hpp index e1386b13..64cba9c6 100644 --- a/include/file.hpp +++ b/include/file.hpp @@ -21,14 +21,6 @@ #include "gfx/main.hpp" -// Convenience feature for visiting the below. -template -struct Visitor : Ts... { - using Ts::operator()...; -}; -template -Visitor(Ts...) -> Visitor; - class File { // Construct a `std::streambuf *` by default, since it's probably lighter than a `filebuf`. std::variant _file; diff --git a/include/helpers.hpp b/include/helpers.hpp index 7026b416..2ce90926 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -85,4 +85,12 @@ // For lack of , this adds some more brevity #define RANGE(s) std::begin(s), std::end(s) +// Convenience feature for visiting variants. +template +struct Visitor : Ts... { + using Ts::operator()...; +}; +template +Visitor(Ts...) -> Visitor; + #endif // HELPERS_H diff --git a/src/asm/parser.y b/src/asm/parser.y index 87c6e685..a6afe0bd 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -27,6 +27,7 @@ #include "extern/utf8decoder.hpp" +#include "helpers.hpp" #include "linkdefs.hpp" #include "platform.hpp" // strncasecmp, strdup @@ -324,10 +325,10 @@ static void strfmt(char *dest, size_t destLen, char const *fmt, std::variant &arg = args[a++]; static char buf[MAXSTRLEN + 1]; - if (std::holds_alternative(arg)) - fmt_PrintNumber(buf, sizeof(buf), &spec, std::get(arg)); - else - fmt_PrintString(buf, sizeof(buf), &spec, std::get(arg)); + std::visit(Visitor{ + [&](uint32_t num) { fmt_PrintNumber(buf, sizeof(buf), &spec, num); }, + [&](char *str) { fmt_PrintString(buf, sizeof(buf), &spec, str); }, + }, arg); i += snprintf(&dest[i], destLen - i, "%s", buf); }