Exploring Template Programming in C++

Example of template specialization

#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <numeric> // for std::accumulate
#include <algorithm>
using namespace std;

template<class T1=float, class T2=float>
void Swap(T1 a, T2 b)
{
    T1 temp = a;
    a = b;
    b = temp;
    cout<<a<<","<<b<<'\n';
}
template<> //template specilization
void Swap(const char* a, const char* b)
{
    cout<<b<<","<<a<<'\n';
}

int main()
{

    Swap(5,6);
    Swap(5.6,6.4);
    string aa="x";
    string bb="y";
    Swap(aa,bb);
    Swap("a","b"); //Need template specilation for const char*
    return 0;
}