mardi 29 septembre 2015

C++11 accessing each variadic parameter

Is it possible to split variadic parameter into list of items and access them? below you can see example of what I want to achieve - first piece, is standard, simple example of using variadic parameters

template<typename ... Types>
float sum(float first, Types ... rest)
{
    return first + sum(rest...);
}

below, you can see what I'd like to do

template<typename ... Types>
float sum(float first, Types ... rest)
{
    std::cout<<first<<std::endl;
    for(auto item : rest)
             cout<<rest<<std::endl;
}

I know I can print and do things recursively, but is there way to access params w/o recursion?

Aucun commentaire:

Enregistrer un commentaire