Make error_code formatter debug-enabled

This commit is contained in:
Victor Zverovich
2025-10-19 10:35:45 -07:00
parent a2289b8593
commit 08d38d6e78
2 changed files with 7 additions and 0 deletions

View File

@@ -513,6 +513,8 @@ template <> struct formatter<std::error_code> {
bool debug_ = false;
public:
FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; }
FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* {
auto it = ctx.begin(), end = ctx.end();
if (it == end) return it;

View File

@@ -13,6 +13,7 @@
#include <vector>
#include "fmt/os.h" // fmt::system_category
#include "fmt/ranges.h"
#include "gtest-extra.h" // StartsWith
#ifdef __cpp_lib_filesystem
@@ -335,6 +336,10 @@ TEST(std_test, error_code) {
EXPECT_EQ(fmt::format("{:s}", ec), ec.message());
EXPECT_EQ(fmt::format("{:?}", std::error_code(42, generic)),
"\"generic:42\"");
EXPECT_EQ(fmt::format("{}",
std::map<std::error_code, int>{
{std::error_code(42, generic), 0}}),
"{\"generic:42\": 0}");
}
template <typename Catch> void exception_test() {