mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-29 00:32:29 +00:00
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:
parent
f86e6f8eb0
commit
d7b1919b29
2 changed files with 62 additions and 38 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue