recursive equal, and firstDifference functions
timotheecour
timothee.cour2 at gmail.com
Tue Mar 19 11:13:14 PDT 2013
> And how do you even have the concept of recursion without some
> sort of range or container to recursively iterate through?
It's not hard: I've done it for a serialization library I've been
working on (which has some advantages over std.orange, such as
serializing to json/binary etc. more on this later), as well as
for my toStringRecurse: it works on any data type roughly as
follows:
auto equalRecurse(T)(T a) {
static if isAssociativeArray!(T)) {
}
else static if(isArray!(T)) {
}
else static if(is(T == struct) ){
foreach(i, member; a.tupleof) {
...
}
else static if...
}
>> Expecting the compiler to automagically figure out how to
>> compare two types for you is just begging for trouble
I beg to differ. I like to be as lazy as possible when writing
user code (as opposed to library code). The compiler can do a lot
of stuff automagically in D thanks to CT reflection. I didn't run
into problems when using the serialization on rather complex
nested objects.
More information about the Digitalmars-d-learn
mailing list