[英]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()
?请解释为什么使用
auto
时begin()
的迭代器类型与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>::iterator
而rbegin()
迭代器应具有类型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.