Skip to content

Commit

Permalink
Replace vararg function with template varargs
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
  • Loading branch information
Caellian committed May 25, 2024
1 parent e642130 commit 5bf3551
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/colours.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

#include "logging.h"

#include <cstdarg>
#include <cstdio>
#include <optional>

Expand All @@ -57,15 +56,13 @@ Colour Colour::from_argb32(uint32_t argb) {
#endif /* BUILD_COLOUR_NAME_MAP */

std::optional<Colour> inline no_colour() { return std::nullopt; }
template <typename... Args>
std::optional<Colour> parse_error(const std::string &color_str,
const char *format...) {
va_list args;
va_start(args, format);
size_t len = snprintf(nullptr, 0, format, args);
const char *format, Args... args) {
size_t len = snprintf(nullptr, 0, format, args...);

char *reason = new char[len + 1];
snprintf(reason, len + 1, format, args);
va_end(args);
snprintf(reason, len + 1, format, args...);

CRIT_ERR("can't parse color '%s' (len: %d): %s", color_str.c_str(),
color_str.length(), reason);
Expand Down

0 comments on commit 5bf3551

Please sign in to comment.