You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider this hypothetical example:
///////////////// test.d /////////////////
T[] copyArray(T=I, I)(I[] input)
{
auto result = new T[input.length];
foreach (n, ref i; input)
result[n] = i;
return result;
}
void main()
{
// copy as is
int[] r1 = copyArray([1, 2, 3]);
// copy to another type
long[] r2 = copyArray!long([1, 2, 3]);
}
//////////////////////////////////////////
There is currently no way to get this code to work, without either declaring an overload for copyArray, or replacing T=I with T=SomeDummyType and later checking to see if something was explicitly passed or not.
The text was updated successfully, but these errors were encountered:
It's not an "hypothetical example" - it makes real code ugly! :/
Let me add an example from a recent PR in phobos
https://github.com/dlang/phobos/pull/4263
If we could support the forwarding of argument types, we would only have _one_, very nice & readable function header:
```T[] makeArray(T = Unqual!(ElementType!R), Allocator, R)```
Of course we can add another function overload, but it unnecessary bloats!
```Unqual!(ElementType!R)[] makeArray(Allocator, R)(auto ref Allocator alloc, R range){ import std.range.primitives; alias T = Unqual!(ElementType!R); return makeArray!(T, Allocator, R)(alloc, range);}T[] makeArray(T, Allocator, R)(auto ref Allocator alloc, R range) ```
Vladimir Panteleev (@CyberShadow) reported this on 2014-03-21T11:17:57Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=12433
CC List
Description
The text was updated successfully, but these errors were encountered: