Object.opEquals, opCmp, toHash
Timon Gehr
timon.gehr at gmx.ch
Thu Feb 16 07:52:44 PST 2012
On 02/16/2012 09:35 AM, 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?
The utility of const, pure, nothrow and @safe is already rather crippled
when using Phobos. It is a rather small minority of my pure functions
that are effectively annotated pure, because most of Phobos is not
properly annotated and the inference for templates does not work
satisfactorily yet.
So imo, making opEquals, opCmp, toHash const pure nothrow @safe is
blocked by properly annotating Phobos as well as the following issues:
Bugs in existing attribute inference:
http://d.puremagic.com/issues/show_bug.cgi?id=7205
http://d.puremagic.com/issues/show_bug.cgi?id=7511
Enhancement required for making templates const correct:
http://d.puremagic.com/issues/show_bug.cgi?id=7521
>
> 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.).
It would be helpful if we could add cast(pure) for that purpose. The
documentation could state that cast(pure) is only valid if the behaviour
of the enclosing function still appears to be pure.
More information about the Digitalmars-d
mailing list