Really fix Issue 16478 - Don't allow to!T() in constraint#4922
Really fix Issue 16478 - Don't allow to!T() in constraint#4922schveiguy merged 1 commit intodlang:masterfrom
Conversation
Use specialization to prefer to!S when S is a static array.
|
|
I don't think this will work, because constraints aren't considered specialization. int[1] arr;
to!string(arr); // ambiguity errorWhat you need is something like: if(Args.length > 1 || (Args.length == 1 && !isStaticArray!(Args[0])))Alternatively, auto to(Val, Args...)(Val v, Args args) if(!isStaticArray!Val)
{
return toImpl!T(v, args);
} |
|
Hm... it does work, but I don't understand why. I'm sure I've had to deal with this not being a specialization. I also can't find the rule that says why this is a specialization. But it seems to compile fine. |
I think it works like this. When one argument is supplied to |
|
Is that rule outlined in the spec somewhere? |
|
Not sure. Although the constraints page seems to support this - right at the end (under Overloading based on Constraints) it shows: |
|
But that is specialization as I understand it -- a colon with a specification is a specialization. See here: https://dlang.org/spec/template.html#parameters_specialization I can't find the rule that says that individual type parameters are considered before variadic ones. |
|
Regarding the PR, I think it's fine as long as this rule is correct and understood. I just don't know if the current behavior is what is intended. |
|
Found the answer (@aG0aep6G on forums) https://dlang.org/spec/template.html#variadic_template_specialization |
|
@CyberShadow why the failure? |
|
Hrm, the heuristic for the dlang.org makefile's iffy Pushed a fix and queued PRs for retesting, hopefully should be fixed now. May need a commit to master to seed the cache. |
|
Auto-merge toggled on |
|
@CyberShadow thanks. |
to!Swhen S is a static array.(For background, see #4898 (comment))
Ping @schveiguy.