How to preserve function parameters scopeness

Adam D. Ruppe destructionator at gmail.com
Thu Jun 6 11:22:39 UTC 2019


On Thursday, 6 June 2019 at 09:45:08 UTC, Ivan Butygin wrote:
> I want to extract function parameters types from declaration, 
> remove some of them and construct new function pointer type 
> from remaining types.

Do you know where they are likely to be or how many will be 
filtered?

Slicing the Params thing directly, without using Filter, can do 
it:

void main()
{
     alias P = Parameters!foo[1 .. $];
     alias P2 = Parameters!foo[0 .. 1];
     pragma(msg, P);
     alias F1 = ReturnType!foo function(P, P2);
     pragma(msg, F1);
}


So if you can make a helper function to find the indexes for you, 
you can call that and do these slices, then put them back 
together when defining the new function.

But doing this when you don't know how many you are slicing is 
tricky. I suppose it could be written recursively; do one 
iteration of this technique for each param to be removed, then if 
there's another to go, run it again on the generated function 
until you get to what you want. (this is kinda how Filter works 
inside anyway, just I don't think the scopeness there is 
preserved through one of its non-function middle steps. Keeping 
the params inside a function for each middle step will sidestep 
this.... I think).

Just I haven't actually tried that and imo it would be much 
prettier if you can just slice out one block lol.


More information about the Digitalmars-d mailing list