Templates are mechanisms to support the so-called generic programming. Generic broadly means we can define a function or a class without worrying about what types it accepts.
We define those functions and classes using some generic type. And when we instantiate them, we use a concrete type. So, we can use templates when we want to define a class or a function that can accept almost any type.