STL array的begin方法(4)

原文地址:http://www.cplusplus.com/reference/array/array/begin/
public member function
<array>

std::array::begin

      iterator begin() noexcept;
const_iterator begin() const noexcept;
Return iterator to beginning
Returns an iterator pointing to the first element in the array container.

返回一个指向array容器第一个元素的iterator.


Notice that, unlike member array::front, which returns a reference to the first element, this function returns a random access iterator pointing to it.

注意和array::front不同,front是返回一个指向第一个元素的引用,这个函数是返回一个指向第一个元素的随机访问迭代器。


In zero-sized arrays, this function returns the same as array::end, but the returned iterator should not be dereferenced.

如果array大小为0,该函数的返回值和end是一样的,但是他们都不应该被解除引用。

例子:

#include <iostream>
#include <array>
using namespace std;
void end1(){
    array<double,0> ad;
    auto ib=ad.begin();
    cout<<"ad.begin()="<<*ib<<endl;
}
运行结果:



Parameters

none

Return Value

An iterator to the beginning of the sequence.

返回一个指向第一个元素的迭代器。


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

如果array对象是const属性,那么返回一个const_itertor,否则,返回一个普通的iterator.


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

iterator和const_iterator都是随机访问迭代器。

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// array::begin example
#include <iostream>
#include <array>

int main ()
{
  std::array<int,5> myarray = { 2, 16, 77, 34, 50 };

  std::cout << "myarray contains:";
  for ( auto it = myarray.begin(); it != myarray.end(); ++it )
    std::cout << ' ' << *it;
  std::cout << '\n';

  return 0;
}


Output:
myarray contains: 2 16 77 34 50

Complexity

Constant.

Iterator validity

No changes.

Data races

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
author:天下无双

2014-8-26

于GDUT


——————————————————————————————————————————————————————————————————





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值