Strange output
Daemon
daemon at yahoo.com
Fri Jun 7 12:10:53 PDT 2013
The following program is supposed to print out only numbers that
are less than 5, yet the number 63 gets printed.
module main;
import std.stdio;
import std.conv;
int main(string[] argv)
{
auto de = find!(delegate(a) { return a < 5; })([10, 11, 15, 16,
27, 20, 2, -4, -17, 8, 64, 6]);
foreach (int b; de[0 .. $])
{
writeln(b);
}
readln();
return 0;
}
T[] find(alias pred, T)(T[] input)
if (is(typeof(pred(input[0])) == bool))
{
for (; input.length > 0; input = input[1 .. $])
{
if (pred(input[0]))
{
break;
}
}
return input;
}
I realize it's extremely improbable that I've discovered a bug,
so what exactly could I be doing wrong? Why is the output:
2
-4
-17
8
63
6
I'm probably missing something obvious. If the input is just
[63], then nothing gets printed out.
More information about the Digitalmars-d-learn
mailing list