| Thread overview | |||||
|---|---|---|---|---|---|
|
August 24, 2014 Error: template cannot deduce function from argument types. | ||||
|---|---|---|---|---|
| ||||
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
}
| ||||
August 24, 2014 Re: Error: template cannot deduce function from argument types. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Damian Day | 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.
| |||
August 24, 2014 Re: Error: template cannot deduce function from argument types. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Damian Day | 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 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply