From slices to perfect imitators: opByValue

monarch_dodra via Digitalmars-d digitalmars-d at puremagic.com
Thu May 8 06:57:22 PDT 2014


On Thursday, 8 May 2014 at 12:48:17 UTC, Sönke Ludwig wrote:
> Am 08.05.2014 13:05, schrieb monarch_dodra:
>> Not necessarily: As soon as indirections come into play, you 
>> are
>> basically screwed, since const is "turtles all the way down".
>>
>> So for example, the conversion from "const RefCounted!T" to
>> "RefCounted!(const T)" is simply not possible, because it 
>> strips the
>> const-ness of the ref count.
>>
>> What we would *really* need here is NOT:
>> "const RefCounted!T" => "RefCounted!(const T)"
>> But rather
>> "RefCounted!T" => "RefCounted!(const T)"
>>
>> The idea is to cut out the "head const" directly. This also 
>> applies to
>> most ranges too BTW.
>>
>> We'd be much better of if we never used `const MyRange!T` to 
>> begin with,
>> but simply had a conversion from `MyRange!T` to 
>> `MyRange!(const T)`,
>> which references the same data.
>>
>> In fact, I'm wondering if this might not be a more interesting 
>> direction
>> to explore.
>
> The reference count _must_ be handled separate from the 
> payload's const-ness, or a const(RefCount!T) would be 
> completely dysfunctional.

Right, which is my point: "const(RefCount!T)" *is* dysfunctional, 
which is why you'd want to skip it out entirely in the first 
place.This holds true for types implemented with RefCount, such 
as Array and Array.Range.


More information about the Digitalmars-d mailing list