From 20b29c5ff56c605d52fb6e391c28daea26ab719a Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 28 Feb 2024 20:42:20 +0100 Subject: Core/Misc: Allow formatting optionals with Trinity::StringFormat --- src/common/Utilities/StringFormat.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/common/Utilities/StringFormat.h') diff --git a/src/common/Utilities/StringFormat.h b/src/common/Utilities/StringFormat.h index d34528a04df..fd31ddc28d5 100644 --- a/src/common/Utilities/StringFormat.h +++ b/src/common/Utilities/StringFormat.h @@ -18,7 +18,8 @@ #ifndef TRINITYCORE_STRING_FORMAT_H #define TRINITYCORE_STRING_FORMAT_H -#include "fmt/core.h" +#include "Optional.h" +#include namespace Trinity { @@ -108,4 +109,17 @@ namespace Trinity } } +template +struct fmt::formatter, Char> : formatter +{ + template + auto format(Optional const& value, FormatContext& ctx) const -> decltype(ctx.out()) + { + if (value.has_value()) + return formatter::format(*value, ctx); + + return formatter().format("(nullopt)", ctx); + } +}; + #endif -- cgit v1.2.3