reduce a BitArray[]
Alex Parrill via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Dec 29 09:42:26 PST 2015
On Tuesday, 29 December 2015 at 09:26:31 UTC, Alex wrote:
> The problem is, that the last line with the reduce does not
> compile. Why?
If you get an error, it is imperative that you tell us what it is.
For the record, this code:
import std.bitmanip;
import std.stdio;
import std.algorithm;
void main() {
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));
}
Gives me the error:
/opt/compilers/dmd2/include/std/algorithm/iteration.d(2570):
Error: variable f868.main.F!(__lambda1).e cannot be declared to
be a function
/opt/compilers/dmd2/include/std/meta.d(546): Error: template
instance f868.main.F!(__lambda1) error instantiating
/opt/compilers/dmd2/include/std/algorithm/iteration.d(2477):
instantiated from here: staticMap!(ReduceSeedType, __lambda1)
/d486/f868.d(16): instantiated from here:
reduce!(BitArray[])
/d486/f868.d(16): Error: template std.algorithm.iteration.reduce
cannot deduce function from argument types !((a, b) => a &
b)(BitArray[]), candidates are:
/opt/compilers/dmd2/include/std/algorithm/iteration.d(2451):
std.algorithm.iteration.reduce(fun...) if (fun.length >= 1)
On 2.069.1 (dpaste: http://dpaste.dzfl.pl/8d7652e7ebeb). I don't
have time ATM to diagnose it further. It definitely shouldn't be
that cryptic of an error message.
More information about the Digitalmars-d-learn
mailing list