STL vector中的cend方法(9)

其实这跟end方法差不了多少,只不过这个iterator是有const属性。
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.

返回一个具有const属性的iterator指向超尾元素。


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.

一个const_iterator是一种类似于指向常量的迭代器,他们可以被递增或是递减(除非这个iterator本身是常量才不能这样),这就像和end()返回的iterator一样,只是cend()返回的迭代器不能用于修改该元素而已,甚至vector本身并不是const属性,该方法返回的iterator也是不能用于修改元素的.



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

如果容器为空,这个返回值跟cbegin()是一样的。


The value returned shall not be dereferenced.

该方法得到的iterator(除非递递减之后)不应该被解除引用。


Parameters

none

Return Value

const_iterator to the element past the end of the sequence.

返回值为一个const_iterator指向序列的超尾元素。


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

返回的iterator属于随机访问迭代器。


Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// vector::cbegin/cend
#include <iostream>
#include <vector>

int main ()
{
  std::vector<int> myvector = {10,20,30,40,50};

  std::cout << "myvector contains:";

  for (auto it = myvector.cbegin(); it != myvector.cend(); ++it)
    std::cout << ' ' << *it;
  std::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.
该方法不会访问容器里的元素,但是返回的这个iterator可以用来访问元素,并且用他们来访问或者是修改不同的元素都是安全的。(这里的修改?)

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值