Accessing template parameter pack

Suppose I have this function:


template<typename...T> void doSomething() {

}

and I call it :

doSomething<ClassA, ClassB, ClassC>();

How can I access these classes in the "doSomething()" function?
The pack expansion T... is a comma-separated list of each type in the parameter pack T, or nothing if the pack is empty. That is, use the ellipsis.

To index parameter packs arbitrarily (i.e., to access the Ith element of the parameter pack), say std::tuple_element_t<I, std::tuple<Ts...>>.

What is doSomething()?
Last edited on
"doSomething()" is just a method in which I want to access the Ts that are passed in.
"doSomething()" is just a method in which I want to access the Ts that are passed in.

I'm somewhat less willing to summarize the behavior of the entire language feature in general than to answer specific questions.

You can find a complete explanation of pack expansion on cppreference:
https://en.cppreference.com/w/cpp/language/parameter_pack#Pack_expansion

Pack expansion is intuitive after a little practice.
Topic archived. No new replies allowed.