Bug 3098 – std.algorithm.reduce example can not compile
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-06-27T02:15:00Z
Last change time
2015-06-09T01:27:57Z
Assigned to
andrei
Creator
samhu.samhu
Comments
Comment #0 by samhu.samhu — 2009-06-27T02:15:42Z
Below example is from std.algorithm.reduce:
double[] a = [ 3.0, 4, 7, 11, 3, 2, 5 ];
// Compute minimum and maximum in one pass
auto r = reduce!(min, max)(a);
// The type of r is Tuple!(double, double)
assert(r.field[0] == 2); // minimum
assert(r.field[1] == 11); // maximum
// Compute sum and sum of squares in one pass
r = reduce!("a + b", "a + b * b")(0.0, 0.0, a);
assert(r.field[0]==35);
assert(r.field[1]=233);
Can't compile.Error msg:
testFormat.d(22): Error: template std.algorithm.Reduce!("a + b","a + b * b").reduce(E,Range) does not match any function template declaration
testFormat.d(22): Error: template std.algorithm.Reduce!("a + b","a + b * b").reduce(E,Range) cannot deduce template function from argument types !()(double,double,double[])
Not sure whether this is a bug.
Comment #1 by andrei — 2009-08-27T23:44:22Z
Fixed documentation:
- r = reduce!("a + b", "a + b * b")(0.0, 0.0, a);
+ r = reduce!("a + b", "a + b * b")(tuple(0.0, 0.0), a);