The pros and cons of templates
Before you start using templates, it's important to understand the benefits of using them as well as the disadvantages they may incur.
Let's start by pointing out the advantages:
- Templates help us avoid writing repetitive code.
- Templates foster the creation of generic libraries providing algorithms and types, such as the standard C++ library (sometimes incorrectly referred to as the STL), which can be used in many applications, regardless of their type.
- The use of templates can result in less and better code. For instance, using algorithms from the standard library can help write less code that is likely easier to understand and maintain and also probably more robust because of the effort put into the development and testing of these algorithms.
When it comes to disadvantages, the following are worth mentioning:
- The syntax is considered complex and cumbersome, although with a little practice this should not...