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

Rainer Schuetze r.sagitario at gmx.de
Fri Feb 1 12:14:54 PST 2013



On 01.02.2013 20:18, monarch_dodra wrote:
> On Friday, 1 February 2013 at 19:10:26 UTC, Rainer Schuetze wrote:
>>
>>
>> On 01.02.2013 09:06, Dmitry Olshansky wrote:
>>> 01-Feb-2013 00:32, Rainer Schuetze пишет:
>>>>
>>>>
>>>> - how do you reference count immutable containers? You'll have to cast
>>>> the payload to mutable and assume it is not in read-only memory.
>>>
>>> Containers of immutables can have ref-count easily.
>>> And I'd say fully immutable containers are rare case and can rely on GC.
>>
>> Do you want different implementations of the containers depending on
>> the mutable/immutable/shared modifier? Would that be possible?
>
> You can only do that on the qualifier of the *parameters*, not the
> container itself.

Ok, but that won't help changing reference count semantics, because the 
type of the elements are irrelevant here. It's about the container itself.

>
> This is not possible because an S "is a" const(S). If the implementation
> of an S was different from a const(S), then you'd violate that. At best,
> a const(S) is an S with restricted possibilities, bot not *different*
> possibilities.

I guess you would have to convert it to a different type, but it can be 
an efficient operation transferring the payload unmodified. Also, when 
converting to shared, you might even be able to verify that there are no 
other references left (that must be non-sharing).


More information about the Digitalmars-d mailing list