[Issue 16486] Compiler see template alias like a separate type in template function definition

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Sep 13 13:55:12 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16486

--- Comment #4 from Sky Thirteenth <sky.13th.95 at gmail.com> ---
(In reply to Steven Schveighoffer from comment #3)
> The issue is that the compiler doesn't replace the alias until AFTER
> instantiation.
> 
> It should be able to see that:
> 
> testFunctionC(T)(TestAliasB!T arg)
> 
> is the same as 
> 
> testFunctionC(T)(TestType!(T, 3) arg)
> 
> and reduce basically to the same thing as testFunctionA
> 
> Still definitely an enhancement, as there is no definition of how the
> compiler will work backwards through template instantiations.
> 
> It may be a duplicate, I distinctly remember wishing for this kind of thing
> back when D2 was in infancy.

Actually, in my opinion, as it acts now, looks wrong, because this feature is
not used at full power. 

We can use templates and template alias, while declare variables, but can't do
the same thing while describe arguments for other templates(no matter is it
type or function). Don't you feel wrong about it?

The meaning of this features, is to simplify things. But in this case we need
to write something like this:
```
auto foo( That )( What.TheHell!(is(That : Thing) && How!(IShould!(Use!That)))
arg )
{
    //...
}
```
Rather then just write down this:
```
auto foo( That )( CatInABag!That arg )
{
    //...
}
```

Of course, now I'm exaggerating things, but still it can be pretty useful
feature.

--


More information about the Digitalmars-d-bugs mailing list