Andrei Alexandrescu wrote: > interface Cloneable(T) if (is(T == class)) > { > private T doClone(); // must implement but can't call > T clone() // this is what everybody can call > { > auto result = doClone(); > assert(typeof(result) == typeof(this)); > assert(this.equals(result)); > return result; > } > }
This sounds like a case for contract inheritance rather than two layers of functions. > interface ComparableForEquality(T) > { > protected bool doEquals(T); > final bool equals(T rhs) > { > auto result = doEquals(rhs); > assert(rhs.equals(cast(T) this) == result); > return result; > } > } This, on the other hand, does require two layers of functions if you want to remove the infinite recursion by replacing the 'equals' in the assertion with 'doEquals'. -- Rainer Deyke - rain...@eldwood.com