I am implementing a sort of MATLAB-esque interpreter. I had asked a question in a previous thread about std::vector and apparently it's not really want I want.
In MATLAB, you can dynamically allocate arrays in a very poor and inefficient fashion, i.e.
a(54,34) = 4.5;
would allocate an array of that size and set the very bottom right corner to 4.5. You can further say
a(54,66) = 23532;
which would resize the array and set that value.
My question is, what would be the most efficient way to implement this? Right now I'm just thinking that it needs to allocate an array larger than the initial dimensions (create a reserve), and every time you go to set a value, through overloaded operations or whatever, it'll have to check to see if you're requesting a location outside of the reserve and possibly resize and copy the old data. If it's not outside the reserve size, increase the "size" variable of the array to match the new largest dimensions accessed.
I can't really think of a better way to do this. I'd like to avoid if statements for every time you want to set a value...but I don't think I'm going to get around it. Thanks in advance for any suggestions.