int[][] better type match than int[] for int[]?!
Andrej Mitrovic
andrej.mitrovich at gmail.com
Mon Sep 17 06:21:41 PDT 2012
This completely surprised me:
bool doMatch(int[] lhsArr, int[][] arrArr)
{
foreach (int[] rhsArr; arrArr)
{
writeln("if (!doMatch(lhsArr, arrArr))");
if (!.doMatch(lhsArr, arrArr))
return false;
}
return true;
}
bool doMatch(int[] lhsArr, int[] rhsArr)
{
return true;
}
void main()
{
int[] x = [1, 2];
int[][] y = [[1, 2], [1, 2]];
bool b = doMatch(x, y);
}
This will enter an infinite loop because the first doMatch overload
gets recursively called. I don't understand why the second overload
isn't picked up as a match in the call "doMatch(lhsArr, arrArr)".
More information about the Digitalmars-d
mailing list