Marking its various bits as @nogc is still proving to be a challenge
since Object.destroy is not @nogc, among other things.
We _are_ using GC.addRange and GC.removeRange to handle anything
inside the underlying type that uses GC.
Why the user would do this in conjunction with Unique is
questionable, but until we can explicitly forbid doing so, let's
not break garbage collection for them.
Note that this also makes nested structs and classes impossible,
because there is no way AFAIK to get the frame pointer into
unique()
Also cleaned up the Unique documentation a bit.
Unfortunately some of the unittests could not be used as documented
unittests because placing them in the struct gives an error about
RTInfo!(Nested) being recursvely expanded.
- add RefCounted!T.this(T) which takes an RValue or a copy
and use move to initialized the refcounted store
- add refCounted to infer T from the argument and disable
RefCounted's autoInit, also move initializes the store
From the related pull request
(https://github.com/D-Programming-Language/phobos/pull/3139),
there seems to be a general consensus that it is more important to
do Unique "right", even if that means breaking changes, so long as
there is a clean migration path. With that in mind, I have made the
following additional changes:
- Instead of constructors that take a RefT, Uniques can now be
created one of two ways: via .create or .fromNested.
See the DDocs of both for details.
- opDot is replaced with "alias _p this". A cursorty Google search
indicates that opDot is deprecated and that alias this is the
preferred method. Like C++'s unique_ptr, Unique now enjoys
pointer-like operations (such as dereferencing),
but cannot be set to null or assigned from a different pointer
due to opAssign and the disabled postblit constructor.
- Consequently, isEmpty has been removed. Instead, just use
is null as you would with a pointer.
- Removal of redundant unit tests
- Various comment and unit test cleanup
It is currently impossible (or so it seems) to use malloc and
emplace to create a nested class or struct, so we'll return to
using the GC for now. We'll also restore the constructors that take
a RefT, as using new _inside_ the context of the nested class or
struct is apparently the only way to create one currently.
I picked up the trick of converting a pointer into an array
using the [0 .. size] syntax from std/regex/package.d.
Unique.create is still segfaulting, but this seems to be an issue
with the class version of emplace regardless of this Unique work.
The bug can be found here:
https://issues.dlang.org/show_bug.cgi?id=14402