Skip to content

Commit

Permalink
Clean up reset to match spec
Browse files Browse the repository at this point in the history
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. (?)
  • Loading branch information
mrdomino committed Jun 19, 2024
1 parent acbf10c commit 74e5e85
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions ctl/unique_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ struct unique_ptr

~unique_ptr() /* noexcept */
{
reset();
if (p)
d(p);
}

unique_ptr& operator=(unique_ptr r) noexcept
Expand All @@ -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
Expand Down

0 comments on commit 74e5e85

Please sign in to comment.