1 //===-- llvm/ADT/HashExtras.h - Useful functions for STL hash ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains some templates that are useful if you are working with the
11 // STL Hashed containers.
13 // No library is required when using these functions.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_ADT_HASHEXTRAS_H
18 #define LLVM_ADT_HASHEXTRAS_H
22 // Cannot specialize hash template from outside of the std namespace.
23 namespace HASH_NAMESPACE {
25 // Provide a hash function for arbitrary pointers...
26 template <class T> struct hash<T *> {
27 inline size_t operator()(const T *Val) const {
28 return reinterpret_cast<size_t>(Val);
32 template <> struct hash<std::string> {
33 size_t operator()(std::string const &str) const {
34 return hash<char const *>()(str.c_str());
38 } // End namespace std