简体   繁体   English

为什么 begin 和 rbegin 迭代器类型的拼写不同?

[英]Why are the begin and rbegin iterator types different in spelling?

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() ?请解释为什么使用autobegin()的迭代器类型与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: begin()迭代器应具有类型std::list<std::string>::iteratorrbegin()迭代器应具有类型std::list<std::string>::reverse_iterator的理解是什么,但是VS2022 建议rbegin()的迭代器类型不是我所期望的:

图像

I expected it_2 to be the following type:我希望it_2是以下类型:

std::list<std::string>::reverse_iterator

Please explain what type it_2 actually hides?请解释it_2实际隐藏的是什么类型?

std::list<std::string>::reverse_iterator is required to be a typedef of std::reverse_iterator<std::list<std::string>::iterator> . std::list<std::string>::reverse_iterator必须std::reverse_iterator<std::list<std::string>::iterator>的类型定义。 This means that they are simply different names for the same class.这意味着它们只是同一个 class 的不同名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM