On Saturday, 24 January 2015 at 00:13:34 UTC, Laeeth Isharc wrote:
Hi.
Should the following code work?
Yes, that error is caused by a bug of
BitArray(https://issues.dlang.org/show_bug.cgi?id=13806). Having
"init" function broke template constraints of "chain"(and must
break dozen of other templates).
pragma(msg, ElementType!(BitArray[])) // prints 'pure nothrow
void(bool[] ba)' - ElementType uses "init" property to determine
types.
import std.bitmanip;
import std.stdio;
import std.array;
import std.range:chain;
void test()
{
int[] a=[1,2,3,4,5];
int[] b=[5,4,3,2,1];
int[] c = chain(a,b).array; // chain two arrays of int
writefln("%s",c);
}
void test2()
{
BitArray a;
a.init([1,0,1,0]);
BitArray b;
b.init([0,1,0,1]);
BitArray[] d;
d~=a;
d~=b;
BitArray[] c=chain([a],[b]).array; // cannot chain two
bitarrays
BitArray[] e=chain(d,d).array; // cannot chain two arrays of
bitarrays
writefln("%s",c);
}
int main(string[] args)
{
test();
test2();
return 1;
}
bitmanip.d(23): Error: template std.range.chain cannot deduce
function from argument types !()(BitArray, BitArray),
candidates are:
/usr/include/dmd/phobos/std/range.d(2493):
std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 &&
allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) &&
!is(CommonType!(staticMap!(ElementType, staticMap!(Unqual,
Ranges))) == void))
bitmanip.d(24): Error: template std.range.chain cannot deduce
function from argument types !()(BitArray[], BitArray[]),
candidates are:
/usr/include/dmd/phobos/std/range.d(2493):
std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 &&
allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) &&
!is(CommonType!(staticMap!(ElementType, staticMap!(Unqual,
Ranges))) == void))
bitmanip.d(24): Error: declaration bitmanip.test2.c is already
defined
bitmanip.d(25): Error: template std.range.chain cannot deduce
function from argument types !()(BitArray[], BitArray[]),
candidates are:
/usr/include/dmd/phobos/std/range.d(2493):
std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 &&
allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) &&
!is(CommonType!(staticMap!(ElementType, staticMap!(Unqual,
Ranges))) == void))
I cannot seem to concatenate - directly, or using chain - two
bitarrays, or two arrays of bitarrays.