mardi 24 janvier 2017

How can I map a C++ parameter pack into a sequence of std::pair objects?

I have a variadic template function foo():

template <typename... Args>
void foo(Args &&... args);

This function is intended to be invoked with all arguments of size_t. I can enforce that using some metaprogramming. I need to take the resulting list of arguments two at a time and put them into a container of std::pair<size_t>. Conceptually, something like:

std::vector<std::pair<size_t> > = { 
    std::make_pair(args[0], args[1]), 
    std::make_pair(args[2], args[3]), ...
};

Is there a straightforward way to do this? I know that by pack expansion, I could put the arguments into a flat container, but is there a way to group them two by two into std::pair objects at the same time?

Aucun commentaire:

Enregistrer un commentaire