Is string :: iterator necessarily random_access_iterator?

This page indicates that string::iterator and string::const_iterator are “specific types of iterators for the compiler”. Does this mean that this string::iterator made in a category other than random_access_iterator ?

+6
source share
4 answers

ISO C ++ 03, 21.3-2 :

(...) Also, since iterators supported by basic_string are random access iterators (...)

So yes, these are necessarily random access iterators.

+12
source

Looking at N3376 21.4/3

Iterators supported by basic_string are random access iterators.

For such tasks, it is always a good idea to have a standard (or draft) handy. It takes some time to get used to finding things there, but this is the first resource.

+5
source

This page says that std::string::iterator is RandomAccessIterator and it is much more reliable than cplusplus.com.

+3
source

This does not mean that it is not a random access iterator (as other answers said, the standard requires it to be a random access iterator.)

What this means is that the exact types of iterators are unspecified, that is, they can be char* , or they can be std::string::__iterator or __gnu_cxx::__normal_iterator<char, std::string> or something else. Any of these implementation options is allowed as long as it satisfies the requirements of the random access iterator and can be called by the name string::iterator

+3
source

Source: https://habr.com/ru/post/920165/


All Articles