digitalmars.D.learn - BitArray - incomplete implementation?
- Laeeth Isharc (61/61) Jan 23 2015 Hi.
- Laeeth Isharc (34/34) Jan 23 2015 To avoid confusion, the below is the code that fits the error
- anony (8/70) Jan 23 2015 Yes, that error is caused by a bug of
- Laeeth Isharc (8/15) Jan 23 2015 Thanks for this. If I recompile phobos with the pull request
Hi. Should the following code work? 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.
Jan 23 2015
To avoid confusion, the below is the code that fits the error message: 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[] 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; }
Jan 23 2015
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.
Jan 23 2015
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.Thanks for this. If I recompile phobos with the pull request (having edited out the init property entirely) then the code mostly works. However, I still can't use join, joiner, or chain on two BitArrays. Eg auto x=joiner(a,b).array; I can chain two arrays of BitArrays, but not join or joiner them. If this is what ought to happen, why?
Jan 23 2015