Auto keyword with const variable
monarch_dodra
monarchdodra at gmail.com
Wed Jul 24 03:09:24 PDT 2013
On Wednesday, 24 July 2013 at 10:01:14 UTC, bearophile wrote:
> dennis luehring:
>
>> and how would it look to preserve the const if auto would
>> auto-rip it of?
>
> You could write:
>
> immutable j = n;
>
> For every default behavour you need a way to implement the
> other nicely :-)
>
> Currently for the problem of the OP you can use this:
>
> Unqual!(typeof(n)) j = n;
>
> Bye,
> bearophile
Definitly. Auto means "same type". I think it could be OK if it
followed IFTI rules? After all, in concept, it's kind of the same
mechanism.
I wouldn't go any further than that though.
//----
void foo(T)(T t)
{
pragma(msg, T.stringof);
}
void main(string[] args)
{
immutable int[] i = [1, 2, 3];
foo(i);
auto j = i;
pragma(msg, typeof(j).stringof);
}
//----
immutable(int)[]
immutable(int[])
//----
Problem: I don't really see a good usecase for making auto have
special IFTI behavior. Keeping it to "same type, 100% of the
time" seems like the best.
More information about the Digitalmars-d-learn
mailing list