mardi 25 octobre 2022

how can I send c++ template to a wraped element in parameter pack?

now I have a special requirement.

  1. the quantity of parameters handled by the function is not constant, so I have to use parameter pack in C++

  2. the parameter is std::pair<std:string, template>, but different argument has different type of template, so the args would be like std::pair<std::string, int>, std::pair<std::string, bool>, .... Actually, I need to evaluate the type of each argument and perform different branch by the type. And in C++ only template can transfer typename as argument.

  3. an iterable class would be one of input arguments, so I hope to use the size of this argument instead of the quantity of variable parameters.

so the function would be similar like this:

template<typename... T>
template<typename pair_t> std::pair<std::string, T>
std::vector<ret_class> my_fun(const iterable_class &in_obj, pair_t &...type)
{
    std::vector<ret_class> ret;
    int i=0;
    for(auto arg:type) // ergodic all variable parameters, but I hope to use the iterable_class.size() as the index limit.
    {
        ret.push(handle_fun<arg.second>(iterable_class[i])); // arg.second would change the behavior of handle_fun
        ++i;
    }
    return ret;
}

but it can't pass compile.

Can anybody help me to clarify this issue?

Aucun commentaire:

Enregistrer un commentaire