Chinaunix首页 | 论坛 | 博客
  • 博客访问: 356564
  • 博文数量: 78
  • 博客积分: 2222
  • 博客等级: 大尉
  • 技术积分: 745
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-24 10:48
文章分类

全部博文(78)

文章存档

2012年(7)

2011年(33)

2010年(38)

分类: C/C++

2010-10-21 18:57:14

hash_map不是C++标准库的一部分,但因其重要性很多库(sgi stlboost)实现了hash_map,包括g++编译器所带的头文件也包含了hash_map的实现代码(其实现为sgi stl的版本),其在include/ext目录下,该目录还包含了hash_setrope等的实现。

// 文件/usr/include/c++/4.4.0/ext/hash_map

_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
 65 
 66 using std::equal_to;
 67 using std::allocator;
 68 using std::pair;
 69 using std::_Select1st;
 70 
 71 /**
 72 * This is an SGI extension.
 73 * @ingroup SGIextensions
 74 * @doctodo
 75 */

 76 template<class _Key, class _Tp, class _HashFn = hash<_Key>,
 77 class _EqualKey = equal_to<_Key>, class _Alloc = allocator<_Tp> >
 78 class hash_map


首先从上述头文件开始的部分可以发现,hash_map定义在__gnu_cxx命名空间中,故你必须在使用时限定名字空间__gnu_cxx::hash_map,或者使用using关键字,如下例:

#include <ext/hash_map>
using namespace __gnu_cxx;

int main()
{
    hash_map<int, string> hm;
    /* 其它使用hash_map的代码 */
}


STL其它头文件信息:

1.几乎所有的容器都在同名的头文件里,比如,vector中声明,list中声明等。例外的是声明了setmultiset声明了mapmultimap

2. 除了四个算法外,所有的算法都在中声明。例外的是accumulateinner_productadjacent_differencepartial_sum。这些算法在中声明。

3.特殊的迭代器,包括istream_iteratorsistreambuf_iterators,在中声明。

4.标准仿函数(比如less)和仿函数适配器(比如not1bind2nd)在中声明。

阅读(2277) | 评论(1) | 转发(4) |
给主人留下些什么吧!~~

aoyang8882011-09-13 17:43:23