Why can't we define re-assignable const reference variable?
Steven Schveighoffer
schveiguy at yahoo.com
Tue Feb 19 15:13:48 PST 2008
"Sergey Gromov" wrote
> Please, why invent new syntax ?
>
> const(T) t; // mutable ref to const T
> const{T t;} // const ref to const T, because of transitiviness
>
> This syntax even worked in one of the previous compiler versions!
Yes, this is one of the trials of Walter to see if he could get tail-const
to work.
The problem is if T is not a reference/pointer (such as int). Now:
const(T) t;
T t;
are equivalent, which is necessary to make that const system work. To have
some variable declared as const(T), and then allow assignment to that
variable is completely inconsistent with the fundamental usage of
parentheses. If you have something defined as f(x), the entirety of x
should be affected by f. This is why that system was dropped, as it should
have been.
-Steve
More information about the Digitalmars-d
mailing list