Reputation: 27
std::list<std::string> list = {"Milton", "Shakespeare", "Austen"};
auto it_1 = list.begin(); // auto -> std::list<std::string>::iterator
auto it_2 = list.rbegin(); // auto -> std::reverse_iterator<std::list<std::string>::iterator>
// std::list<std::string>::reverse_iterator it_3 = list.rbegin();
Please explain why the iterator type for begin()
when using auto
is different from the iterator type for rbegin()
?
What is the understanding that the begin()
iterator should have type std::list<std::string>::iterator
and the rbegin()
iterator should have type std::list<std::string>::reverse_iterator
, but VS2022 suggests that rbegin()
's iterator type is not what I expected:
I expected it_2
to be the following type:
std::list<std::string>::reverse_iterator
Please explain what type it_2
actually hides?
Upvotes: 0
Views: 115
Reputation: 66961
std::list<std::string>::reverse_iterator
is required to be a typedef of std::reverse_iterator<std::list<std::string>::iterator>
. This means that they are simply different names for the same class.
Upvotes: 1