0
for(std::vector<TMenuItem*>::iterator itItem=miMoreStylesArray.begin(); itItem<miMoreStylesArray.end(); itItem++) {

If std::iterator is being fazed out, then what do I use instead to iterate through vector?

u666sa
  • 59
  • 4
  • 6
    `std::iterator` has nothing, or at best very little, to do with `std::vector::iterator`. It was meant as a base class for implementing one's own custom iterators. All it does is provide a bunch of typedefs. `std::vector::iterator` is not deprecated. – Igor Tandetnik Feb 20 '22 at 02:27
  • Related background on `std::iterator`: https://stackoverflow.com/a/48446603/11082165 – Brian61354270 Feb 20 '22 at 02:34
  • 2
    Regardless of the status of `std::vector::iterator`, `auto` makes your code a lot less noisy. To say nothing of range iteration syntax. – rici Feb 20 '22 at 02:50
  • 1
    I think what's most important to mention regarding this question is that the code shown doesn't make any direct use of `std::iterator`. Perhaps OP is confusing `std::iterator` with any symbol that's named `iterator`. – Drew Dormann Feb 20 '22 at 03:10

2 Answers2

2

std::iterator has nothing to do with the iterators of standard library containers, such as std::vector.

While it is true that std::iterator is deprecated, std::vector<TMenuItem*>::iterator is certainly not.

The deprecation of std::iterator is only relevant to you if you used it as a base class to implement your own custom iterator class.

user17732522
  • 53,019
  • 2
  • 56
  • 105
2

The use of std::iterator was in order to assist you in implementing iterator traits. However, you can easily implement your iterator and its inner traits by yourself without the need of std::iterator, see: Preparation for std::iterator Being Deprecated.

The iterators inside the standard containers remain untouched, as is. Note that they are declared inside their respective containers (e.g. vector<T>::iterator) and not inside std directly.

Amir Kirsh
  • 12,564
  • 41
  • 74