Std :: function argument list and typedefs

I have a typedef something like this:

typedef std::function<int arg1, float arg2> MyFunction;

And somewhere in my code it is used like this:

MyFunction func = [](int arg1, float arg2){ /* do someting */ };

The fact is that every time I change the number of arguments to a function (for example, I add a third argument, arg arg3), I have to update it errywhere throughout my code where I used MyFunction (even if these arguments are not used at all.

And I'm too lazy to do this. Is there a way to get the argument list from std :: function from this type? (I mean), so creating a function might look like this:

MyFunction func = [](MyFunction::args){ /* do someting */ };
+4
source share
1 answer

Since C ++ 14, you can use a polymorphic lambda variable:

MyFunction func = [](int arg1, float arg2, auto&&... unused){ /* ... */ };

std::function<Sig> int, float.

0

All Articles