Too many attributes?

Bruno Medeiros brunodomedeiros+spam at com.gmail
Tue Apr 29 11:53:05 PDT 2008


Janice Caron wrote:
> On 25/04/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
>>  D2 will allow the following:
>>  pure invariant invariant(int) func(invariant(int)) nothrow;
>>  Am I the only one that thinks the above is too much?
> 
> You're not the only one.
> 

I second that.

> 
>     pure int func(invariant(C) a, invariant(C) b)
>     {
>         if (c == b) ...
> 
> Whoops! That won't compile, because - guess what!? - opEquals isn't pure!!!!
> 
> And it doesn't stop there - opEquals cannot be made pure just by
> changing its declaration, because a pure function must have invariant
> arguments, and opEquals has to work with or without invariant data.
> The upshot is that, eventually, Object.opEquals may have to be
> implemented twice:
> 
>     class Object
>     {
>         // the normal version
>         const bool opEquals(const Object o) {...}
> 
>         // the pure version
>         pure invariant bool opEquals(invariant Object o) {...}
>     }
> 
> and, therefore, so will anything that overloads it.
> 

Another example why "scoped const", despite "only" being a syntactical 
convenience, might be so important.


-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list