On Wednesday, 24 July 2013 at 11:26:32 UTC, Mike Parker wrote:
This is the exact behavior I would expect. I think of auto as
"this variable is going to be the same type as that variable."
Since in is const int, then j also is going to be const int. If
you want to copy n into a nonconst variable, you have to cast
away the const.
int j = cast( int )n;
auto j = cast( int )n;
Casting is always an extreme measure, one that should be avoided
in mundane code as much as possible. Despite the fact `auto`
behaves as it should, this really highlights lack of `mutable`
attribute in language.