Extended Type Design.
Tyler Knott
tywebmail at mailcity.com
Tue Mar 20 16:34:42 PDT 2007
Chris Nicholson-Sauls wrote:
> As I understand, there will be an implicit cast of mutables to
> immutables, so assuming 'const' appears under 'invariant' in this list,
> I would expect|hope it to be 'const Foo*' so that it is passable to
> either 'const' or 'invariant' typed parameters. Ie:
>
Actually, I take back what I said in my previous post in this thread. Taking the address of a final variable should
always result in an invariant pointer. The reason is that invariant references require the data they reference to
never, ever change whereas const references expect the data they reference to be changed by other
non-const/non-immutable references to that data. Obviously, since const references can't guarantee the data they
reference won't change they can't be cast to immutable references at all, but because const references can still
guarantee they won't mutate the data they reference immutable references can be freely cast to const references.
More information about the Digitalmars-d
mailing list