Object.opEquals, opCmp, toHash

bearophile bearophileHUGS at lycos.com
Thu Feb 16 05:05:50 PST 2012


Stewart Gordon:

> But if the method is pure, the compiler can automatically implement this as an optimisation.

Functions like toHash take nothing and return a single size_t (hash_t). Often you want to compute the hash value lazily, but this is not possible if toHash needs to be pure. A explicit optional @memoize annotation (similar to the std.functional.memoize) allows toHash to be both catching and safe. (I was also thinking about the idea of a @trusted_pure, but I don't like it, and I think it causes chaos).

Bye,
bearophile


More information about the Digitalmars-d mailing list