LLVM API Documentation

HashExtras.h

Go to the documentation of this file.
00001 //===-- llvm/ADT/HashExtras.h - Useful functions for STL hash ---*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains some templates that are useful if you are working with the
00011 // STL Hashed containers.
00012 //
00013 // No library is required when using these functinons.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef LLVM_ADT_HASHEXTRAS_H
00018 #define LLVM_ADT_HASHEXTRAS_H
00019 
00020 #include "llvm/ADT/hash_map"
00021 #include <string>
00022 
00023 // Cannot specialize hash template from outside of the std namespace.
00024 namespace HASH_NAMESPACE {
00025 
00026 // Provide a hash function for arbitrary pointers...
00027 template <class T> struct hash<T *> {
00028   inline size_t operator()(const T *Val) const {
00029     return reinterpret_cast<size_t>(Val);
00030   }
00031 };
00032 
00033 template <> struct hash<std::string> {
00034   size_t operator()(std::string const &str) const {
00035     return hash<char const *>()(str.c_str());
00036   }
00037 };
00038 
00039 }  // End namespace std
00040 
00041 #endif