I wonder if the two following implementations will produce exactly the same thing with the same performances whatever the compiler I use :
template<class T, unsigned int TSIZE> MyClass1
{
static const unsigned int size_const = 0;
public:
inline void Loop()
{
for(unsigned int i = 0; i < TSIZE; ++i) {
/* DO SOMETHING ON DATA */
}
}
T _data[TSIZE];
};
template<class T, unsigned int TSIZE> MyClass2
{
static const unsigned int size_const = TSIZE;
public:
inline void Loop()
{
for(unsigned int i = 0; i < size_const; ++i) {
/* DO SOMETHING ON DATA */
}
}
T _data[size_const];
};
In the first one, as TSIZE used in the loop is a template parameter, it is almost guaranteed that the compiler will unroll the loop if needed. If the loop is unrolled in the first case, would it be unrolled in the second case (the only difference is that TSIZE is stored in a static const) ?
Thank you very much.