Improvement to std.numeric examples in documentation
Paul Backus
snarwin at gmail.com
Sat Dec 28 03:55:18 UTC 2019
On Saturday, 28 December 2019 at 03:28:33 UTC, BoraxMan wrote:
> When one tries to do something like "normalize(a,10)", dmd
> reports this error.
>
>> Error: template instance normalize!(no, 100) does not match
>> template declaration normalize(R)(R range, ElementType!R sum =
>> 1)
>
> One must actually specify the template parameter, thus
>
>> assert(normalise!(typeof(a)(a,100));
This looks like an instance of issue 1807 [1]. The fix is to move
the alias template (in this case, ElementType) out of the
argument list and into a template constraint:
bool normalize(R, S)(R range, S sum = 1)
if (isForwardRange!R && is(S == ElementType!R))
You can work around this particular issue in your own code with
the following wrapper function:
auto normalize(R, S)(R range, S sum)
if (is(S == ElementType!R ))
{
import std.numeric: normalize;
return normalize!R(range, sum);
}
[1] https://issues.dlang.org/show_bug.cgi?id=1807
More information about the Digitalmars-d
mailing list