简体   繁体   English

是矢量 <int> :: const_iterator是output_iterator?

[英]Is vector<int>::const_iterator an output_iterator?

According to the C++ concepts: 根据C ++概念:

Any iterator other than input_iterator is an output_iterator. 除了input_iterator以外的任何迭代器都是output_iterator。

A vector<int>::const_iterator is a random_access_iterator , and of course that is an output_iterator . vector<int>::const_iteratorrandom_access_iterator ,当然是output_iterator

However, according to cppreference.com , an output_iterator must be writable, while a vector<int>::const_iterator is not. 但是,根据cppreference.comoutput_iterator必须可写,而vector<int>::const_iterator不可写。

Is vector<int>::const_iterator an output_iterator ? vector<int>::const_iteratoroutput_iterator吗?

See also: How to check if an iterator is an output_iterator in c++? 另请参见: 如何检查迭代器在c ++中是否为output_iterator?

No. vector<int>::const_iterator is a constant iterator ( [container.requirements.general] ), which means it does not satisfy the requirements of output iterators. vector<int>::const_iterator是一个常量迭代器[container.requirements.general] ),这意味着它不满足输出迭代器的要求。

[iterator.requirements.general]/4 : [iterator.requirements.general] / 4

Iterators that further satisfy the requirements of output iterators are called mutable iterator s. 进一步满足输出迭代器要求的迭代器称为可变迭代器 Nonmutable iterators are referred to as constant iterator s. 不可迭代的迭代器称为常量迭代器


An vector::const_iterator is a random_access_iterator, and of course is an output_iterator. vector :: const_iterator是random_access_iterator,当然是output_iterator。

This is simply wrong. 这是完全错误的。

Look here: Cpp Reference 在这里查看: Cpp参考

An OutputIterator is an Iterator that can write to the pointed-to element. OutputIterator是可以写入指向元素的Iterator。

What your quote apparently means to say is that any iterator that does not satisfy Input iterator requirements is an Output iterator. 您的报价显然意味着要说的是,任何不满足Input Iterator要求的迭代器都是Output迭代器。

The standard hierarchy of iterator categories defines (see 24.2.1) the following sequence of iterator categories with nested requirements 迭代器类别的标准层次结构定义(参见24.2.1)具有嵌套需求的以下迭代器类别序列

Random Access -> Bidirectional -> Forward -> Input 随机访问->双向->转发->输入

while Output iterator category stands alone. 而输出迭代器类别则独立存在。

This nesting means that every Forward iterator is also Input iterator (ie also satisfies the requirements of Input iterator category), every Bidirectional iterator is also Forward and Input iterator at the same time. 这种嵌套意味着每个正向迭代器也是输入迭代器(即也满足输入迭代器类别的要求),每个双向迭代器同时也是正向和输入迭代器。 This is the context in which your quite is supposed to be interpreted. 在这种情况下,您应该对您的事物进行解释。

std::vector::const_iterator is a Random Access iterator, which makes it satisfy the requirements of Bidirectional, Forward and Input iterator as well. std::vector::const_iterator是一个随机访问迭代器,它也满足双向,正向和输入迭代器的要求。 Ie in that sense std::vector::const_iterator is an Input iterator (!). 即从这个意义上说std::vector::const_iterator 一个输入迭代器(!)。 For which reason your quote cannot be used to deduce that it is an Output iterator. 因此,您的报价不能用来推断它是一个输出迭代器。

The further subdivision into mutable iterators and nonmutable ( constant ) iterators is applied on top of that, but it is not necessary to bring it into the picture in this case. 除此之外 ,还可以进一步细分为可变迭代器和 可变常量 )迭代器,但是在这种情况下,不必将其引入图片中。

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

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