From 2e11b2d35a0ebd38bbde8a0875e93d3830da4ccf Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Thu, 15 Apr 2021 22:06:18 +0200 Subject: [PATCH] AK: Add outln_if and warnln_if This uses the same gating mechanism as dbgln_if and should be equivalent to #define flag etc --- AK/Format.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/AK/Format.h b/AK/Format.h index a46b06c4b59..3193c792208 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -384,13 +384,29 @@ void outln(CheckedFormatString&& fmtstr, const Parameters&... par inline void outln() { outln(stdout); } +# define outln_if(flag, fmt, ...) \ + do { \ + if constexpr (flag) \ + outln(fmt, ##__VA_ARGS__); \ + } while (0) + template -void warn(CheckedFormatString&& fmtstr, const Parameters&... parameters) { out(stderr, move(fmtstr), parameters...); } +void warn(CheckedFormatString&& fmtstr, const Parameters&... parameters) +{ + out(stderr, move(fmtstr), parameters...); +} template void warnln(CheckedFormatString&& fmtstr, const Parameters&... parameters) { outln(stderr, move(fmtstr), parameters...); } inline void warnln() { outln(stderr); } + +# define warnln_if(flag, fmt, ...) \ + do { \ + if constexpr (flag) \ + outln(fmt, ##__VA_ARGS__); \ + } while (0) + #endif void vdbgln(StringView fmtstr, TypeErasedFormatParams);