www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17040] New: std.algorithm.iteration.reduce example does not

https://issues.dlang.org/show_bug.cgi?id=17040

          Issue ID: 17040
           Summary: std.algorithm.iteration.reduce example does not
                    compile
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: donte5379 comcast.net

davidcha% dmd --version
DMD64 D Compiler v2.071.2

This example is from http://dlang.org/phobos/std_algorithm_iteration.html

import std.algorithm.comparison : max, min;
import std.math : approxEqual;
import std.range;

int[] arr = [ 1, 2, 3, 4, 5 ];
// Sum all elements
auto sum = reduce!((a,b) => a + b)(0, arr);
assert(sum == 15);


The error message is

./reduce_bug.d(17): Error: template instance reduce!((a, b) => a + b) template
'reduce' is not defined
Failed: ["dmd", "-v", "-o-", "./reduce_bug.d", "-I."]

It will compile and run if the import statement is changed to either of the
following: 
import std.algorithm;
import std.algorithm.iteration;

--
Dec 28 2016