Templates have been helping programmers to change the way they are able to code since the ealy 1990s. Since that time they have advanced rapidly, and in this tutorial we will take a close look at them and learn to use them to effectively decrease our tasks.
Templates, as a programming concept, redefined the way we are able to code nowadays. Templates appeared back in the early 1990s and soon after, they started to advance rapidly. For this reason, the legendary author Scott Meyers decided to skip over templates; thus, they aren’t covered in the book, “Effective C++.”
Later in 1995, despite the fact that he wrote a chapter on templates, the author decided not to include it in the published edition of the book, More Effective C++, since he thought that this area was still experiencing growth and evolution.
He was quite right. This so-called evolution lead to the rise of one of the most crucial items for a C++ programmer in the 21st century: the template libraries. Here we can include one of the best known libraries, the STL (Standard Template Library), which is also included in Visual Studio's STD.
But there exist many others that are just as important; for example, the boost library or the Loki library of Andrei Alexandrescu. All of these rely on templates and you must be very familiar with them if you plan to become a good, efficient, and fast C++ programmer.
I want to congratulate you for investing your time in something that I can promise you won't regret. This article will teach you all that you need to know about templates. It can be considered a prequel to the STL library introduction article.
We're going to begin with function templates, followed by class templates, and conclude with template specialization or non-type parameters for templates. All of this will be covered, so prepare yourself for more knowledge and let's begin!