From 74e5e85467047c50b976e13b0ad520781b6b8017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Dee=20=28J=C5=8Dshin=29?= Date: Wed, 19 Jun 2024 06:52:09 -0700 Subject: [PATCH] Clean up reset to match spec Remove the variants from the T[] specialization. Also follow the spec on the order of operations in reset, which may matter if we are deleting an object that has a reference to the unique_ptr that is being reset. (?) --- ctl/unique_ptr.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/ctl/unique_ptr.h b/ctl/unique_ptr.h index dbdde7679..c2f8bf61c 100644 --- a/ctl/unique_ptr.h +++ b/ctl/unique_ptr.h @@ -70,7 +70,8 @@ struct unique_ptr ~unique_ptr() /* noexcept */ { - reset(); + if (p) + d(p); } unique_ptr& operator=(unique_ptr r) noexcept @@ -86,19 +87,12 @@ struct unique_ptr return r; } - void reset(const nullptr_t = nullptr) noexcept + void reset(const pointer p2 = pointer()) noexcept { - if (p) - d(p); - p = nullptr; - } - - void reset(auto* const p2) - { - if (p) { - d(p); - } + const pointer r = p; p = p2; + if (r) + d(r); } void swap(unique_ptr& r) noexcept