Up: Template Forward Declarations


9.2.1 Template signature equivalence

The formal parameters of a forward signature are allowed to have identifiers, which facilitates latter parameters depending on former parameters. Forward declarations are equivalent if the prototype name matches (in the same namespace) and their template signatures are equivalent. The following forward declarations are equivalent (in C++):

     template <int> class foo;
     template <int P> class foo;
     template <int Q> class foo;

However, only the identifiers used in template class definitions may be referenced from within the definition.

     template <int R>
     class foo {
       /* R may be referenced as the first parameter */
     };

Note that nowhere outside of the definition, can template parameters be referenced (just as in C++). In \hac, one may declare an instance of a declared but undefined type, which may not necessarily contain any named parameters.

     foo<7> bar;
     int N = bar.R; // ERROR: no public member named R

Here is an example of equivalent template signatures:

     template <int N, int [N]> ...
     template <int N, int A[N]> ...
     template <int N, int B[N]> ...
     template <int M, int A[M]> ...
     template <int M, int B[M]> ...

In all cases, the first parameter must be named because the second parmeter depends on the first. Since nothing else depends on the second parameter, its name is optional. Again, only the parameter names used in the definition may be referenced from within the definition.

The same rules in this section (ripped off of C++) pertain to process, channel, and datatype template definitions in HAC.