diff options
Diffstat (limited to 'src/common/Utilities/StringFormat.h')
-rw-r--r-- | src/common/Utilities/StringFormat.h | 16 |
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 |