diff --git a/include/fmt/format.h b/include/fmt/format.h index 89834476..f77b51c6 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2553,6 +2553,14 @@ class basic_writer { void write(basic_string_view str, FormatSpecs... specs) { write_str(str, format_specs(specs...)); } + + template + typename std::enable_if::value>::type write(const T* p) { + format_specs specs; + specs.flags_ = HASH_FLAG; + specs.type_ = 'x'; + write_int(reinterpret_cast(p), specs); + } }; template diff --git a/test/format-test.cc b/test/format-test.cc index 67f6da35..56a1f879 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1609,6 +1609,7 @@ TEST(FormatTest, UdlTemplate) { TEST(FormatTest, ToString) { EXPECT_EQ("42", fmt::to_string(42)); + EXPECT_EQ("0x1234", fmt::to_string(reinterpret_cast(0x1234))); } TEST(FormatTest, ToWString) {