gpt4 book ai didi

c++ - 根据标准,std::vector erase 运算符的返回值是多少?

转载 作者:太空狗 更新时间:2023-10-29 23:38:50 25 4
gpt4 key购买 nike

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

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

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

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

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

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

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

无法理解这是在标准中描述的
你能指点一下吗?

更新:我的问题不是关于vector::erase 是如何工作的,
而是从标准中的哪个位置,因为我认为这是可靠的信息来源,我们可以推断出有关返回值的信息

最佳答案

信息位于稍微不直观的位置。 erase 返回的内容在一般容器要求部分的序列容器部分有详细说明,特别是 [sequence.reqmts]/11

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

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.

关于c++ - 根据标准,std::vector erase 运算符的返回值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52301100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com