12.1. Templates or Generics?

If you're a C++ programmer, you may be asking yourself why you should even concern yourself with generics. After all, you already have full access to the power of templates and you'll probably view generics as narrowing the scope of your generic landscape. However, there are still plenty of good reasons for a C++ programmer to take an interest in generics.

Even though templates offer some added power that's not achievable in generics (see Chapter 3, "Generics ≠ Templates"), this power also comes with some baggage. And, given some of the efficiencies and strengths of generics, it seems to make sense for C++ programmers to at least take a step back and reconsider how generics might influence their overall approach to using or consuming generic types.

The main point here isn't to say generics should be used in lieu of templates. Instead, the point is only that generics bring a new set of parameters to the equation that may—or may not—change how and when you choose to use templates and generics. Clearly, if you're in a more controlled environment, you're likely to stick with a pure, template-based approach. However, if you have more specific size and interoperability requirements, you may want to consider how the use of generics might bring added value to your solutions.

Get Professional .NET 2.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.