mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-03 20:54:08 +00:00
Format unique_ptr with custom deleter (#3177)
* Format unique_ptr with custom deleter Added deleter type to fmt::ptr unique_ptr overload. Deleter type is part of the unique_ptr type. * Review: apply clang-format Co-authored-by: Hans-Martin B. Jensen <haje@eposaudio.com>
This commit is contained in:
parent
d2e89c8b08
commit
7df30f91ae
@ -3888,7 +3888,8 @@ template <typename T> auto ptr(T p) -> const void* {
|
||||
static_assert(std::is_pointer<T>::value, "");
|
||||
return detail::bit_cast<const void*>(p);
|
||||
}
|
||||
template <typename T> auto ptr(const std::unique_ptr<T>& p) -> const void* {
|
||||
template <typename T, typename Deleter>
|
||||
auto ptr(const std::unique_ptr<T, Deleter>& p) -> const void* {
|
||||
return p.get();
|
||||
}
|
||||
template <typename T> auto ptr(const std::shared_ptr<T>& p) -> const void* {
|
||||
|
@ -1508,6 +1508,12 @@ TEST(format_test, format_pointer) {
|
||||
std::unique_ptr<int> up(new int(1));
|
||||
EXPECT_EQ(fmt::format("{}", fmt::ptr(up.get())),
|
||||
fmt::format("{}", fmt::ptr(up)));
|
||||
struct custom_deleter {
|
||||
void operator()(int* p) const { delete p; }
|
||||
};
|
||||
std::unique_ptr<int, custom_deleter> upcd(new int(1));
|
||||
EXPECT_EQ(fmt::format("{}", fmt::ptr(upcd.get())),
|
||||
fmt::format("{}", fmt::ptr(upcd)));
|
||||
std::shared_ptr<int> sp(new int(1));
|
||||
EXPECT_EQ(fmt::format("{}", fmt::ptr(sp.get())),
|
||||
fmt::format("{}", fmt::ptr(sp)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user