具有递归模板参数包函数是否为每次迭代创建特定函数?

Does having a recursive template parameter pack function create a specific function for each iteration?

假设我使用参数包重新创建 printf

void printf(const char* string)
{
    std::cout << string;
}

template <typename T, typename... Params>
void printf(const char* string, T first, Params... p)
{
    while (*string != '[=10=]')
    {
        if (*string == '%' && *(string + 1) != '%')
        {
                std::cout << first;
                string += 2;
                printf(string, p...);
                return;
        }

        std::cout << *string++;
    }
}

我使用以下参数调用该函数:

printf("%d is the answer to life, the universe, and everything. Pi = %f", 42, 3.14);

编译器会创建 2 个具有不同签名的不同函数吗?

printf(const char*, int, Params...);printf(const char*, double, Params...);

如果是这样,带有 10 个参数的函数调用将导致创建 10 个不同的函数。编译器是否对此进行了优化?

我希望此调用产生以下两个模板实例:

printf(const char*, int, double);

printf(const char*, double);

并且,是的,如果您将十一个参数传递给此 printf(),编译器将生成模板函数的十个实例。这就是为什么模板在创建代码膨胀方面享有盛誉,当之无愧。

如果有,说

printf("Foo %d\n", 10);

printf("Bar %d\n", 20);

我希望两个模板实例相同,并在 link 时合并在一起。但这是一个小小的安慰。