Avoiding some template bloat?

bearophile bearophileHUGS at lycos.com
Mon Oct 8 15:35:12 PDT 2012


> (if necessary slicing the fixed sized matrix into a dynamic 
> array of dynamic arrays).

It's not hard to convert a fixed sized matrix into this run-time 
value that requires no templating on the sizes and requires no 
slicing and no heap allocations inside the template function that 
performs just the compile-time tests:

struct Mat2D(T) {
     T* ptr;
     size_t nrows, ncols;
     // + indexing methods
}

Using something like that the matrix multiplication function I've 
shown becomes just a shell that calls a function that accepts two 
Mat2D and is templated only on T.

Bye,
bearophile


More information about the Digitalmars-d mailing list