reduce a BitArray[]

Alex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 29 01:26:31 PST 2015


Hi there,
a silly question from me for the turn of the year... I apparently 
missing the forest through the trees.
The first part of the code works as expected:

[code]
     int[] arr8 = [1,2,3,4,5];

     int sum = 0;
     foreach(int summand; arr8)
     {
     	sum += summand;
     }
     writeln("sum1: ", sum);

     writeln("sum2: ", reduce!((a,b) => a + b)(arr8));
[/code]

The second one does not:

[code]
     import std.bitmanip;

     BitArray[] arr7 = [BitArray([0, 1, 0, 1, 0, 1]), BitArray([0, 
1, 0, 0, 0, 0]), BitArray([0, 1, 0, 1, 0, 0]), BitArray([0, 1, 0, 
1, 0, 0])];

     BitArray common = BitArray([1,1,1,1,1,1]);
     foreach(BitArray ba; arr7)
     {
         common &=  ba;
     }
     writeln("common2: ", common);

     //writeln("common1: ", reduce!((a,b) => a & b)(arr7));
[/code]

The problem is, that the last line with the reduce does not 
compile. Why?


More information about the Digitalmars-d-learn mailing list