const(Object)ref is here!

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Dec 7 08:15:33 PST 2010


On 12/7/10 7:05 AM, Michel Fortin wrote:
> On 2010-12-07 09:05:20 -0500, Jason House <jason.james.house at gmail.com>
> said:
>
>> Michel Fortin Wrote:
>>> The point is that the 'ref' in in the 'b' and 'c' variable declaration
>>> has the effect of changing the ref from B and C from const to mutable,
>>> even for B where the ref was explicitly specified to be const. I was
>>> wondering if some people would find that surprising, but if I
>>> understand you well that's what you expect when seeing this, right?
>>
>> I've been wondering if it makes more sense for 'ref' to be a storage
>> class rather than some kind of type constructor. Doing that would make
>> the typedef's with ref be illegal. It'd also make foo!(const(T) ref)
>> be illegal as well as (const(T) ref)[]. As a storage class, it can
>> only be added to variable declarations.
>>
>> I think the array case would be missed. I'm not sure what people would
>> think of the template case, especially when it pops up in code such as
>> foo!(typeof(x)). If ref isn't a storage class, then generic
>> programmers will need an equivalent to unqual that only strips the
>> outer-most ref. As a storage class typeof would not return the ref.
>> How do templates work with your patch?
>
>  From my tests, templates work as they should. For instance, I can
> easily call std.algorithm.sort on an array of const(Object)ref.

Does it work on a general random-access range? Generally, does the 
feature have a solution for all issues discussed?

Andrei


More information about the Digitalmars-d mailing list