chain(const(array of class)) fails
SimonN via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jan 31 13:22:06 PST 2016
Hi,
we start with the following code snippet, which works.
import std.algorithm;
import std.range;
import std.stdio;
class A { int val; }
class B : A { this() { val = 3; } }
class C : A { this() { val = 4; } }
B[] b = [new B(), new B()];
C[] c = [new C(), new C()];
void main()
{
chain(b, c).each!(a => a.val.writeln);
}
The output, as expected, is:
3
3
4
4
Now I change the declarations of B[] b and C[] c to the
following, keeping
everything else in the code snippet the same:
const(B[]) b = [new B(), new B()];
const(C[]) c = [new C(), new C()];
This makes dmd 2.070 choke: ( http://dpaste.dzfl.pl/eee69fd03dd9 )
Error: template std.range.chain cannot deduce function from
argument
types !()(const(B[]), const(C[])),
candidates are:
/opt/compilers/dmd2/include/std/range/package.d(804):
std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 &&
allSatisfy!(iseputRange, staticMap!(Unqual, Ranges)) &&
!is(CommonType!(
staticMap!(ElementType, staticMap!(Unqual, Ranges))) == void))
What's stumping me -- constness doesn't make dmd choke on ranges
of
numbers. If I replace the classes B and C with simple 'int' and
'double',
this compiles again:
const(int[]) b = [1, 2];
const(double[]) c = [3.3, 4.4];
void main() { chain(b, c).each!(a => a.writeln); }
Why does it fail for const(array of class)?
Is any template magic about Unqual or staticMap relevant here?
-- Simon
More information about the Digitalmars-d-learn
mailing list