| Home | Libraries | People | FAQ | More

## Function hash_value

boost::hash_value — Implementation of the hash function.

## Synopsis

    std::size_t hash_value(int val);
    std::size_t hash_value(unsigned int val);
    std::size_t hash_value(long val);
    std::size_t hash_value(unsigned long val);
    std::size_t hash_value(float val);
    std::size_t hash_value(double val);
    std::size_t hash_value(long double val);
    template<typename T> std::size_t hash_value(T* const& val);
    template<typename T, unsigned N> std::size_t hash_value(T (&val)[N]);
    template<typename T, unsigned N> std::size_t hash_value(const T (&val)[N]);
    template<typename Ch, typename A>
      std::size_t hash_value(std::basic_string<Ch, std::char_traits<Ch>, A> const& val);
    template<typename A, typename B>
      std::size_t hash_value(std::pair<A, B> const& val);
    template<typename T, typename A>
      std::size_t hash_value(std::vector<T, A> const& val);
    template<typename T, typename A>
      std::size_t hash_value(std::list<T, A> const& val);
    template<typename T, typename A>
      std::size_t hash_value(std::deque<T, A> const& val);
    template<typename K, typename C, typename A>
      std::size_t hash_value(std::set<K, C, A> const& val);
    template<typename K, typename C, typename A>
      std::size_t hash_value(std::multiset<K, C, A> const& val);
    template<typename K, typename T, typename C, typename A>
      std::size_t hash_value(std::map<K, T, C, A> const& val);
    template<typename K, typename T, typename C, typename A>
      std::size_t hash_value(std::multimap<K, T, C, A> const& val);

## Description

Generally shouldn't be called directly by users, instead they should use `boost::hash`, `boost::hash_range` or `boost::hash_combine` which call `hash_value` without namespace qualification so that overloads for custom types are found via ADL.

Notes: | This is an extension to TR1
Throws: | Only throws if a user supplied version of `hash_value` throws for an element of a container, or one of the types stored in a pair.

Returns:

Types | Returns
--- | ---
`int`, `unsigned int`, `long`, `unsigned long` | `val`
`float`, `double`, `long double` | An unspecified value, except that equal arguments shall yield the same result.
`T*` | An unspecified value, except that equal arguments shall yield the same result.
`T val[N]`, `const T val[N]` | `hash_range(val, val+N)`
`std:basic_string<Ch, std::char_traits<Ch>, A>`, `std::vector<T, A>`, `std::list<T, A>`, `std::deque<T, A>`, `std::set<K, C, A>`, `std::multiset<K, C, A>`, `std::map<K, T, C, A>`, `std::multimap<K, T, C, A>` | `hash_range(val.begin(), val.end())`

`std::pair<A, B>`

    size_t seed = 0;
    hash_combine(seed, val.first);
    hash_combine(seed, val.second);
    return seed;

| Copyright © 2005, 2006 Daniel James