D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3098 - std.algorithm.reduce example can not compile
Summary: std.algorithm.reduce example can not compile
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-27 02:15 UTC by Sam Hu
Modified: 2015-06-09 01:27 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Sam Hu 2009-06-27 02:15:42 UTC
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 Andrei Alexandrescu 2009-08-27 23:44:22 UTC
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);