Why? With closed_account::vector_ptr and with closed_account::unique_vector_ptr, one can literally safely access any vector element (even though it may be out of bounds) with no range limit. |
That is exactly what he is saying has no purpose. I personally can't think of a single reason why you would want that as a "feature" (Access any element even out of bounds).
All you are doing is covering up a run-time error and allowing the application to fail silently in the background instead of crashing.
This is not something you want to do...
You are probably going to ask why so I will try to explain it to you, though bear with me it has been a long night ;). When all you are doing is hiding the run-time exception and then continuing on with execution of the program the programmer has no idea that he/she made a logical error in the code (Trying to access an element out-of-ranges).
Instead they will think that the code is working as it should be, that is until something in their code breaks because of that normally out-of-range element. And that will happen trust me because they are not accessing the element they thought they would be. Instead they are doing whatever they wanted to do on a new permanent element that they don't even know about which will just cause even more errors down the line(Not to mention all the other new elements in the vector you added between the end of "real" vector and the out-of-range element).
Now in the case of a normal std::vector the programmer would know pretty quickly they made the logical error because of the out-of-bounds exception, but in your solution that logical error gets hidden and will be harder to notice and find.
Seriously just think about the main "problem" you are trying to solve (Make it so that it doesn't matter what element you try and access on a vector) for a little bit.
Can you name a single instance where accessing an element that is out-of-range on a std::vector is not a logical error?
You can't because you never should want or need to access an element that you know is out-of-range, other than that there is only the obvious error where you didn't know it was out-of-range which is even worse (As I described above).
All in all that is what NoXzema means when he says that it has no point to it. In fact I would go even further and say that not only does it try and solve a problem that isn't there, it also introduces new problems like silently squashing run-time exceptions and continuing execution in a bad state.
Hope I didn't do to bad of a job trying to explain this, if you didn't understand anything (Sorry been a long day so not sure if I worded things correctly) just let me know and I will try and explain better.