IFTI in Eponymous Templates

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 29 14:38:23 PDT 2016


On 06/29/2016 08:59 PM, jmh530 wrote:
> For instance, in the bar function below, I have to
> explicitly instantiate the inner function template.
>
>
[...]
>
> template bar(T)
> {
>      T bar(U)(T x, U y)
>      {
>          return x + cast(T)y;
>      }
> }
>
> void main()
> {
>      int a = 1;
>      long b = 2;
>      auto x = foo(a, a);
>      //auto y = bar(a, b); //error
>      auto y = bar!(long)(a, b);
> }

You're explicitly instantiating the outer bar there, not the inner one. 
The inner one is instantiated via IFTI. You're explicitly setting T = 
long. U = long is set implicitly from the type of b.

IFTI is defined to work on function templates. The outer bar is not a 
function template. It's a template for a function template. So no IFTI.

Maybe IFTI could work on templates for (templates for ...) function 
templates. Someone would have to consider all the details, write up an 
improvement proposal, get it approved, and implement it.


More information about the Digitalmars-d-learn mailing list