finding composed structs

Tobias Pankrath tobias at pankrath.net
Tue Oct 30 13:16:11 PDT 2012


On Tuesday, 30 October 2012 at 19:16:18 UTC, Dan wrote:
> So until this bug is fixed any time I have any dynamic array, 
> including string in struct S, implement opEquals. When the bug 
> is fixed I can remove them. What I didn't realize is that 
> including an opEquals in A will cause generation of opEquals in 
> B,C,D for free (maybe only if called).
>
> If this is still off base please let me know.
>
> Thanks
> Dan

In the meantime you can use this function template to compare 
structs field by field.

bool oneStepEqual(T,F)(ref T lhs, ref F rhs)
     if(is(Unqual!T == Unqual!F) && is(T == struct))
{
         bool result = true;
     foreach(mem; __traits(allMembers, T))
     {
         static if(!is(typeof(__traits(getMember, T, mem)) == 
function))
         {
             result = result && (__traits(getMember, lhs, mem) == 
__traits(getMember, rhs, mem));
         }
     }
     return result;
}



More information about the Digitalmars-d-learn mailing list