On 04/26/2013 01:58 AM, Zach the Mystic wrote:
...

I also thought of the trick mentioned by Timon, where the compiler
infers the need or lack thereof for the value/reference type in
templates based on what things are done within the function body. But as
you said, figuring out the rules for making the compiler smart enough to
choose the right one seems like a hard task.

I think it is easy.

If it forwards to another
'auto ref' template parameter, it needs to descend into that template,
determine *its* type of parameter, and then assign the type of its own
parameter accordingly.
...

No, when forwarding to another template, non-lazy parameters will always have an address, ref or not ref. lazy auto ref parameters should be restricted to the template case.

The cases where it makes a difference are auto ref returns, __traits(isRef, ...), and lazy auto ref parameters. (If there are more, they will be detected by grepping the compiler source for occurrences of the 'ref' "storage class" representation, presumably an enum value.)

The compiler does not have to be particularly smart. IMO this is the way to generalize auto ref to non-template functions.

Reply via email to