std::array介绍
来源:互联网 发布:类似商务通的软件 编辑:程序博客网 时间:2024/06/05 22:56
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.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.
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).
Zero-sized arrays are valid, but they should not be dereferenced (members front, back, and data).
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.
Another unique feature of array containers is that they can be treated as tuple objects: The <array> header overloads theget function to access the elements of the array as if it was a tuple, as well as specialized tuple_size and tuple_elementtypes.
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.
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.
Member types
The following aliases are member types of array. They are widely used as parameter and return types by member functions:Member functions
Iterators
- begin
- Return iterator to beginning (public member function )
- end
- Return iterator to end (public member function )
- rbegin
- Return reverse iterator to reverse beginning (public member function )
- rend
- Return reverse iterator to reverse end (public member function )
- cbegin
- Return const_iterator to beginning (public member function )
- cend
- Return const_iterator to end (public member function )
- crbegin
- Return const_reverse_iterator to reverse beginning (public member function )
- crend
- Return const_reverse_iterator to reverse end (public member function )
Capacity
- size
- Return size (public member function )
- max_size
- Return maximum size (public member function )
- empty
- Test whether array is empty (public member function )
Element access
- operator[]
- Access element (public member function )
- at
- Access element (public member function )
- front
- Access first element (public member function )
- back
- Access last element (public member function )
- data
- Get pointer to data (public member function )
Modifiers
- fill
- Fill array with value (public member function )
- swap
- Swap content (public member function )
Non-member function overloads
- get (array)
- Get element (tuple interface) (function template )
- relational operators (array)
- Relational operators for array (function template )
Non-member class specializations
- tuple_element<array>
- Tuple element type for array (class template specialization )
- tuple_size<array>
- Tuple size traits for array (class template specialization )
0 0
- std::array介绍
- std::array
- std::array 学习速记
- std::vector介绍
- std::vector介绍
- std::vector介绍
- std::stringstream 的介绍
- std::vector介绍
- std::vector介绍
- std::vector介绍 .
- std::vector介绍
- std::vector介绍
- std::vector介绍 .
- std::vector介绍
- std::vector介绍
- std::vector介绍
- std::vector介绍
- std::vector介绍
- ubuntu cuda
- PG数据库获取系统时间函数
- 好吧,虽然我很渣,但是我想做出自己的东西
- RIAD级别选择与IOPS计算
- 利用WPS将office文档转换成PDF(一)
- std::array介绍
- 【OpenCV入门教程之二】 一览众山小:OpenCV 2.4.8 or OpenCV 2.4.9组件结构全解析
- 股票和债券的区别
- myeclipse :Java.lang.UnsupportedClassVersionError:
- 将数据实体转换成字典集合
- 正则表达式和string对象的正则表达式
- 高德地图坐标转换问题
- OC中的block的用法总结
- angular表格带筛选分页,本地json