STL array的介绍(1)

class template
<array>

std::array

template < class T, size_t N > class array;
Array class
Arrays are fixed-size sequence containers: they hold a specific number of elements ordered in a strict linear sequence.

array是固定大小的序列容器,array存储固定大小的元素在连续的精确的序列中。


Internally, an array does not keep any data other than the elements it contains (not even its size, which is a template parameter, fixed on compile time). It is as efficient in terms of storage size as an ordinary array declared with the language's bracket syntax ([]). This class merely adds a layer of member and global functions to it, so that arrays can be used as standard containers.

在内部,一个array除了它的元素之外不保存其他的任何数据(甚至是其大小,因为其大小是array的模板参数,在编译的时候就已经确定了)。这是一种和平常利用[]语法来声明的数组一样高效的容器,该类仅仅只是在普通数组上加了一些成员以及全局方法,使array可以被当成标准容器来使用。


Unlike the other standard containers, arrays have a fixed size and do not manage the allocation of its elements through an allocator: they are an aggregate type encapsulating a fixed-size array of elements. Therefore, they cannot be expanded or contracted dynamically (see vector for a similar container that can be expanded).

和其他标准容器不一样的是,array具有固定的大小以及当它的元素超过(限制的大小)时它不能通过内存分配器来继续重分配,它是一个固定大小数组元素的封装,因此,他们不能自动增长或者收缩(比如vector).


Zero-sized arrays are valid, but they should not be dereferenced (members frontback, and data).

大小为0的array是有效的,但是不应该被解除引用。(front,back,data方法).

例子:

#include <iostream>
#include <array>
using namespace std;
int main()
{
    array<int,0> ai;
    cout<<ai.front()<<endl;
    cout<<ai.back()<<endl;
    cout<<ai.data()<<endl;
}
运行截图:


可以看到,对其front,back得不到正确的值。


Unlike with the other containers in the Standard Library, swapping two array containers is a linear operation that involves swapping all the elements in the ranges individually, which generally is a considerably less efficient operation. On the other side, this allows the iterators to elements in both containers to keep their original container association.

和其他容器在标准库中的行为不同,交换两个array容器将分别交换两者的元素,这是一种线性操作,通常被认为是一种低效的行为。另一方面,这可以使原来的迭代器保持有效。

Another unique feature of array containers is that they can be treated as tuple objects: The <array> header overloads the get function to access the elements of the array as if it was a tuple, as well as specialized tuple_size and tuple_element types.

array容器另一个独有的特性是可以被当成一个元组对象看待,array头文件重载了get方法可以使其像元组一样访问其元素,同样被特化的还有tuple_size以及tuple_element


Container properties

Sequence
Elements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by their position in this sequence.
元素严格地顺序排列在序列中,可以通过位置访问序列中的元素。
Contiguous storage
The elements are stored in contiguous memory locations, allowing constant time random access to elements. Pointers to an element can be offset to access other elements.
元素一次存放在连续的内存单元中,允许在常量时间内随即访问元素,指针可以通过偏移来访问元素。
Fixed-size aggregate
The container uses implicit constructors and destructors to allocate the required space statically. Its size is compile-time constant. No memory or time overhead.
容器使用内置的constructor以及deconstructor来请求分配空间,其大小在编译时是一个常量,内存以及时间都不会超出。

Template parameters

T
Type of the elements contained.
Aliased as member type array::value_type.
N
Size of the array, in terms of number of elements.
In the reference for the array member functions, these same names are assumed for the template parameters.

Member types

The following aliases are member types of array. They are widely used as parameter and return types by member functions:

member typedefinitionnotes
value_typeThe first template parameter (T)
referencevalue_type&
const_referenceconst value_type&
pointervalue_type*
const_pointerconst value_type*
iteratorrandom access iterator to value_typeconvertible to const_iterator
const_iteratorrandom access iterator to const value_type
reverse_iteratorreverse_iterator<iterator>
const_reverse_iteratorreverse_iterator<const_iterator>
size_typesize_tunsigned integral type
difference_typeptrdiff_tsigned integral type

Member functions

Iterators

Capacity

Element access

Modifiers

Non-member function overloads


Non-member class specializations


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

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

转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双

2014-8-25

于GDUT


——————————————————————————————————————————————————————————————————————————-———




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值