pass-by-ref semantics for structs (was Deque impl.)

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Jan 31 08:17:14 PST 2013


On 1/31/13 11:00 AM, Steven Schveighoffer wrote:
> On Thu, 31 Jan 2013 10:40:15 -0500, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>> It has a destructor.
>
> One which is not called if allocated on the heap.

That is correct. My point was that with structs we get to implement 
full-fledged reference counting for containers.

Reference counting makes a lot of sense for containers. They inherently 
own their internals, don't have cycles, and are massive enough to make 
pass by value effectively an anti-pattern (as it is for C++). At the 
same time memory reclamation is of high interest. Reference counting is 
really the sweet spot for containers.

> It's possible to make a class reference that is destroyed when going out
> of scope. Then you have the option, heap destroyed or stack destroyed.
>
> Not possible with structs (at least for now).

I don't understand this. Is it about the deprecated meaning of scope?


Andrei




More information about the Digitalmars-d mailing list