mercredi 12 juillet 2017

Trying to call the first element of a parameter pack as a function and pass the rest of the pack to it as arguments

I have to write a template function with the following interface:

template <typename... Args>
void create(Args&&... args)

I need to be able to call it like this:

create([](int, float){}, 42, 5.f);

and I want the function (lambda) to be called with the 2 arguments passed after it. How can I achieve this?

I'm constrained with the interface of create() - I cannot separate the function parameter ouf of the parameter pack because of... reasons (just trust me). Perhaps it can be extracted with some tricks like in here and have the rest of the parameter pack forwarded to it...?

This should work with functions taking an arbitrary number of arguments - not just an int and a float.

Aucun commentaire:

Enregistrer un commentaire