Is it possible to override a variadic template by changing the number of fixed parameters before the function parameter pack? For example:
#include <iostream>
template <typename ...Args>
void foo(std::string, std::string, std::string, Args...)
{
std::cout << "THREE STRINGS\n";
}
template <typename ...Args>
void foo(std::string, std::string, Args...)
{
std::cout << "TWO STRINGS\n";
}
int main() {
foo("key", "msg", "data", 1, 2);
}
Running this causes the second foo
to be called, but I want the first to be called. Is there a better way to overload this function?
Aucun commentaire:
Enregistrer un commentaire