Yes, you are complicating If you have declaration like this : template class MyMatrix then the transpose function should be like this : template MyMatrix Transpose( const MyMatrix & m ) { MyMatrix res; // implementation return res; }.
Yes, you are complicating. If you have declaration like this : template class MyMatrix then the transpose function should be like this : template MyMatrix Transpose( const MyMatrix & m ) { MyMatrix res; // implementation return res; }.
My personal feeling is that this is making things way too complex. By all means include the data type in the template, but including the dimensions seems wrong.
2 He is probably thinking that the compiler can open-code operations on small matrices (and thus avoid loop overhead) when the bounds are compile-time constants. He might be right. – Nemo Jun 5 at 17:52 @Nemo - ah, OK - C++ is not my thing (any more) - so it seemed odd to me.
Thanks Nemo. – Will A Jun 5 at 17:53 1 Depending on your field, the additional type safety can also be useful, and it also allows non-heap allocation of your underlying data structure. Ultimately, the more general solution is usually the better call, but there are definitely arguments in favor of unique types.
– Dennis Zickefoose Jun 5 at 18:23.
The first attempt fails because the specialization is a separate type and the template parameters of the base template are not known there. The second verision is correct according to the language, but like Will A says - do you really want every combination of row and col to create a new type?
I would write it something like this, to allow arbitrary depths of recursion (matrices of matrices of matrices...) template struct MyMatrix { typedef T value_type; T stuffrowscols; // or whatever }; // For basic types, transpose is identity. Template struct Transpose { typedef T result_type; result_type operator()(const T & in) { return in; } }; // For more complex types, specialize and invoke recursively. Template struct Transpose > { typedef MyMatrix, cols, rows> result_type; result_type operator()(const MyMatrix & in) { Transpose transposer; // (invoke transposer on each element of in and build result) } }; Here, Transpose is a functor; you create an instance of it but call it as a function.
For extra credit, you could have it inherit from unary_function and get the result_type typedef for free...
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.