IFTI, value types, and top-level const
monarch_dodra
monarchdodra at gmail.com
Fri Jun 7 09:24:14 PDT 2013
On Friday, 7 June 2013 at 13:58:33 UTC, Peter Alexander wrote:
> This code fails to compile because T is deduced to be `const
> int`:
>
> void foo(T)(T x)
> {
> x++;
> }
>
> void main()
> {
> const int y = 0;
> foo(y);
> }
>
>
> Analogous code in C++ works because C++ strips the top-level
> const.
>
> Is there any reason this isn't done in D with non-ref value
> type parameters? Of course, I can use Unqual, but it is a
> hassle to always remember. It also doesn't help with bloat
> because these will all call different functions:
>
> const int a;
> immutable int b;
> int c;
> foo(a);
> foo(b);
> foo(c);
>
> What is the value in things being the way they are?
I seem to specifically remember that it *didn't* work this way.
Isn't this a regression?
More information about the Digitalmars-d
mailing list