Don't attribute in file headers anymore. See llvmdev for the
[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 is distributed under the University of Illinois Open Source
6 // 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 // Provide a hash function for arbitrary pointers...
27 template <class T> struct hash<T *> {
28   inline size_t operator()(const T *Val) const {
29     return reinterpret_cast<size_t>(Val);
30   }
31 };
32
33 template <> struct hash<std::string> {
34   size_t operator()(std::string const &str) const {
35     return hash<char const *>()(str.c_str());
36   }
37 };
38
39 }  // End namespace std
40
41 #endif