Annoying thing about auto ref function template

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 20 14:08:40 PDT 2017


On Monday, March 20, 2017 13:20:52 Jonathan M Davis via Digitalmars-d wrote:
> So, yes, this particular restriction can be annoying, but there is a good
> reason for the restriction (though the error message _is_ pretty bad), and
> I have no idea how we would fix the problem.

After thinking about this further, it does occur to me that there's a fairly
simple workaround. e.g.

auto foo(T)(T t)
{
    return bar(t);
}

auto bar(T)(auto ref T t)
{
    ...
}

Then you can just use foo!int. Now, that requires you to pick whether it's
ref or not, but if there were a way to explicitly instantiate a function
with an auto ref parameter, you'd have to do that anyway.

- Jonathan M Davis



More information about the Digitalmars-d mailing list