mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
fmt::ptr: support unique_ptr and shared_ptr.
This commit is contained in:
committed by
Victor Zverovich
parent
d306585a3f
commit
6b20863918
@ -3290,6 +3290,12 @@ typename Context::iterator vformat_to(
|
|||||||
// Example:
|
// Example:
|
||||||
// auto s = format("{}", ptr(p));
|
// 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 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 {
|
template <typename It, typename Char> struct arg_join {
|
||||||
It begin;
|
It begin;
|
||||||
|
@ -1600,6 +1600,10 @@ TEST(FormatterTest, FormatPointer) {
|
|||||||
EXPECT_EQ("0x" + std::string(sizeof(void*) * CHAR_BIT / 4, 'f'),
|
EXPECT_EQ("0x" + std::string(sizeof(void*) * CHAR_BIT / 4, 'f'),
|
||||||
format("{0}", reinterpret_cast<void*>(~uintptr_t())));
|
format("{0}", reinterpret_cast<void*>(~uintptr_t())));
|
||||||
EXPECT_EQ("0x1234", format("{}", fmt::ptr(reinterpret_cast<int*>(0x1234))));
|
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
|
#if FMT_USE_NULLPTR
|
||||||
EXPECT_EQ("0x0", format("{}", FMT_NULL));
|
EXPECT_EQ("0x0", format("{}", FMT_NULL));
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user