Quote:Original post by SiCrane
Your initial statement, "you can save a lot of time in the future when you start trying to treat an iterator as you would a pointer", which you conveniently edited out of the quote, has nothing to do with that. What you just said is a restatement of your container of pointers argument, my objection to which you didn't address.
I'm sorry, but I didn't 'conveniently edit' something to try and make my point I simply wanted to cut down on the amount of quoting. Maybe I'm not explaining myself clearly enough.
I was trying to stress that if you start to believe that an iterator is a pointer (which using -> can lead you to think that especially when you start to use STL), then it will cause you problems in the future. I don't know if "you can save a lot of time in the future when you start trying to treat an iterator as you would a pointer" was clear enough, but I meant you can save yourself time by knowing exactly why treating an iterator like a pointer causes errors, rather then trying to use it as one and not knowing why it doesn't work.
By dereferencing the iterator, you are working with the basic type stored within the vector, a type you know and a type you understand.
Would I dereference a vector<MyObject**>::iterator. To right I would. I'd much rather use the basic type (MyObject**) as I assume I know what that is, know how it works and understand the context in which I am using it.
Quote:Original post by SiCrane
And using those facts are also useful in writing more readable and clear code. Unless you think that
... Some STL Code...
No, but then that example doesn't cover the concerns I was having. Both versions treat the iterator as a MyObject*.
Personally I would call do_something(*(my_vector.begin()+7)) and pass it by reference for two reasons
* I don't want it passed by pointer because I don't want to treat an iterator as such
* I'm taking it that it cannot be null (and if it was out of bounds, then iterator debugging would hopefully catch it).
Quote:Original post by SiCrane
And this code shows no mention of operator -> whatsoever.
I'm not sure what you are trying to prove with that statement because of course it doesn't. But by being able to use iterators as pointers (by being able to use operator->), people do think they can treat them as they would any kind of pointer, hence the example of a cast (which it trying to show a case in point where not treating iterators as pointers can save you time).
We are talking about two different things here. You are talking about the implementation details of the STL, I'm specifically talking about the use (and specifically the ease of use) of the STL. Knowledge of the STL is not something that everyone has, and I can assure you iterators are one of the things that tend to trip people up. By keeping it within the realms that people are confident with, that makes the intent clear (something which the STL often does not do), makes it easier to use and maintain, and makes it easier to move onto other concepts of the STL as your knowledge grows.
Whether you agree or not, I know this from experience.