Chris Lattner | 57dbb3a | 2001-07-23 17:46:59 +0000 | [diff] [blame] | 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 LLVM_SUPPORT_HASHEXTRAS_H |
| 11 | #define LLVM_SUPPORT_HASHEXTRAS_H |
| 12 | |
| 13 | #include <string> |
| 14 | #include <hash_map> |
| 15 | |
| 16 | template <> struct hash<string> { |
| 17 | size_t operator()(string const &str) const { |
| 18 | return hash<char const *>()(str.c_str()); |
| 19 | } |
| 20 | }; |
| 21 | |
Vikram S. Adve | bf2b7e8 | 2001-07-28 04:41:10 +0000 | [diff] [blame] | 22 | // Provide a hash function for arbitrary pointers... |
| 23 | template <class T> struct hash<T *> { |
| 24 | inline size_t operator()(const T *Val) const { return (size_t)Val; } |
| 25 | }; |
| 26 | |
Chris Lattner | 57dbb3a | 2001-07-23 17:46:59 +0000 | [diff] [blame] | 27 | #endif |