Object.opEquals, opCmp, toHash

Jonathan M Davis jmdavisProg at gmx.com
Thu Feb 16 01:27:31 PST 2012


On Thursday, February 16, 2012 00:35:20 Walter Bright wrote:
> These all need to be:
> 
>      const pure nothrow @safe
> 
> Unless this is done, the utility of const, pure, nothrow and @safe is rather
> crippled.
> 
> Any reason why they shouldn't be?
> 
> One reason is memoization, aka lazy initialization, aka logical const. I
> don't believe these are worth it. If you must do it inside those functions
> (and functions that override them), you're on your own to make it work
> right (use unsafe casts, etc.).

I think that that's essentially the conclusion that we as a group have come to 
in discussions on it in the past. The exception are those folks who don't want 
any of those functions to be const, because that cripples caching, lazy 
initialization, etc for classes. And so they argue against the whole idea. But 
we _have_ to make them const or, as you say, const is horribly crippled. It's 
one area where D's const is rather costly, but I don't see any way around it.

toString is another one, though making that pure right now just wouldn't work, 
because so little string stuff can pure pure (e.g. primarily because format, 
to, and appender aren't pure). But that really needs to be fixed anyway.

- Jonathan M Davis


More information about the Digitalmars-d mailing list