const again

Christopher Wright dhasenan at gmail.com
Thu Dec 6 14:54:31 PST 2007


Walter Bright wrote:
>> 1. The array itself is const and may not be resized or have its 
>> contents changed.
>> 2. The array is not const but its elements are, so the array may be 
>> resized, but only const member functions may be called on the 
>> contained objects.
>>
>> To me, "const(C)[]" looks like case 2, because only the element type 
>> is in parenthesis.  Thus "const C[]" or "const (C[])" would both 
>> represent case 1.  However, this is obviously not how things currently 
>> work.
> 
> Right, but under the new regime, that is how they would work.
> 
>> I this has something to do with the desire to shoehorn tail const into 
>> the design, but it doesn't feel natural to me.  Can you explain why it 
>> works the way it does?
> 
> I've given up on tail const in any of its forms. The new regime has no 
> tail const, no head const, it's just const, and fully transitive const 
> at that.

So if I have:
const(Foo)* t;
the pointer is const and points to a const Foo?

What about this:
template Ptr(T) {
    alias T* Ptr;
}
Ptr!(const(Foo)) t;

If I have a template method that says:
void Something (T)() {
    T[] stuff = new T[5];
    stuff[2] = T.init;
}
Something!(const(Foo));

Will that fail?



More information about the Digitalmars-d mailing list