From 6bf039d7507504d001dd69f75c59e2204d5278b5 Mon Sep 17 00:00:00 2001
From: Victor Zverovich <viz@fb.com>
Date: Tue, 17 May 2022 16:31:06 -0700
Subject: [PATCH] Add std::thread::id formatter

---
 include/fmt/std.h | 8 +++++++-
 test/std-test.cc  | 4 ++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/fmt/std.h b/include/fmt/std.h
index 5e7d3668..baa30e1f 100644
--- a/include/fmt/std.h
+++ b/include/fmt/std.h
@@ -8,7 +8,9 @@
 #ifndef FMT_STD_H_
 #define FMT_STD_H_
 
-#include "format.h"
+#include <thread>
+
+#include "ostream.h"
 
 #if FMT_HAS_INCLUDE(<version>)
 #  include <version>
@@ -27,4 +29,8 @@ struct fmt::formatter<std::filesystem::path> : formatter<string_view> {
 };
 #endif
 
+FMT_BEGIN_NAMESPACE
+template <> struct formatter<std::thread::id> : ostream_formatter {};
+FMT_END_NAMESPACE
+
 #endif  // FMT_STD_H_
diff --git a/test/std-test.cc b/test/std-test.cc
index 36ce4ae3..6cda2891 100644
--- a/test/std-test.cc
+++ b/test/std-test.cc
@@ -14,3 +14,7 @@ TEST(std_test, path) {
   EXPECT_EQ(fmt::format("{:8}", std::filesystem::path("foo")), "foo     ");
 #endif
 }
+
+TEST(std_test, thread_id) {
+  EXPECT_FALSE(fmt::format("{}", std::this_thread::get_id()).empty());
+}