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 is distributed under the University of Illinois Open Source
00006 // 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 functions.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef LLVM_ADT_HASHEXTRAS_H
00018 #define LLVM_ADT_HASHEXTRAS_H
00019 
00020 #include <string>
00021 
00022 // Cannot specialize hash template from outside of the std namespace.
00023 namespace HASH_NAMESPACE {
00024 
00025 // Provide a hash function for arbitrary pointers...
00026 template <class T> struct hash<T *> {
00027   inline size_t operator()(const T *Val) const {
00028     return reinterpret_cast<size_t>(Val);
00029   }
00030 };
00031 
00032 template <> struct hash<std::string> {
00033   size_t operator()(std::string const &str) const {
00034     return hash<char const *>()(str.c_str());
00035   }
00036 };
00037 
00038 }  // End namespace std
00039 
00040 #endif