any news on const/invariant?

Walter Bright newshound1 at digitalmars.com
Wed Nov 28 21:02:29 PST 2007


Steven Schveighoffer wrote:
> "Derek Parnell" wrote
>> Also, what is the syntax now for declaring a const function that returns a
>> const value?
> 
> const const(int)* f(){ ... }
> or
> const(int)* f() const { ... }
> 
> This REALLY REALLY needs an example in the docs.  Walter, please do 
> something about this.  The const void f() example doesn't cut it, especially 
> for C++ defectors.  I had to ask this question a while back in the learn NG 
> after carefully examining the docs :)
> 
> Also, will the following compile?

Yes.

> const int* f1() const {...}

A const function returning an int*. The const here is just redundant.

> invariant int* f2() const {...}

An invariant function returning an int*. The invariant overrides the const.

> And if they do, what do they mean?



More information about the Digitalmars-d mailing list