根据标准,std :: vector擦除运算符的返回值是什么? [英] What is return value from std::vector erase operator, according to the standard?

查看:121
本文介绍了根据标准,std :: vector擦除运算符的返回值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更喜欢从源头获取信息,在这种情况下,这是ISO-IEC 14882, 擦除方法描述如下:

I prefer to get info from the source, for this case this is ISO-IEC 14882, where erase method is described as the following:

迭代器擦除(const_iterator位置);
迭代器擦除(首先是const_iterator,最后是const_iterator);

"iterator erase(const_iterator position);
iterator erase(const_iterator first, const_iterator last);

效果:无效 擦除点或擦除点之后的迭代器和引用.

Effects: Invalidates iterators and references at or after the point of the erase.

复杂度:T的析构函数称为次数等于 擦除的元素数,但是的移动分配运算符 T称为与元素中元素数相等的次数. 删除元素后的向量.

Complexity: The destructor of T is called the number of times equal to the number of the elements erased, but the move assignment operator of T is called the number of times equal to the number of elements in the vector after the erased elements.

抛出:什么都没有,除非有异常 由复制构造函数,移动构造函数,赋值引发 运算符,或移动T的赋值运算符."

Throws: Nothing unless an exception is thrown by the copy constructor, move constructor, assignment operator, or move assignment operator of T."

找不到有关返回的迭代器的信息, 当然,我用Google搜索并得到:

Can't find information about returned iterator, of course, I Googled and got:

一个迭代器,指向后面的元素的新位置 函数调用删除的最后一个元素

An iterator pointing to the new location of the element that followed the last element erased by the function call

无法理解标准中的描述
你能指出我吗?

Can't understand there this is described in the standard
Could you point me on it?

更新:我的问题不是关于vector::erase的工作方式,
但是我可以从标准的哪个位置开始,作为我接受的可靠信息来源,我们就可以推断出有关返回值的信息

Update: my question is not about how vector::erase works,
but rather from where in the standard, as I accept as reliable source of information we can deduce information about returned value

推荐答案

信息位于不太直观的位置. erase返回的内容在常规容器要求"部分的序列容器"部分下进行了详细说明,尤其是 [sequence.reqmts]/11

The information is in a slightly un-intuitive place. What erase returns is detailed under the sequence containers section of general container requirements section, specificly [sequence.reqmts]/11

a.erase(q)返回的迭代器指向在删除元素之前紧接q的元素.如果不存在这样的元素,则返回a.end().

The iterator returned from a.erase(q) points to the element immediately following q prior to the element being erased. If no such element exists, a.end() is returned.

[sequence.reqmts]/12

a.erase(q1, q2)返回的迭代器在擦除任何元素之前先指向q2指向的元素.如果不存在这样的元素,则返回a.end().

The iterator returned by a.erase(q1, q2) points to the element pointed to by q2 prior to any elements being erased. If no such element exists, a.end() is returned.

这篇关于根据标准,std :: vector擦除运算符的返回值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆