any news on const/invariant?
Janice Caron
caron800 at googlemail.com
Fri Nov 30 00:08:52 PST 2007
On Nov 30, 2007 12:16 AM, Bruce Adams <tortoise_74 at yeah.who.co.uk> wrote:
> By the way to the const(this) advocates. Though the idea looks nice on the
> surface
> it isn't quite consistent. const works on type (declarations), this is a
> variable not
> a type.
Of course it's not consistent with existing syntax, otherwise it would
already compile. const(this) is proposed /new/ syntax. In fact, I
proposed extending the idea to const(lvalue), where lvalue is any
lvalue known at compile time. This would allow you to do:
class Outer
{
int outerX;
class Inner
{
int innerX;
const(outer) f(/*...*/)
}
}
Here f promises not to modify anything accessed through outer, so any
attempt to modify outerX (for example) would be picked up at compile
time. Personally, I really like the idea. const(this) becomes a
special case of that, and replaces const-for-member-functions very
nicely.
More information about the Digitalmars-d
mailing list