Issue 3789, stucts equality

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Mar 29 04:56:28 PDT 2012


On 3/29/12, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
> D makes things so damn easy.

Correction, makes things easier. No need to pass the type of 'this':

template safeOpEquals()
{
    bool opEquals(typeof(this) t)
    {
        foreach (lhsField, rhsField; lockstep(this.tupleof, t.tupleof)) {
            if (lhsField != rhsField)
                return false;
        }
        return true;
    }
}
struct Foo
{
    int[] arr;
    mixin safeOpEquals;
}


More information about the Digitalmars-d mailing list