This is an old revision of the document!


Dependent templates

We've already seen how template parameters can be used to construct parameterized circuits, as well as change the size of arrays in the process port list. In addition, they can also be used to specify parameters used in the template itself.

template<pint N; pint data[N]>
defproc test(chan!(int) out)
{
    chp {
       (; i : N : out!data[i])
     }
}

In the example above, the process test takes a parameter N, followed by a parameter array of size N.

pint x[3];
x[0] = 1; x[1] = 3; x[2] = 5;
test<3,x> t;

In the above example, the CHP body for instance t would be expanded into

  out!1; out!3; out!5