Summary
In this chapter, we looked at a powerful tool for code reuse: C++ templates. The underlying idea is very simple and attractive: If the algorithms should be the same for different types, you should write it only once and later indicate for what actual type you want this algorithm to be used.
This is the ideal, but the practical use of this idea faces a number of difficulties. The syntax of C++ templates is complex. The use of specializations complicates matters even more. Sometimes figuring out which specialization will be called in each case becomes a chore. Sometimes, what works on one machine under one compiler will not work on another machine under a different compiler.
In addition, the use of templates entails space and performance ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access