10.1. What is a template

A template defines a family of related classes or functions, where the parameters in the declaration describe how they are specialized. Templates are generic entities that can be instantiated to create specific user-defined types. The compiler generates new classes or functions when you supply arguments for the parameters. The class or function definition generated from a template with a set of template parameters is called a specialization.

Templates are an area of the C++ language that provide a great deal of flexibility for developers. The ISO C++ standard defines the language facilities and features for templates. Unfortunately, the standard does not specify how a compiler should implement templates. This means that there are sometimes significant differences between the methods used to implement templates in compiler products from different vendors.

Developers porting C++ code that uses templates to the AIX platform sometimes have problems with the implementation model. The main problems experienced are:

  • Long compile and link times

  • Linker warnings of duplicate symbols

  • Increase in code and executable size

Up until VisualAge C++ for AIX Version 6.0, all of the above problems are generally caused by inefficient use of the compiler implementation of templates. The Version 6 compiler provides new options that handle templates more efficiently. The number of problems experienced will depend on the platform the code is being ported from and the template implementation method used on that platform. Sometimes, the problems can be fixed on AIX by simply adding a few compiler options. In other instances, the code layout needs to be changed in order to utilize the most efficient implementation method on AIX. In most of these rare cases, the code changes are backwards compatible with the original platform the code is being ported from. This is very important for developers who maintain a single source tree that must compile correctly on multiple platforms.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset