vendredi 10 mars 2017

How can I "map" a parameter pack

This question is similar with this, It seems in my version I need to write my own sizeof...

Suppose I have a struct Wrapper with definition

struct Wrapper{
    string s;
}

and I have a function, it accept a pack of Wrapper and printf them. Because printf take a pack of const char *, so I need to map this pack of Wrapper into a pack of const char *

template<typename ... Args>
void printf_wrapper(string format, Args&& ... args){
    printf(format.c_str(), /* #1: WHAT CAN I WRITE HERE */)
}

I heard a swallow function may help me with that, but what does it like, and how it functions?

Aucun commentaire:

Enregistrer un commentaire