1 //===-- HashExtras.h - Useful functions for STL hash containers -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
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 functinons.
15 //===----------------------------------------------------------------------===//
17 #ifndef SUPPORT_HASHEXTRAS_H
18 #define SUPPORT_HASHEXTRAS_H
20 #include "Support/hash_map"
23 // Cannot specialize hash template from outside of the std namespace.
24 namespace HASH_NAMESPACE {
26 template <> struct hash<std::string> {
27 size_t operator()(std::string const &str) const {
28 return hash<char const *>()(str.c_str());
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);
39 } // End namespace std