Summary
Templates are a complex subject, yet through this chapter, we have discovered that this complexity can create amazingly reusable code. The Queue
class created here can hold a queue of any elements without any changes to its internals, which is a huge benefit when writing code that needs to be reused in many areas. While not as fully functional, robust, or performant as STL queues, it still gives insight into how a rudimentary version of an STL container can be recreated without too much work, if the STL is unavailable to us or, for some reason, does not suit our needs. We looked at template functions and classes and discovered how powerful they can be when used correctly, along with areas that we might want to be mindful of.
In the next chapter, we are going to cover the STL itself and look closely at the containers it provides. The STL will become invaluable to your future programming efforts in C++. It does a lot of the hard work for us, meaning we will not have to keep...