Changes For Bug 352
[oota-llvm.git] / include / llvm / ADT / HashExtras.h
1 //===-- llvm/ADT/HashExtras.h - Useful functions for STL hash ---*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains some templates that are useful if you are working with the
11 // STL Hashed containers.
12 //
13 // No library is required when using these functinons.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_ADT_HASHEXTRAS_H
18 #define LLVM_ADT_HASHEXTRAS_H
19
20 #include "llvm/ADT/hash_map"
21 #include <string>
22
23 // Cannot specialize hash template from outside of the std namespace.
24 namespace HASH_NAMESPACE {
25
26 template <> struct hash<std::string> {
27   size_t operator()(std::string const &str) const {
28     return hash<char const *>()(str.c_str());
29   }
30 };
31
32 // Provide a hash function for arbitrary pointers...
33 template <class T> struct hash<T *> {
34   inline size_t operator()(const T *Val) const {
35     return reinterpret_cast<size_t>(Val);
36   }
37 };
38
39 }  // End namespace std
40
41 #endif