Implicit Template Parameters Cannot Decipher Aliases?

Simen Kjærås simen.kjaras at gmail.com
Wed Apr 25 12:47:38 UTC 2018


On Wednesday, 25 April 2018 at 11:26:40 UTC, Vijay Nayar wrote:
> On Wednesday, 25 April 2018 at 10:25:11 UTC, Simen Kjærås wrote:
>> In the general case, the issue is unsolvable, since the 
>> relationship between template parameters and alias results may 
>> be arbitrarily complex. A simple degenerate case is this:
>
> Ok, wow, you weren't kidding. That becomes really complex 
> really fast.
>
> In that case, is the general rule of thumb that programmers 
> should not use aliases for templated types when specifying 
> template function parameters?  No implicit type inference is 
> done on the return type or on local variables, so these alias 
> seem fine enough there. Or should they just be entirely avoided 
> to avoid these kinds of problems?

Right now, yeah, that's probably the most sensible rule to follow.

If someone were to write a DIP, the simple cases (which I'd guess 
constitute >90% of realistic use cases) could be handled. It 
would have to be somewhat limited, and identifying a sensible set 
of limitations would be an important part of the work.

I'm not sure exactly what's the best way to implement this - 
maybe a lowering from

     auto foo(T)(Vector3!T arg) {}

to

     auto foo(T)(Vector!(T,3) arg) {}

That would only work if there's a single overload and no static 
ifs involved. For a solution that works with static ifs or 
overloads, something must be done about how the matching itself 
works.


On Wednesday, 25 April 2018 at 11:42:12 UTC, ag0aep6g wrote:
> https://issues.dlang.org/show_bug.cgi?id=1807

Thanks. :)

--
   Simen


More information about the Digitalmars-d-learn mailing list