简体   繁体   中英

TMP C++ and parameter packs

template<std::size_t... Is>
void unlock_(std::index_sequence<Is...>) {

    iter(std::get<Is>(tuple)...);
}

Let's consider above example. I cannot understand iter(std::get<Is>(tuple)...); . I know that ... is expanding "operator". So it should be applied to parameter pack ( in sense arguments) or template paremeter packs. And I can imagine what is std::index_sequence<Is...> . Because Is is template parameter pack it should be just 1, 2, 3, 4, ... ( for example) . In that case out parameter is specific because it is not type. It is size_t .

But here: std::get<Is>(tuple)...); std::get<Is>(tuple) doesn't return parameter/template pack so I cannot context of usage.

PS Is it possible to see how the code looks after meta-programming? Similarly to after preprocessing?

Thanks in advance.

This is a method of expanding a std::tuple by generating a compile-time sequence of indices.

... in this context expands forms containing unexpanded parameter packs. It will generate a list like this:

Is...
0,1,2,...

doSomething(Is)...
doSomething(0), doSomething(1), doSomething(2), ...

doSomething(Is...)
doSomething(0,1,2,...)

std::get<Is>(tuple)...
std::get<0>(tuple), std::get<1>(tuple), std::get<2>(tuple), ...

iter(std::get<Is>(tuple)...)
iter(std::get<0>(tuple), std::get<1>(tuple), std::get<2>(tuple), ...)

The effect is that iter is called with arguments extracted from the tuple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM