digitalmars.D.learn - Querying parameter passing semantics for `auto ref const` variables
- =?UTF-8?B?Tm9yZGzDtnc=?= (8/8) Jan 15 2017 Is there a way to query at compile-time whether a call to
- =?UTF-8?B?Tm9yZGzDtnc=?= (10/11) Jan 15 2017 Further, overloading such as
- kinke (4/6) Jan 15 2017 According to
- =?UTF-8?B?Tm9yZGzDtnc=?= (18/24) Jan 15 2017 This
- =?UTF-8?B?Tm9yZGzDtnc=?= (4/16) Jan 15 2017 given that
Is there a way to query at compile-time whether a call to f(T)(auto ref const T x) passed the variable `x` from a l-value or r-value? A call to `isRef!T` inside the function `f` is always `false` for `l-value` and `r-value` passing. I need this to detect automatic delayed evaluation of sub-expressions in my GNU MP wrapper at https://github.com/nordlow/gmp-d
Jan 15 2017
On Sunday, 15 January 2017 at 14:33:25 UTC, Nordlöw wrote:Is there a way to query at compile-time whether a call toFurther, overloading such as struct S { int x, y; } static f(in S s) {} static f(const ref S s) {} f(S.init); S s; f(s); fails as declaration f is already defined
Jan 15 2017
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)`.
Jan 15 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: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!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)`.
Jan 15 2017
On Sunday, 15 January 2017 at 17:41:36 UTC, Nordlöw wrote: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:truegiven that enum isRef(alias fn) = __traits(isRef, fn); :)
Jan 15 2017