// class which // results in // implicit

// instantiation

Function Template

Following are examples of explicit and implicit instantiation syntax for a function template:

template <class T> void sort(Array<T> &); // declaration // for the

// sort() // function // template

template <class T> void sort(Array<T> &v) {/* ... */}; // definition // of the

// sort() // function // template

template void sort<char> (Array <char>&); // request to // explicitly // instantiate // the

// sort<char> () // template

// function

//NOTE <char> is not required if

//the compiler can deduce this.

void foo() {

 

 

 

Array <int> ai;

 

 

 

sort(ai);

// use of the

sort<int> ()

}

//

template function which

 

//

results in

implicit instantiation

 

 

 

 

NOTE: All template options on an aCC command-line apply to every file on the command line.

If you specify more than one option on a command-line, only the last option takes effect.

For More Information, refer to the ANSI/ISO C++ International Standard for additional details including explicit specialization syntax.

Command-Line Option Instantiation

See “Template Options” (page 91) for more information on command-line instantiation.

Compile-Time Instantiation

By default, compile-time instantiation is in effect. Instantiation is attempted for any use of a template in the translation unit where the instantiation is used. All used template functions, all static data members and member functions of instantiated template classes, and all explicit instantiations are instantiated in the resulting object file.

If there are duplicate instantiations at link-time, the linker arbitrarily selects an instantiation for inclusion in the a.out or shared library.

The following command-lines are equivalent; each compiles a.C using compile-time instantiation.

aCC -c +inst_compiletime a.C

aCC -c a.C

134 Using HP aC++ Templates