LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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 template <> struct hash<std::string> {
00027   size_t operator()(std::string const &str) const {
00028     return hash<char const *>()(str.c_str());
00029   }
00030 };
00031 
00032 // Provide a hash function for arbitrary pointers...
00033 template <class T> struct hash<T *> {
00034   inline size_t operator()(const T *Val) const {
00035     return reinterpret_cast<size_t>(Val);
00036   }
00037 };
00038 
00039 }  // End namespace std
00040 
00041 #endif