const again
Walter Bright
newshound1 at digitalmars.com
Thu Dec 6 15:05:17 PST 2007
Christopher Wright wrote:
>> 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?
No, it is a mutable pointer to a const Foo. A const pointer to a const
Foo would be:
const(Foo*) t;
> 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?
Yes, because T[] will be the same thing as const(Foo)[]. Hiding it
behind an alias and a template won't change that <g>.
More information about the Digitalmars-d
mailing list