STL vector中的end方法(8)

来源:互联网 发布:java获取浏览器地址 编辑:程序博客网 时间:2024/06/04 17:54
public member function
<vector>

std::vector::end

  • C++98
  • C++11
      iterator end() noexcept;const_iterator end() const noexcept;
Return iterator to end
Returns an iterator referring to the past-the-end element in the vector container.

返回一个超尾迭代器指向vector容器最后元素的再下一个元素(这个位置是没有元素存在的)。


The past-the-end element is the theoretical element that would follow the last element in the vector. It does not point to any element, and thus shall not be dereferenced.

这个超尾元素是一个假设紧跟容器最后一个元素的下一个位置的元素,但是该超尾迭代器本身是不指向任何元素的,因此不应该被解除引用。


Because the ranges used by functions of the standard library do not include the element pointed by their closing iterator, this function is often used in combination with vector::begin to specify a range including all the elements in the container.

因为标准库里面用于指示范围的函数并没有包含被超尾迭代器所指向的元素,这个函数通常联合begin一起来使用用于指出容器范围内的所有元素。区间范围为[begin,end)


If the container is empty, this function returns the same as vector::begin.
如果容器是空的,那么这个函数的返回值和begin是一样的。

Parameters

none

Return Value

An iterator to the element past the end of the sequence.
返回值是一个超尾迭代器,指向超出序列范围外的一个位置。

If the vector object is const-qualified, the function returns a const_iterator. Otherwise, it returns an iterator.

如果vector对象本身具有const属性,那么将返回一个const_iterator,否则,返回一个普通的iterator.


Member types iterator and const_iterator are random access iterator types (pointing to an element and to a const element, respectively).

该迭代器的类型属于随机访问迭代器类型。


Example

12345678910111213141516
// vector::begin/end#include <iostream>#include <vector>int main (){  std::vector<int> myvector;  for (int i=1; i<=5; i++) myvector.push_back(i);  std::cout << "myvector contains:";  for (std::vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)    std::cout << ' ' << *it;  std::cout << '\n';  return 0;}
Edit & Run


Output:
myvector contains: 1 2 3 4 5

Complexity

Constant.

Iterator validity

No changes.

Data races

The container is accessed (neither the const nor the non-const versions modify the container).

容器将被访问。

No contained elements are accessed by the call, but the iterator returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.

当这个函数调用时,容器内的元素不会被实际访问,但是该迭代器可以用来访问或者是修改元素,并且他们的操作都是安全的。


Exception safety

No-throw guarantee: this member function never throws exceptions.

The copy construction or assignment of the returned iterator is also guaranteed to never throw.

该方法不会抛出异常

利用复制构造器或者是赋值运算符得到的该iterator也不会抛出异常

//翻译的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。

转载请注明出处:http://blog.csdn.net/qq844352155

2014-8-11

于GDUT




0 0
原创粉丝点击