ctl::unique_ptr improvements and cleanup (#1221)

Explicitly value-initializes the deleter, even though I have not found a
way to get the deleter to act like it’s been default-initialized in unit
tests so far.

Uses auto in reset. The static cast is apparently not needed (unless I’m
missing some case I didn’t think of.)

Implements the general move constructor - turns out that the reason this
didn’t work before was that default_delete<U> was not move constructible
from default_delete<T>.

Drop inline specifiers from functions defined entirely inside the struct
definition since they are implicitly inline.

* Cleans 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. (?)

* Tests Base/Derived reset.

* Adds some constexpr declarations.

* Adds default_delete specialization for T[].

* Makes parameters const.
This commit is contained in:
Steven Dee (Jōshin) 2024-06-20 18:44:31 -04:00 committed by GitHub
parent f86e6f8eb0
commit d7b1919b29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 62 additions and 38 deletions

View file

@ -91,6 +91,12 @@ struct SetsGDtor
}
};
struct Base
{};
struct Derived : Base
{};
int
main()
{
@ -211,7 +217,16 @@ main()
Ptr<int, StatefulDeleter> y(&a);
}
{
Ptr<Base> x(new Base);
x.reset(new Derived);
Ptr<Derived> y(new Derived);
Ptr<Base> z(ctl::move(y));
}
// next is 18
CheckForMemoryLeaks();
return 0;
}