f648a28c099c58e38934c6b5edd27479cefea653
[oota-llvm.git] / include / Support / HashExtras.h
1 //===-- HashExtras.h - Useful functions for STL hash containers -*- C++ -*-===//
2 //
3 // This file contains some templates that are useful if you are working with the
4 // STL Hashed containers.
5 //
6 // No library is required when using these functinons.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef SUPPORT_HASHEXTRAS_H
11 #define SUPPORT_HASHEXTRAS_H
12
13 #include "Support/hash_map"
14 #include <string>
15
16 // Cannot specialize hash template from outside of the std namespace.
17 namespace HASH_NAMESPACE {
18
19 template <> struct hash<std::string> {
20   size_t operator()(std::string const &str) const {
21     return hash<char const *>()(str.c_str());
22   }
23 };
24
25 // Provide a hash function for arbitrary pointers...
26 template <class T> struct hash<T *> {
27   inline size_t operator()(const T *Val) const { return (size_t)Val; }
28 };
29
30 }  // End namespace std
31
32 #endif