How to check that function gets ref parameter?

Andrey Zherikov andrey.zherikov at gmail.com
Sun Dec 13 16:41:06 UTC 2020


I'm trying to check that function has 'ref' parameter. The only 
way I found so far is to use std.traits.Parameters.

Here is the code I have:
     void f(int) {}
     void g(ref int) {}
     void main()
     {
         writeln(Parameters!f[0].stringof);
         writeln(__traits(isRef, Parameters!f[0]));
         writeln(Parameters!g.stringof);
         writeln(Parameters!g[0].stringof);
         writeln(__traits(isRef, Parameters!g[0]));
     }

The output is:
     int
     false
     (ref int)
     int
     false

"Parameters!g[0]" strips off 'ref' qualifier as you can see. How 
can I make it work?


More information about the Digitalmars-d-learn mailing list