Annoying thing about auto ref function template

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 20 18:10:38 PDT 2017


On Monday, March 20, 2017 22:14:37 Yuxuan Shui via Digitalmars-d wrote:
> On Monday, 20 March 2017 at 21:53:47 UTC, Jonathan M Davis wrote:
> > On Monday, March 20, 2017 21:37:26 Yuxuan Shui via
> >
> > Digitalmars-d wrote:
> >> [...]
> >
> > auto ref for non-templates would not be quite the same thing,
> > and regardless, it wouldn't help any with explictly
> > instantiating a template that had an auto ref parameter. So, it
> > really wouldn't solve the problem at all. It would just make it
> > so that if you didn't want a templated function, you could use
> > auto ref.
> >
> > [...]
>
> Makes sense...
>
> OK, attempt 2: how about support implicit partial application for
> templates?

Well, you can do something like

template foo(T)
{
    auto foo()(auto ref T t)
    {
        return t;
    }
}

void main()
{
    alias f = foo!int;
    auto a = f(42);
}

and then foo!int, but you're not going to get a function pointer out of it,
since for that, you need to instantiate the inner function template. It does
give partial instantiation though.

- Jonathan M Davis



More information about the Digitalmars-d mailing list