Check out example codes for "template in c++". It will help you in understanding the concepts better.

Code Example 1

template <class T>
void swap(T & lhs, T & rhs)
{
 T tmp = lhs;
 lhs = rhs;
 rhs = tmp;
}

Code Example 2

namespace std {
  template<typename t> struct hash<MyClass<t>>
  {
  	size_t operator() (const MyClass<t>& c) const;
  }
}

// You can also do things like

template<template<typename t> class type> func_name<type<t>>();

Code Example 3

template <class T>
void swap(T & lhs, T & rhs)
{
 T tmp = lhs;
 lhs = rhs;
 rhs = tmp;
}

void main()
{
  int a = 6;
  int b = 42;
  swap<int>(a, b);
  printf("a=%d, b=%d\n", a, b);
  
  // Implicit template parameter deduction
  double f = 5.5;
  double g = 42.0;
  swap(f, g);
  printf("f=%f, g=%f\n", f, g);
}

/*
Output:
a=42, b=6
f=42.0, g=5.5
*/

Code Example 4

template class  Graph<string>;

Code Example 5

template <typename T>
void Swap(T &n1, T &n2)
{
	T temp;
	temp = n1;
	n1 = n2;
	n2 = temp;
}

Code Example 6

// template function
template <class T>
T Large(T n1, T n2)
{
	return (n1 > n2) ? n1 : n2;
}

Learn ReactJs, React Native from akashmittal.com