recursive equal, and firstDifference functions

Dan dbdavidson at yahoo.com
Tue Mar 19 13:50:55 PDT 2013


On Tuesday, 19 March 2013 at 20:28:09 UTC, Jonathan M Davis wrote:
>
> Those are what opEquals, opCmp, and toHash are for. It might 
> make sense to
> define mixins which implement them for you (dealing with 
> whatever recursive
> semantics are necessary), but using external functions for 
> those just isn't
> going to fly.

Understand the sentiment. But you can easily have those external
functions call the member equivalents if they exist, and if not
still proceed and work. This is what they do, in fact. For 
instance,
it is nice to have the mixin for opCmp that actually calls member
opCmp if they exist. This opens the door a bit. It allows you to
have a reasonable opCmp for a type with a member that has none.

The same approach can be used for dup/gdup - which we have 
discussed
a few times now.

> The language and standard library are designed around them being
> part of the types themselves. Stuff like AAs won't work if 
> those functions
> aren't defined on the types themselves.
>

Sorry, I don't understand the last statement.




More information about the Digitalmars-d-learn mailing list