Const: what do you want to achieve (proposition...)?

Gilles G. schaouette at free.fr
Tue Nov 13 05:22:03 PST 2007


Janice Caron Wrote:

> On Nov 13, 2007 10:03 AM, Gilles G. <schaouette at free.fr> wrote:
> > So, what do you think?
> 
> It doesn't distinguish between const and invariant.
Of course, you need a keyword to express that something doesn't change, but you don't need a keyword to express that a function doesn't change its arguments.

> 
> If the function is a member function, it doesn't tell me if the class
> instance (this) will be modified.
This is the same problem as above, you need a keyword to express that something is a constant. I was talking about "how some people want to be sure data never gets modified when passed as an argument".

But now you could use the "invariant" keyword for that purpose:
class B{
    private int i=0;
    int invariant noModification(){return i;}
    int changeThis(int j){i=j;}
}
The benefit is that you only need one keyword to express that something doesn't change, ever.

...

Wow, maybe I should dreaming and wake up now...



More information about the Digitalmars-d mailing list