template<unsigned int m, unsigned int n, class T = float>
class matrix
{
public:
// Constructor
matrix() {}
T & operator () (const unsigned int i, const unsigned int j)
{ return element[i*n+j]; } // <- is THIS calculated
//at compile time or at runtime?
private:
T element[m*n];
};
Thanks a lot!
--------------------------------------------------------
There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
There is another theory which states that this has already happened...
[edited by - Corrail on February 2, 2004 10:15:27 AM]
At Runtime or at Compile time?
Hi all!
I'm just writing a template matrix library and have a question about when the following example is calculated:
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
Do you want to know when the "i*n+j" is calculated? It is calculated at runtime because i and j could be anything. Unless I''m missing something...
*damn*
Sorry, you''re right. And if I call
When is this calculated? Does it change anything if I declare that operator function as inline?
--------------------------------------------------------
There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
There is another theory which states that this has already happened...
Sorry, you''re right. And if I call
matrix<3,3,float> tmp;tmp(0,0) = 0.0f;
When is this calculated? Does it change anything if I declare that operator function as inline?
--------------------------------------------------------
There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
There is another theory which states that this has already happened...
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
Yes, this is calculated at runtime.
This would be calculated at compiletime.
...
template < int i, int j >
T & operator () ()
{ return element[i*n+j]; }
...
But I see no reason to make such things.
[edited by - OdinsKrieger on February 2, 2004 10:38:05 AM]
This would be calculated at compiletime.
...
template < int i, int j >
T & operator () ()
{ return element[i*n+j]; }
...
But I see no reason to make such things.
[edited by - OdinsKrieger on February 2, 2004 10:38:05 AM]
Yeah... That would definitly cause an function overkill...
Ok, thanks a lot. I''ll try to optimzie it in another way.
--------------------------------------------------------
There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
There is another theory which states that this has already happened...
Ok, thanks a lot. I''ll try to optimzie it in another way.
--------------------------------------------------------
There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
There is another theory which states that this has already happened...
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement