vector::cbegin (c++11)
2016-07-23 15:04
281 查看
//其实这个和begin差不多,只是具有了const属性,不能用于修改元素而已。
public member function
<vector>
Return const_iterator to beginning
Returns a const_iterator pointing to the first element in the container.
返回一个const_iterator指向容器的第一个元素。
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::begin,
but it cannot be used to modify the contents it points to, even if the vector object is not itself const.
一个const_iterator是一种类似于指向常量的迭代器,他们可以被递增或是递减(除非这个iterator本身是常量才不能这样),这就像和begin()返回的iterator一样,只是cbegin()返回的迭代器不能用于修改该元素而已,甚至vector本身并不是const属性,该方法返回的iterator也是不能用于修改元素的.
If the container is empty, the returned iterator value shall not be dereferenced.
如果容器为空,不应该对该iterator解除引用(即对该iterator取*)
Parameters
none
A const_iterator to the beginning of the sequence.
一个指向序列第一个元素的具有const属性的iterator.
Member type const_iterator is a random access iterator type that points to a const
element.
该const_iterator属于随机访问迭代器,指向一个具有const属性的元素(该元素本身可能并不是const的)
Constant.
No changes.
该方法不会对其他迭代器的有效性造成影响。
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可以用来访问元素,并且用他们来访问或者是修改不同的元素都是安全的。(这里似乎有点问题?运用const_cast转换?这里似乎转化不了,什么情况?)
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的拷贝也不会抛出异常。
public member function
<vector>
std::vector::cbegin
const_iterator cbegin() const noexcept;
Return const_iterator to beginning
Returns a const_iterator pointing to the first element in the container.
返回一个const_iterator指向容器的第一个元素。
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::begin,
but it cannot be used to modify the contents it points to, even if the vector object is not itself const.
一个const_iterator是一种类似于指向常量的迭代器,他们可以被递增或是递减(除非这个iterator本身是常量才不能这样),这就像和begin()返回的iterator一样,只是cbegin()返回的迭代器不能用于修改该元素而已,甚至vector本身并不是const属性,该方法返回的iterator也是不能用于修改元素的.
If the container is empty, the returned iterator value shall not be dereferenced.
如果容器为空,不应该对该iterator解除引用(即对该iterator取*)
Parameters
none
Return Value
A const_iterator to the beginning of the sequence.一个指向序列第一个元素的具有const属性的iterator.
Member type const_iterator is a random access iterator type that points to a const
element.
该const_iterator属于随机访问迭代器,指向一个具有const属性的元素(该元素本身可能并不是const的)
// 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.
该方法不会访问容器里的元素,但是返回的这个iterator可以用来访问元素,并且用他们来访问或者是修改不同的元素都是安全的。(这里似乎有点问题?运用const_cast转换?这里似乎转化不了,什么情况?)
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的拷贝也不会抛出异常。
相关文章推荐
- 大话设计模式12----外观模式
- C++ vector用法
- 并查集C++实现
- leetcode_c++:栈: Implement Queue using Stacks(232)
- c++ 在windwos上创建盘符,并且,监控盘符里面任一文件的变动事件
- 谈谈8年C++面向对象设计的经验体会
- C/C++头文件大全
- leetcode_c++:栈: Implement Stack using Queues(225)
- 模拟实现strstr函数
- Google C++编程规范--《空格的使用》
- leetcode_c++:栈: Basic Calculator(224)
- C++小常识笔记
- C99 新增了复数类型(_Complex)和虚数类型(_Imaginary)。简单来说,C99 提供了三种复数类型:float _Complex,double _Complex,和 long do
- 一个整型数组里除了两个数之外,其他数都出现了两次。找出这两个出现一次的数。
- wince 遍历文件夹,删除文件夹,及文件夹内文件
- C99布尔类型
- 高质量C/C++编译指南 学习笔记
- #define中的一种用法
- 解决hash冲突的方法
- 漫谈C++为什么不支持模板虚函数