Invariant Question (yes, another one)

Matti Niemenmaa see_signature at for.real.address
Thu Nov 15 07:16:12 PST 2007


Janice Caron wrote:
> On 11/15/07, Xinok <xnknet at gmail.com> wrote:
>> Const is the read-only type, meaning that the data COULD change
>> unexpectedly. However, invariant means the data is guaranteed never to
>> change. You can't guarantee const data is never going to change,
> 
> I know that. You're stating the obvious.
> 
>> which
>> is why it gives you an error.
> 
> I don't follow that reasoning. Please explain in more detail.
> invariant(char)[] can always be implicitly cast to const(char)[] ...
> and that's exactly what I'm trying to do.

If I understood correctly:

An invariant variable cannot change, period. If you cast an invariant variable
to const, and then change it through the const variable (this bit seems dubious
to me), the invariant variable has changed. But this isn't permissible. Hence,
you can't cast invariant to const.

-- 
E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi



More information about the Digitalmars-d mailing list