On 3/29/12, Andrej Mitrovic <andrej.mitrov...@gmail.com> wrote: > Speaking of which, does anyone have some sort of template to > autogenerate an opEquals that compares all fields of a struct via > '=='?
Well that took 2 seconds. import std.range; template safeOpEquals(T) { bool opEquals(T t) { foreach (lhsField, rhsField; lockstep(this.tupleof, t.tupleof)) { if (lhsField != rhsField) return false; } return true; } } struct Foo { int[] arr; mixin safeOpEquals!Foo; } void main() { Foo a, b; a.arr = [1, 2, 3].dup; b.arr = [1, 2, 3].dup; assert(a == b); } D makes things so damn easy.