Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Hash Function Objects.

#include <boost/tr1/functional.hpp>

or

#include <functional>

Class template std::hash is a unary-functor that converts some type T into a hash-value, specializations of std::hash are provided for integer, character, floating point, and pointer types, plus the two string types std::string and std::wstring. See the Boost.Hash documentation for more information.

namespace std {
namespace tr1 {

template <class T>
struct hash : public unary_function<T, size_t>
{
   size_t operator()(T val)const;
};

// Hash function specializations
template <> struct hash<bool>;
template <> struct hash<char>;
template <> struct hash<signed char>;
template <> struct hash<unsigned char>;
template <> struct hash<wchar_t>;
template <> struct hash<short>;
template <> struct hash<int>;
template <> struct hash<long>;
template <> struct hash<unsigned short>;
template <> struct hash<unsigned int>;
template <> struct hash<unsigned long>;
template <> struct hash<float>;
template <> struct hash<double>;
template <> struct hash<long double>;
template<class T> struct hash<T*>;
template <> struct hash<std::string>;
template <> struct hash<std::wstring>;

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_HASH if your standard library implements this part of TR1.

Standard Conformity: Boost.Hash adds specialisations of std::hash for a wider range of types than those required by TR1: Boost.Hash acts as a testbed for issue 6.18 in the Library Extension Technical Report Issues List.

[Note] Note

There are portability issues with this template - in particular the hash template might not actually be defined inside namespace std::tr1, making user-defined specializations of the template non-portable. For example Visual C++ 2010 defines hash in namespace std and then imports this into std::tr1 with a using declaration.


PrevUpHomeNext