mardi 28 avril 2015

Variadic template function composition

Hoping the stackoverflow community can help me with this problem. I would like to have something like the following compile

template <typename A>  
void VARIADIC_TEMPLATE_FUNCTION(A* tptr)
{   
    //Do nothing
}   

template <typename A, typename B, typename... C>
void VARIADIC_TEMPLATE_FUNCTION(A* tptr)
{   
    // Do stuff here with typename B and tptr (not included)
    VARIADIC_TEMPLATE_FUNCTION<A,C...>(tptr);
}   

clearly this doesn't work, the signatures of the two functions conflict.

I have been attempting to fix this by passing some variadic arguments as well, but nothing seems to work. I'm not against passing "fake" variables - but prefer not to.

The caller would do something like (for example):

ClassP* ptr;
VARIADIC_TEMPLATE_FUNCTION<ClassP, ClassA, ClassB, ClassC, ClassD>(ptr);

Aucun commentaire:

Enregistrer un commentaire