读书人

STL学习之map器皿(0)

发布时间: 2012-06-23 14:52:43 作者: rapoo

STL学习之map容器(0)
map

Map是一系列有一个键值(key)和映射值(value)组合的存储元素关联容器。

在一个map中,key值是唯一的确定一个元素,而映射值(value)是这个key相关的值的某个排序。键的类型和值的类型是不同的,例如,map的一个典型的实例----电话簿索引是以姓名作为key,以电话号码作为value的。

本质上,map中的元素是从低到高的键值排序伴随着一个设置在构造函数中严格的弱排序的标准。

作为关联容器,他们特别设计了通过键值快速访问(不像通过相关联或者相对位置快速访问的顺序容器)。

因此,下面是map作为关联容器的几个主要特征:

唯一的键值:在map容器中,每个键值都是唯一的。每一个元素都是有键和值组成。元素值即为其键的简单的关联容器,需要看一下set关联容器。元素始终保持着严格的弱排序。

map中的键唯致使此关联容器可以直接执行访问操作(operator[]),此访问操作允许访问值。

在c++标准模板库的说明文档中,map容器有四个模板参数:

成员函数

迭代器:

容器(Capacity:

元素访问:

修改容器操作:

观察者(Observers:

操作:

分配器:

成员类型of template <class Key, class T, class Compare=less<Key>, class Allocator=allocator<pair <const Key, T> > > class map;
member typedefinitionkey_typeKeymapped_typeTvalue_typepair<const Key,T>key_compareComparevalue_compareNested class to compare elements (see member function value_comp)allocator_typeAllocatorreferenceAllocator::referenceconst_referenceAllocator::const_referenceiteratorBidirectional iteratorconst_iteratorConstant bidirectional iteratorsize_typeUnsigned integral type (usually same as size_t)difference_typeSigned integral type (usually same as ptrdiff_t)pointerAllocator::pointerconst_pointerAllocator::const_pointerreverse_iteratorreverse_iterator<iterator>const_reverse_iteratorreverse_iterator<const_iterator>

读书人网 >编程

热点推荐