您的位置:首页 > 编程语言 > C语言/C++

vector::cend (c++ 11)

2016-07-23 15:18 441 查看
public member function

<vector>


std::vector::cend

const_iterator cend() const noexcept;


Return const_iterator to end
Returns a const_iterator pointing to the past-the-end element in the container.

A const_iterator is an iterator that points to const content. This iterator can be increased and decreased (unless it is itself also const), just like the iterator returned by vector::end,
but it cannot be used to modify the contents it points to, even if the vector object is not itself const.

If the container is empty, this function returns the same as vector::cbegin.

The value returned shall not be dereferenced.


Parameters

none


Return Value

A const_iterator to the element past the end of the sequence.

Member type const_iterator is a random access iterator type that points to a const element.

// vector::cbegin/cend
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector = {10,20,30,40,50};
cout << "myvector contains:";
for (auto it = myvector.cbegin(); it != myvector.cend(); ++it)
cout << ' ' << *it;
cout << '\n';

return 0;
}

Output:

myvector contains: 10 20 30 40 50


Complexity (复杂性)

Constant.


Iterator validity

No changes.  该方法不会对其他迭代器的有效性造成影响。


Data races

The container is accessed. 该容器应该是可访问的。

No contained elements are accessed by the call, but the iterator returned can be used to access them. 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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: