Querying parameter passing semantics for `auto ref const` variables

Nordlöw via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 15 09:41:36 PST 2017


On Sunday, 15 January 2017 at 17:00:41 UTC, kinke wrote:
> On Sunday, 15 January 2017 at 14:33:25 UTC, Nordlöw wrote:
>> A call to `isRef!T` inside the function `f` is always `false` 
>> for `l-value` and `r-value` passing.
>
> According to 
> https://dlang.org/spec/template.html#auto-ref-parameters, it 
> should be `__traits(isRef, x)`.

This

     struct S { int x, y; }
     void f()(auto ref const S s)
     {
         pragma(msg, "type:", typeof(s), " isRef:", isRef!s);
     }
     f(S.init);
     S s;
     f(s);

prints

     type:const(S) isRef:false
     type:const(S) isRef:true

I made the mistake of incorrectly using

     isRef!S

when I should have used

     isRef!s

Thanks!


More information about the Digitalmars-d-learn mailing list