We will look at passing multiple template parameters in our template parameter list.
Have a look at the code:
#include<iostream>
template<typename t1, typename t2>
void foo(t1 input1, t2 input2)
{
std::cout<<input1<<std::endl;
std::cout<<input2<<std::endl;
}
int main()
{
foo<int, float>(3, 4.5f);
return 0;
}
We shall copy this code in https://cppinsights.io/ and have a look at what kind of code compiler generates on our behalf if we use templates.
Following are insights from above webpage:
#include<iostream>
template<typename t1, typename t2>
void foo(t1 input1, t2 input2)
{
(std::cout << input1) << std::endl;
(std::cout << input2) << std::endl;
}
/* First instantiated from: insights.cpp:12 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
void foo<int, float>(int input1, float input2)
{
std::cout.operator<<(input1).operator<<(std::endl);
std::cout.operator<<(input2).operator<<(std::endl);
}
#endif
int main()
{
foo<int, float>(3, 4.5F);
return 0;
}