From ce4a65ffea258c52f3fa1fba63f2375a1241d4ab Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 17 Feb 2018 09:38:46 +0000 Subject: [PATCH] Add pointer support to basic_writer --- include/fmt/format.h | 8 ++++++++ test/format-test.cc | 1 + 2 files changed, 9 insertions(+) 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) {