📅  最后修改于: 2020-12-15 04:29:04             🧑  作者: Mango
数组是固定大小的序列容器。容器是保存相同类型数据的对象。顺序容器严格按线性顺序存储元素。
容器类使用隐式构造函数静态地分配所需的内存。内存是在编译时分配的,因此数组大小无法在运行时缩小或扩展。数组中的所有元素都位于连续的内存位置。
以下是
template < class T, size_t N >
class array;
T-所包含元素的类型。
T可以用任何其他数据类型(包括用户定义的类型)代替。
N-数组的大小。
零大小的数组也是有效的。在这种情况下,array.begin()和array.end()指向同一位置。但是调用front()或back()的行为是不确定的。
成员函数可以将以下成员类型用作参数或返回类型。
Sr.No. | Member types | Definition |
---|---|---|
1 | value_type | T (First parameter of the template) |
2 | reference | value_type& |
3 | const_reference | const value_type& |
4 | pointer | value_type* |
5 | const_pointer | const value_type* |
6 | iterator | a random access iterator to value_type |
7 | const_iterator | a random access iterator to const value_type |
8 | reverse_iterator | std::reverse_iterator |
9 | const_reverse_iterator | std::reverse_iterator |
10 | size_type | size_t |
11 | difference_type | ptrdiff_t |
以下是
Sr.No. | Method & Description |
---|---|
1 | array::at
Returns a reference to the element present at location N in given array container. |
2 | array::back
Returns a reference to the last element of the array container. |
3 | array::begin
Returns an iterator which points to the start of the array. |
4 | array::cbegin
Returns a constant iterator which points to the start of the array. |
5 | array::cend
Returns a constant iterator which points to the past-end element of array. |
6 | array::crbegin
Returns a constant reverse iterator pointing to the last element of the array. |
7 | array::crend
Returns a constant reverse iterator which points to the past-end. |
8 | array::data
Return a pointer pointing to the first element of the array container. |
9 | array::empty
Tests whether size of array is zero or not. |
10 | array::end
Returns an iterator which points to the past-end element of array. |
11 | array::fill
Sets given value to all elements of array. |
12 | array::front
Returns a reference to the first element of the array container. |
13 | array::max_size
Returns the maximum number of elements that can be held by array container. |
14 | array::operator[]
Returns a reference to the element present at location N in a given array container. |
15 | array::rbegin
Returns a reverse iterator pointing to the last element of the array. |
16 | array::rend
Returns a reverse iterator which points to the theoretical element preceding to first element of the array. |
17 | array::size
Returns the number of elements present in the array. |
18 | array::swap
Swap the contents of the two array. |
Sr.No. | Method & Description |
---|---|
1 | get(array)
Returns reference to the Ith element of the array container. |
2 | bool operator==
Tests whether two containers are identical or not |
3 | bool operator!=
Tests whether two containers are identical or not |
4 | bool operator<
Tests whether first array container is less than second or not. |
5 | bool operator<=
Tests whether first array container is less than or equal to second or not. |
6 | bool operator>
Tests whether first array container is greater than second or not. |
7 | bool operator>=
Tests whether first array container is greater than or equal to second or not. |
Sr.No. | Method & Description |
---|---|
1 | tuple_element(array)
Provides compile-type indexed access to the type of the elements of the array using tuple-like interface. |
2 | tuple_size(array)
Returns the total number of elements present in the container. |