mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-05 02:27:45 +00:00
fmt::ptr: support unique_ptr and shared_ptr.
This commit is contained in:
parent
d306585a3f
commit
6b20863918
@ -3290,6 +3290,12 @@ typename Context::iterator vformat_to(
|
||||
// Example:
|
||||
// auto s = format("{}", ptr(p));
|
||||
template <typename T> inline const void* ptr(const T* p) { return p; }
|
||||
template <typename T> inline const void* ptr(const std::unique_ptr<T>& p) {
|
||||
return p.get();
|
||||
}
|
||||
template <typename T> inline const void* ptr(const std::shared_ptr<T>& p) {
|
||||
return p.get();
|
||||
}
|
||||
|
||||
template <typename It, typename Char> struct arg_join {
|
||||
It begin;
|
||||
|
@ -1600,6 +1600,10 @@ TEST(FormatterTest, FormatPointer) {
|
||||
EXPECT_EQ("0x" + std::string(sizeof(void*) * CHAR_BIT / 4, 'f'),
|
||||
format("{0}", reinterpret_cast<void*>(~uintptr_t())));
|
||||
EXPECT_EQ("0x1234", format("{}", fmt::ptr(reinterpret_cast<int*>(0x1234))));
|
||||
std::unique_ptr<int> up(new int(1));
|
||||
EXPECT_EQ(format("{}", fmt::ptr(up.get())), format("{}", fmt::ptr(up)));
|
||||
std::shared_ptr<int> sp(new int(1));
|
||||
EXPECT_EQ(format("{}", fmt::ptr(sp.get())), format("{}", fmt::ptr(sp)));
|
||||
#if FMT_USE_NULLPTR
|
||||
EXPECT_EQ("0x0", format("{}", FMT_NULL));
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user