I want to have smart pointers instead
I want to have smart pointers instead
int main(string[] args) @nogc { ... }Most of the community packages out there use the GC. Some though are transitioning to a std.experimental.allocator interface, like this containers library https://github.com/economicmodeling/containers
The way I see it, GC should just belong as deferred_ptr
In this case, grandparent did mention a memory management technique, namely garbage collection.
Memory management + plus typically required thread safety usually means reference counting.
Somehow I wasn't considering unique_ptr<T> as a smart pointer, despite using it all the time for resource management to avoid writing wrapper classes.
I do now, you're right.
Also, the lack of checking leads to unique_ptr<T> dereferences potentially having undefined behavior (i.e. whenever you try to dereference a unique pointer that is null [1]).
[1] http://en.cppreference.com/w/cpp/memory/unique_ptr/operator*
That said, the null checks required for C++'s destructor semantics are definitely a little more interesting in this respect, given one is rarely going to do this with raw pointers (although the cases when you don't need to do it also seem like cases the optimiser can handle fairly easily), but an extra branch and/or write at least seems significantly qualitatively different to the full reference counting that people often think of when talking about "smart pointers", which is the point the parent is trying to make (smart pointers aren't just reference counting).
Also, the cost of it not being memory-safe should not be ignored.
In any case, it is unfortunate that unique_ptr is not memory safe, but it also not at all notable, as pretty much nothing in C++ is completely memory safe (even the other smart pointers like shared_ptr).
The deeper problem is that unique pointers essentially are a sort of linear/affine type system, but that C++ leaves the actual checks to the runtime (which implements some, but not all of them).
I think my original point still stands here though: smart pointers != refcounting, inherently.