Add pointer support to basic_writer

This commit is contained in:
Victor Zverovich 2018-02-17 09:38:46 +00:00
parent 91721caa42
commit ce4a65ffea
2 changed files with 9 additions and 0 deletions

View File

@ -2553,6 +2553,14 @@ class basic_writer {
void write(basic_string_view<char_type> str, FormatSpecs... specs) { void write(basic_string_view<char_type> str, FormatSpecs... specs) {
write_str(str, format_specs(specs...)); write_str(str, format_specs(specs...));
} }
template <typename T>
typename std::enable_if<std::is_same<T, void>::value>::type write(const T* p) {
format_specs specs;
specs.flags_ = HASH_FLAG;
specs.type_ = 'x';
write_int(reinterpret_cast<uintptr_t>(p), specs);
}
}; };
template <typename Range> template <typename Range>

View File

@ -1609,6 +1609,7 @@ TEST(FormatTest, UdlTemplate) {
TEST(FormatTest, ToString) { TEST(FormatTest, ToString) {
EXPECT_EQ("42", fmt::to_string(42)); EXPECT_EQ("42", fmt::to_string(42));
EXPECT_EQ("0x1234", fmt::to_string(reinterpret_cast<void*>(0x1234)));
} }
TEST(FormatTest, ToWString) { TEST(FormatTest, ToWString) {