Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Recursive parameter pack functions without parameters C++

I’m trying to create a recursive parameter pack function as follows:

template <class T, class ... Ts>
void myFunction()
{
    execute<T>();

    myFunction<Ts...>();
}

This doesn’t compile with the error:

error C2672: 'Test::myFunction': no matching overloaded function found.

Does anyone know how to do what I’m trying to achieve?
Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you can use C++17 or newer, you can skip the recursion and use a fold expression like

template<class... Ts>
void myFunction()
{
    (execute<Ts>(), ...);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading