Point was, you can merge functions into one where applicable.
It's a maintenance thing.
My point was, there are things you can do with separate get/set functions that you can't do with an all-in-one get function. The opposite is not true.
Hence, it limits your implementation.
If your particular implementation should happen to work into an all-in-one interface, then yeah you
can combine it.
However, should the implementation need to change in the future (due to additional needs, or a change in overall design, or whatever), it might be difficult/impossible to keep the all-in-one function. Which means you have an API break, which means you have to rewrite not only the class, but all code that uses it.
So yeah -- it's something to avoid.
you'll like the assignment operators.
As long as they make sense conceptually and aren't simply a way to avoid typing out a function name, then I'm fine with it =P
Exceeding it's capacity (or changing it's size) is a resize.
But see, exceeding it's capacity or changing it's size are
two different things, which I'm not sure you're grasping.
A vector may only have 10 elements in it, but will have space allocated for 20. (ie: a size of 10, a capacity of 20).
You can add and remove any number of elements to the end of that vector without needing
any reallocation, until you exceed 20 elements, at which point, the capacity needs to be increased and the memory reallocated.
See std::vector::reserve and std::vector::capacity. They're different from std::vector::resize and std::vector::size.
Aside from a hat-tip to realloc,
realloc causes complex types to explode, hence why it can't be used in such a class unless you limit that class to contain POD types only.
my point is it needs to copy less frequently rather than not at all. Latter statement is true, but classes shouldn't have the capacity to be used wrongly.
vector actually makes an effort to "guess" as to how much capacity you need in anticipation of future growth. Yeah, it will get it wrong a lot, but it's pretty much impossible to get it right all the time (or even a high percentage of the time).
As for being able to use a class wrongly -- that's where the performance-vs-safety issue comes in. Although in this case we're not really talking about using vector "wrong", just "inefficiently".
Optimisation usually requires you re-write the foundation code in the first place
I don't know about "usually". Sometimes, yeah.
But we're not talking about ripping apart and reoptimizing an entire program, here. We're talking about replacing one linked list with another. They're both going to work more or less the same way, so really there's no reason why they couldn't/shouldn't be interchangable.
I find it better to optimise first. More specifically, write short example code to test assumptions, if assumptions wrong, update, if assumptions correct, expand, clarify, incorporate.
I find that optimizing is a very small part of the actual work I do on a project.
I keep it in mind when designing to avoid doing things that are
obviously slow or wasteful, but other than that I just run with it. Running into performance issues that actually needed to be seriously addressed afterward is actually quite rare. C++ is fast.
Bear in mind I type like a zoned out monkey when it comes to code.
I guess I just assumed everyone is as occupied with real life as I am sometimes. =P
Actually, combining both gives you the best of both worlds, fast insertion, with random access [snip]
it's more intended you add a load of items, access them at random, do some work, access it at random, then add more items, repeat.
I guess I'm just having a hard time seeing how this would be useful. Your example at the end of your post didn't make a lot of sense to me. Why would you need to access images randomly?