I just got it! (invariant/const)

guslay guslay at gmail.com
Wed Apr 9 10:36:24 PDT 2008


Steven Schveighoffer Wrote:

> "guslay" wrote
> > Janice Caron Wrote:
> >
> >> On 09/04/2008, Georg Wrede wrote:
> >>
> >>     int f(invariant D d) invariant pure { ... }
> >
> > Shouldn't it be
> >
> > int f(invariant D d) pure { ... }
> >
> > Pure functions are a subset of invariant functions, no?
> 
> No.
> 
> A function does not necessarily need to take an invariant 'this' pointer to 
> be pure.
> 
> For example:
> 
> class C
> {
>    invariant int x;
>    pure int getX() { return x;}
> }
> 
> void foo()
> {
> C c = new C;
> c.getX(); // ok
> }
> 
> -Steve 

c.getX() is equivalent to " int getX( ref C this ) ", so its not pure. 

I will restate: Pure member functions are a subset of invariant member functions.





More information about the Digitalmars-d mailing list