get parameters of a function

Stanislav Blinov via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 28 22:58:35 PDT 2017


On Friday, 28 April 2017 at 20:43:50 UTC, Alex wrote:
> Hi all,
> I have a question about the Parameters trait from
> https://dlang.org/phobos/std_traits.html#Parameters
>
> The following code does not compile. Why?
> Is it mainly assumed to use it with functions without overloads?

Rather, it is to be used on a concrete overload.
If you want to check if two structs are callable with the same 
parameters, you'll need to iterate opCall overloads for both and 
look for a match, e.g. like this:

void main()
{
     foreach(o1; __traits(getOverloads, S1, "opCall"))
     {
         alias P1 = Parameters!o1;
         foreach(o2; __traits(getOverloads, S2, "opCall"))
         {
             alias P2 = Parameters!o2;
             static if (is(P1 == P2))
             {
                 pragma(msg, "Matching params: "~P1.stringof);
             }
         }
     }
}


More information about the Digitalmars-d-learn mailing list