Whenever D is brought up to the general programming public,
the garbage collector is quickly raised as a point of contention.
Regardless of how legitimate or well-informed these concerns are,
it would be a massive public relations boon --- and great for the language,
to boot --- if we could trot out a solid said of RAII-based smart pointers
for those who prefer to use them. We have a solid start in
std.typecons.Unique and std.typecons.RefCounted.
Unfortunately, these classes seem to be victims of bit rot and
compiler bugs of days long gone.
An overview of the changes in this commit is as follows:
- Unique's underlying data now uses malloc and free
instead of the garbage collector. Given that many people use RAII
smart pointers to escape the GC, it seems to make more sense to
avoid it here. On a related note, isn't delete deprecated?
The current destructor uses it.
- std.algorithm.move is used instead of a special release
member function. Whether by design or by happy accident,
move transfers ownership between Unique pointers in a very
similar manner to C++'s std::move with std::unique_ptr.
Along with being a familiar paradigm to C++ users,
using move to transfer ownership makes more intuitive sense
and builds consistency with the rest of Phobos.
- With std.algorithm.move transferring ownership, release now just
frees the underlying pointer and nulls the Unique.
- Unique.create is no longer compiled out using version(None).
Regardless of whether or not there is language support for
checking uniqueness, a utility function that creates a Unique,
taking the same arguments as the underlying type's constructor,
is extremely useful, as demonstrated by the addition of
make_unique to C++14.
- Because Unique.create is now in place and Unique is backed with
malloc, constructors taking a pointer have been removed.
This encourages the use of create as the idiomatic,
consistent method to, well, create Unique objects.
If one can only get a Unique by calling create or moving another
into it, we also ensures uniqueness in one fell swoop.
- A new method, get, returns the underlying pointer, for use in
functions and code that do not play a role in the life cycle
of the object. Smart pointers are as much about ownership
semantics as they are about allocating and freeing memory,
and non-owning code should continue to refer to data using a raw
pointer or a reference.
using selective import
remove nonsense code
integration of static this.
add a comment
avoiding some warnings
remove InvalidTypeException
improve readability
The reason is to do not import `std.uni` tables, `std.string` and
probably `std.algorithm`. Note that format is used in CTFE code and
`Exception` handing.
And it is more comfortable to import `format` from `std.format`.
std.format: clean imports (2)
remove import std.math : pow from std.uni
update scope imports in std.algorithm
update scope imports in std.exception
doFormat -> template
update scope imports in std.typecons
update scope imports in std.functional
update scope imports in std.range
update std.conv scope import
std.format: clean imports (2)
remove import std.math : pow from std.uni
update scope imports in std.algorithm
update scope imports in std.exception
doFormat -> template
update scope imports in std.typecons
update scope imports in std.functional
update scope imports in std.range
move sfromat
add public import of sformat
use std.uni