Pack (since C++11)

A pack is a C++ entity that defines one of the following:

# Notes

This section is incompleteReason: a few words about partial specializations and other ways to access individual elements? Mention recursion vs logarithmic vs shortcuts such as fold expressions Feature-test macro Value Std Feature __cpp_variadic_templates 200704L (C++11) Variadic templates __cpp_pack_indexing 202311L (C++26) Pack indexing

# Example

#include <iostream>
 
void tprintf(const char* format) // base function
{
    std::cout << format;
}
 
template<typename T, typename... Targs>
void tprintf(const char* format, T value, Targs... Fargs) // recursive variadic function
{
    for (; *format != '\0'; format++)
    {
        if (*format == '%')
        {
            std::cout << value;
            tprintf(format + 1, Fargs...); // recursive call
            return;
        }
        std::cout << *format;
    }
}
 
int main()
{
    tprintf("% world% %\n", "Hello", '!', 123);
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
CWG 1533C++11a pack expansion could occur in a member initializer for a membernot allowed
CWG 2717C++11instantiations of alignment specifiers were comma-separatedthey are space-separated

# See also