首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

OutputIterator

OutputIteratorIterator可以写入指向元素的。

实现OutputIterator是STD::Ostream[医]迭代器...

何时ForwardIterator,,,BidirectionalIterator,或RandomAccessIterator满足OutputIterator除了它自己的需求之外,它还被描述为可变...

所需

类型X满足OutputIterator如果。

  • 类型X满足Iterator
  • X是类类型或指针类型。

还有,给予。

  • o,某个类型的值可以写到输出迭代器%28--可能有多个类型是可写的,例如operator=可能是模板。没有关于value_type至于输入迭代器%29
  • r,类型的值X,,,

下列表达式必须有效并具有指定的效果。

Expression

Return

Equivalent expression

Pre-condition

Post-conditions

Notes

*r = o

(not used)

?

r is dereferencable

r is incrementable

After this operation r is not required to be dereferenceable and any copies of the previous value of r are no longer required to be dereferenceable or incrementable.

++r

X&

?

r is incrementable

&r == &++r, r is dereferencable or past-the-end

After this operation r is not required to be incrementable and any copies of the previous value of r are no longer required to be dereferenceable or incrementable.

r++

convertible to const X&

X temp = r; ++r; return temp;

?

?

?

*r++ = o

(not used)

*r = o; ++r;

?

?

?

注记

的唯一有效用途operator*输出迭代器在赋值的左边:operator*可以返回一个代理对象,该对象定义了一个成员。operator=%28,这可能是模板%29。

对于输出迭代器,不能定义等式和不等式。即使operator==被定义,x == y不必暗示++x == ++y...

通过输出迭代器的相同值分配只能发生一次:输出迭代器上的算法必须是单程算法。

通过输出迭代器分配的任务将与增量交替。双增量是未定义的行为%28C++标准目前声称支持双增量,这与stl文档相反lwg#203529%。

只允许纯输出迭代器声明其iterator_traits<X>::value_type,,,iterator_traits<X>::difference_type,,,iterator_traits<X>::pointer,和iterator_traits<X>::reference成为void%28和迭代器,如std::back_insert_iterator只做%29。

标准库

以下标准库迭代器是不为前向迭代器的输出迭代器:

  • std::ostream_iterator
  • std::ostreambuf_iterator
  • std::insert_iterator
  • std::back_insert_iterator
  • std::front_insert_iterator

另见

  • Iterator库
代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com