digitalmars.D.learn - Error: template cannot deduce function from argument types.
- Damian Day (30/30) Aug 23 2014 Hi, I've been trying to reduce a bug in the containers (8824).
Hi, I've been trying to reduce a bug in the containers (8824). From the example below it seems the dup method is passing the constructor an array of dchars and the template is failing. Is this a compiler bug, or ? import std.range, std.traits; struct Array2(T) { private T[] _payload; size_t insertAt(R)(size_t index, R rng) if (isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) { return 0; } this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) { insertAt(0, values); } property Array2 dup() { return Array2(_payload); } } unittest { Array2!int a; //passes Array2!char a; //fails }
Aug 23 2014
On Sunday, 24 August 2014 at 02:53:41 UTC, Damian Day wrote:Hi, I've been trying to reduce a bug in the containers (8824). From the example below it seems the dup method is passing the constructor an array of dchars and the template is failing. Is this a compiler bug, or ? import std.range, std.traits; struct Array2(T) { private T[] _payload; size_t insertAt(R)(size_t index, R rng) if (isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) { return 0; } this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) { insertAt(0, values); } property Array2 dup() { return Array2(_payload); } } unittest { Array2!int a; //passes Array2!char a; //fails }Not a compiler bug. char[] (and wchar[]) as ranges auto-decode to dchars. I.e. ElementType!(char[]) is dchar. And dchar isn't implicitly convertible to char. So the instantiation of insertAt fails.
Aug 24 2014
On Sunday, 24 August 2014 at 02:53:41 UTC, Damian Day wrote:isImplicitlyConvertible!(ElementType!R, T))Try [ElementEncodingType][0]. [0]: http://dlang.org/phobos/std_range.html#ElementEncodingType
Aug 24 2014