Re: C++ is Slow?
nw <new@soton.ac.uk> wrote:
Having op[] return a dummy object is a poor idea, it makes it harder to
drop in different implementations. Only do something like that if you
absolutely have to. See the FAQ for more about this subject.
http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-1...
hmm... ok, the FAQ makes a good point. But raises a couple of
questions.
Firstly is it possible to create a generalizable n-dimensional matrix
using this method?
Of course.
Secondly is there anyway to make this compatible with (have a similar
interface to) a STL vector? It would be nice to use a STL container
for now and then implement my own classes later if required and select
between them using a template parameter.
I'm guessing your nomenclature is confused again. Do you mean a vector
of vectors, when you say "vector" above?
If a Matrix (2 dimensional array, whatever you want to call it) is part
of the problem space and can be implemented in more than one way, then
it should be represented as a class. It would not be "nice" to use a
vector of vectors now and then try to shoehorn some other implementation
into the code later.
Basically does this mean I should never use a multi-dimensional
vector, because I'm cutting myself off from the possibility of
changing the container later?
By all means, use a vector of vectors when you need the functionality
that such a construct would provide. A ragged array, for example, not a
2 dimensional array.