aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/StringFormat.h
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-02-28 20:42:20 +0100
committerShauren <shauren.trinity@gmail.com>2024-02-28 20:42:20 +0100
commit20b29c5ff56c605d52fb6e391c28daea26ab719a (patch)
treeb97c7bc41678ac254981fc4624ae78074112a725 /src/common/Utilities/StringFormat.h
parent288966e796bfa4309fdcb08b9392b61befc3faab (diff)
Core/Misc: Allow formatting optionals with Trinity::StringFormat
Diffstat (limited to 'src/common/Utilities/StringFormat.h')
-rw-r--r--src/common/Utilities/StringFormat.h16
1 files changed, 15 insertions, 1 deletions
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 <fmt/core.h>
namespace Trinity
{
@@ -108,4 +109,17 @@ namespace Trinity
}
}
+template<typename T, typename Char>
+struct fmt::formatter<Optional<T>, Char> : formatter<T, Char>
+{
+ template<typename FormatContext>
+ auto format(Optional<T> const& value, FormatContext& ctx) const -> decltype(ctx.out())
+ {
+ if (value.has_value())
+ return formatter<T, Char>::format(*value, ctx);
+
+ return formatter<std::string_view, Char>().format("(nullopt)", ctx);
+ }
+};
+
#endif