const(Object)ref is here!

Jason House jason.james.house at gmail.com
Tue Dec 7 06:05:20 PST 2010


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?


More information about the Digitalmars-d mailing list