------- Comment #18 from jacob at math dot jussieu dot fr  2006-12-14 16:47 
-------
(In reply to comment #15)
> If the loop bounds are compile-time constants you can use template
> metaprogramming to unroll them.
> 

I shouldn't elaborate on this as this is not the subject of this bug report,
but anyway...

I can't do template unrolling, because actually my template classes are part of
a complicated CRTP ("curiously recurring template pattern") where size() is a
wrapper around a method in a template parameter, and depending on this
parameter, size() may or may not be known at compile time.

The idea is that when you write a library for matrices/vectors, it's always a
dilemma whether the size (dimension) of the matrices/vectors should be a
template parameter(hence fixed at compile-time) or a variable. In the first
approach the coords of the matrix/vector are stored in a T array[Size], in the
second approach they are dynamically allocated with array=new T[Size]. Both
approaches have their pro's and con's, and the "killer feature" of my library
is that it allows both with the same underlying C++ code. This is where the
CRTP is useful. So size() returns a compile-time constant in the first
approach, and a variable in the second one. And I would like the loops to get
unrolled only in the first approach (and, if possible, only if the size is not
too large). So template metaprogramming for that, while probably possible,
would be much hassle.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30201

Reply via email to