Next: , Up: Templates


9.1 Template Basics

CAST supported parameterized definitions and types, also known as templates. HAC supports templates using C++-like template syntax. Templates are useful for defining a family types with highly regular differences. Such generalizations often occur in definitions whose port sizes or implementations vary enumerably or trivially. The most notable differences from CAST templates and HAC templates is the use of angle brackets around template arguments and parameter declarations, and the grammatic location of the template signature1.

In CAST, a parameterized definition might look like this:

     define foo(int N) (node[N] x) { }

The equivalent definition in HAC would be:

     template <pint N>
     defproc foo (bool x[N]) { }

CAST and HAC alike support parameter-dependent template parameters.

     define array()(int N, D[N]) { }

would be written in HAC as:

     template <pint N, D[N]>
     defproc array() { }

Definitions are not the only templatable entities. Typedef Templates, discusses how typedefs can be templated in HAC.


Footnotes

[1] This originates from C++ template syntax.