5 Using HP aC++ Templates

The following sections overview template processing and describe the instantiation coding methods available to you.

“Invoking Compile-Time Instantiation” (page 132)

“Scope and Precedence” (page 132)

“Template Processing” (page 132)

“Explicit Instantiation” (page 133)

“Command-Line Option Instantiation” (page 134)

“Compile-Time Instantiation” (page 134)

“Migrating from Automatic Instantiation to Compile-time Instantiation” (page 135)

“C++ Template Tutorial” (page 136)

Invoking Compile-Time Instantiation

There are three methods of invoking compile-time instantiation:

Explicit Instantiation (developer-directed)

Command-Line Option Instantiation (developer-directed)

Compile-Time Instantiation (default)

Scope and Precedence

Explicit instantiation provides instantiation for a particular template class or template function. While command line options and the default compile-time instantiation provide instantiation at the level of the translation unit.

If you use explicit instantiation in addition to command-line options or default instantiation, explicit instantiation takes precedence.

For example, using the +inst_compiletime option requests instantiation of all used template functions and all static data members and member functions of instantiated template classes within a translation unit. Using explicit instantiation requests instantiation of all members of a particular template class or a particular template function.

Template Processing

In HP aC++, compile-time instantiation is the default template instantiation mechanism. During compile-time instantiation, the compiler instantiates every template entity it sees in a translation unit provided it has the required template definition.

Following is the overview of template processing:During compile-time instantiation, the compiler instantiates every template entity it sees in a translation unit provided it has the required template definition

The compiler places an instantiation in every .o file in which a template is used and its definition is known. The linker arbitrarily chooses a .o file to satisfy an instantiation request. Only the chosen instantiation appears in the a.out or .so file. Any redundant instantiations in other .o files are ignored.

No instantiation information is placed in object (.o) files. The linker is responsible for ignoring duplicate instantiations.

No .I files are created. All .o files are compiled only once.

132 Using HP aC++ Templates

Page 132
Image 132
HP C/aC++ for PA-RISC Software manual Using HP aC++ Templates, Invoking Compile-Time Instantiation, Scope and Precedence