[DEV] add v1.76.0

This commit is contained in:
2021-10-05 21:37:46 +02:00
parent a97e9ae7d4
commit d0115b733d
45133 changed files with 4744437 additions and 1026325 deletions

View File

@@ -0,0 +1,70 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Acknowledgements</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../hash.html" title="Chapter 10. Boost.ContainerHash">
<link rel="prev" href="links.html" title="Links">
<link rel="next" href="../conversion.html" title="Chapter 11. The Conversion Library 1.7">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="links.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../conversion.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="hash.acknowledgements"></a><a class="link" href="acknowledgements.html" title="Acknowledgements">Acknowledgements</a>
</h2></div></div></div>
<p>
This library is based on the design by Peter Dimov. During the initial development
Joaquín M López Muñoz made many useful suggestions and contributed fixes.
</p>
<p>
The formal review was managed by Thorsten Ottosen, and the library reviewed
by: David Abrahams, Alberto Barbati, Topher Cooper, Caleb Epstein, Dave Harris,
Chris Jefferson, Bronek Kozicki, John Maddock, Tobias Swinger, Jaap Suter,
Rob Stewart and Pavel Vozenilek. Since then, further constructive criticism
has been made by Daniel Krügler, Alexander Nasonov and 沈慧峰.
</p>
<p>
The implementation of the hash function for pointers is based on suggestions
made by Alberto Barbati and Dave Harris. Dave Harris also suggested an important
improvement to <code class="computeroutput"><a class="link" href="reference.html#boost.hash_combine">boost::hash_combine</a></code>
that was taken up.
</p>
<p>
Some useful improvements to the floating point hash algorithm were suggested
by Daniel Krügler.
</p>
<p>
The original implementation came from Jeremy B. Maitin-Shepard's hash table
library, although this is a complete rewrite.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2005-2008 Daniel
James<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="links.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../conversion.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

495
doc/html/hash/changes.html Normal file
View File

@@ -0,0 +1,495 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Change Log</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../hash.html" title="Chapter 10. Boost.ContainerHash">
<link rel="prev" href="disable.html" title="Disabling The Extensions">
<link rel="next" href="rationale.html" title="Rationale">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="disable.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="rationale.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="hash.changes"></a><a class="link" href="changes.html" title="Change Log">Change Log</a>
</h2></div></div></div>
<h3>
<a name="hash.changes.h0"></a>
<span class="phrase"><a name="hash.changes.boost_1_33_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_33_0">Boost
1.33.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Initial Release
</li></ul></div>
<h3>
<a name="hash.changes.h1"></a>
<span class="phrase"><a name="hash.changes.boost_1_33_1"></a></span><a class="link" href="changes.html#hash.changes.boost_1_33_1">Boost
1.33.1</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Fixed the points example, as pointed out by 沈慧峰.
</li></ul></div>
<h3>
<a name="hash.changes.h2"></a>
<span class="phrase"><a name="hash.changes.boost_1_34_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_34_0">Boost
1.34.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Use declarations for standard classes, so that the library doesn't need
to include all of their headers
</li>
<li class="listitem">
Deprecated the <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">functional</span><span class="special">/</span><span class="identifier">hash</span><span class="comment">/*.hpp&gt;</span></code> headers. Now a single header,
&lt;<code class="computeroutput">boost/functional/hash.hpp</code>&gt;
is used.
</li>
<li class="listitem">
Add support for the <code class="computeroutput"><span class="identifier">BOOST_HASH_NO_EXTENSIONS</span></code>
macro, which disables the extensions to TR1.
</li>
<li class="listitem">
Minor improvements to the hash functions for floating point numbers.
</li>
<li class="listitem">
Update the portable example to hopefully be more generally portable.
</li>
</ul></div>
<h3>
<a name="hash.changes.h3"></a>
<span class="phrase"><a name="hash.changes.boost_1_34_1"></a></span><a class="link" href="changes.html#hash.changes.boost_1_34_1">Boost
1.34.1</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/952" target="_top">Ticket 952</a>:
Suppress incorrect 64-bit warning on Visual C++.
</li></ul></div>
<h3>
<a name="hash.changes.h4"></a>
<span class="phrase"><a name="hash.changes.boost_1_35_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_35_0">Boost
1.35.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Support for <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">long</span></code>,
<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">complex</span></code>.
</li>
<li class="listitem">
Improved algorithm for hashing floating point numbers:
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
Improved portablity, as described by Daniel Krügler in <a href="http://lists.boost.org/boost-users/2005/08/13418.php" target="_top">a
post to the boost users list</a>.
</li>
<li class="listitem">
Fits more information into each combine loop, which can reduce the
the number of times combine is called and hopefully give a better
quality hash function.
</li>
<li class="listitem">
Improved the algorithm for hashing floating point numbers.
</li>
<li class="listitem">
On Cygwin use a binary hash function for floating point numbers,
as Cygwin doesn't have decent floating point functions for <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code>.
</li>
<li class="listitem">
Never uses <code class="computeroutput"><span class="identifier">fpclass</span></code>
which doesn't support <code class="computeroutput"><span class="keyword">long</span>
<span class="keyword">double</span></code>.
</li>
<li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/1064" target="_top">Ticket 1064</a>:
Removed unnecessary use of <code class="computeroutput"><span class="identifier">errno</span></code>.
</li>
</ul></div>
</li>
<li class="listitem">
Explicitly overload for more built in types.
</li>
<li class="listitem">
Minor improvements to the documentation.
</li>
<li class="listitem">
A few bug and warning fixes:
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/1509" target="_top">Ticket 1509</a>:
Suppress another Visual C++ warning.
</li>
<li class="listitem">
Some workarounds for the Sun compilers.
</li>
</ul></div>
</li>
</ul></div>
<h3>
<a name="hash.changes.h5"></a>
<span class="phrase"><a name="hash.changes.boost_1_36_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_36_0">Boost
1.36.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Stop using OpenBSD's dodgy <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code>.
</li>
<li class="listitem">
Using the boost typedefs for <code class="computeroutput"><span class="keyword">long</span>
<span class="keyword">long</span></code> and <code class="computeroutput"><span class="keyword">unsigned</span>
<span class="keyword">long</span> <span class="keyword">long</span></code>.
</li>
<li class="listitem">
Move the extensions into their own header.
</li>
</ul></div>
<h3>
<a name="hash.changes.h6"></a>
<span class="phrase"><a name="hash.changes.boost_1_37_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_37_0">Boost
1.37.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/2264" target="_top">Ticket 2264</a>:
In Visual C++, always use C99 float functions for <code class="computeroutput"><span class="keyword">long</span>
<span class="keyword">double</span></code> and <code class="computeroutput"><span class="keyword">float</span></code>
as the C++ overloads aren't always availables.
</li></ul></div>
<h3>
<a name="hash.changes.h7"></a>
<span class="phrase"><a name="hash.changes.boost_1_38_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_38_0">Boost
1.38.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Changed the warnings in the deprecated headers from 1.34.0 to errors. These
will be removed in a future version of Boost.
</li>
<li class="listitem">
Moved detail headers out of <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">container_hash</span><span class="special">/</span><span class="identifier">detail</span></code>,
since they are part of functional/hash, not container_hash. <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">container_hash</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">container_fwd</span><span class="special">.</span><span class="identifier">hpp</span></code> has been moved to <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">container_fwd</span><span class="special">.</span><span class="identifier">hpp</span></code>
as it's used outside of this library, the others have been moved to <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">functional</span><span class="special">/</span><span class="identifier">hash</span><span class="special">/</span><span class="identifier">detail</span></code>.
</li>
</ul></div>
<h3>
<a name="hash.changes.h8"></a>
<span class="phrase"><a name="hash.changes.boost_1_39_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_39_0">Boost
1.39.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Move the hash_fwd.hpp implementation into the hash subdirectory, leaving
a forwarding header in the old location. You should still use the old location,
the new location is mainly for implementation and possible modularization.
</li>
<li class="listitem">
<a href="https://svn.boost.org/trac/boost/ticket/2412" target="_top">Ticket 2412</a>:
Removed deprecated headers.
</li>
<li class="listitem">
<a href="https://svn.boost.org/trac/boost/ticket/2957" target="_top">Ticket 2957</a>:
Fix configuration for vxworks.
</li>
</ul></div>
<h3>
<a name="hash.changes.h9"></a>
<span class="phrase"><a name="hash.changes.boost_1_40_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_40_0">Boost
1.40.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Automatically configure the float functions using template metaprogramming
instead of trying to configure every possibility manually.
</li>
<li class="listitem">
Workaround for when STLport doesn't support long double.
</li>
</ul></div>
<h3>
<a name="hash.changes.h10"></a>
<span class="phrase"><a name="hash.changes.boost_1_42_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_42_0">Boost
1.42.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Reduce the number of warnings for Visual C++ warning level 4.
</li>
<li class="listitem">
Some code formatting changes to fit lines into 80 characters.
</li>
<li class="listitem">
Rename an internal namespace.
</li>
</ul></div>
<h3>
<a name="hash.changes.h11"></a>
<span class="phrase"><a name="hash.changes.boost_1_43_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_43_0">Boost
1.43.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="https://svn.boost.org/trac/boost/ticket/3866" target="_top">Ticket 3866</a>:
Don't foward declare containers when using gcc's parallel library, allow
user to stop forward declaration by defining the <code class="computeroutput"><span class="identifier">BOOST_DETAIL_NO_CONTAINER_FWD</span></code>
macro.
</li>
<li class="listitem">
<a href="https://svn.boost.org/trac/boost/ticket/4038" target="_top">Ticket 4038</a>:
Avoid hashing 0.5 and 0 to the same number.
</li>
<li class="listitem">
Stop using deprecated <code class="computeroutput"><span class="identifier">BOOST_HAS_</span><span class="special">*</span></code> macros.
</li>
</ul></div>
<h3>
<a name="hash.changes.h12"></a>
<span class="phrase"><a name="hash.changes.boost_1_44_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_44_0">Boost
1.44.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Add option to prevent implicit conversions when calling <code class="computeroutput"><span class="identifier">hash_value</span></code>
by defining <code class="computeroutput"><span class="identifier">BOOST_HASH_NO_IMPLICIT_CASTS</span></code>.
When using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">hash</span></code> for a type that does not have <code class="computeroutput"><span class="identifier">hash_value</span></code> declared but does have an
implicit conversion to a type that does, it would use that implicit conversion
to hash it. Which can sometimes go very wrong, e.g. using a conversion
to bool and only hashing to 2 possible values. Since fixing this is a breaking
change and was only approached quite late in the release cycle with little
discussion it's opt-in for now. This, or something like it, will become
the default in a future version.
</li></ul></div>
<h3>
<a name="hash.changes.h13"></a>
<span class="phrase"><a name="hash.changes.boost_1_46_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_46_0">Boost
1.46.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Avoid warning due with gcc's <code class="computeroutput"><span class="special">-</span><span class="identifier">Wconversion</span></code> flag.
</li></ul></div>
<h3>
<a name="hash.changes.h14"></a>
<span class="phrase"><a name="hash.changes.boost_1_50_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_50_0">Boost
1.50.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/6771" target="_top">Ticket 6771</a>:
Avoid gcc's <code class="computeroutput"><span class="special">-</span><span class="identifier">Wfloat</span><span class="special">-</span><span class="identifier">equal</span></code>
warning.
</li>
<li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/6806" target="_top">Ticket 6806</a>:
Support <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">array</span></code> and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span></code>
when available.
</li>
<li class="listitem">
Add deprecation warning to the long deprecated <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">container_hash</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">container_fwd</span><span class="special">.</span><span class="identifier">hpp</span></code>.
</li>
</ul></div>
<h3>
<a name="hash.changes.h15"></a>
<span class="phrase"><a name="hash.changes.boost_1_51_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_51_0">Boost
1.51.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Support the standard smart pointers.
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">hash_value</span></code> now implemented
using SFINAE to avoid implicit casts to built in types when calling it.
</li>
<li class="listitem">
Updated to use the new config macros.
</li>
</ul></div>
<h3>
<a name="hash.changes.h16"></a>
<span class="phrase"><a name="hash.changes.boost_1_52_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_52_0">Boost
1.52.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Restore <code class="computeroutput"><span class="keyword">enum</span></code> support, which
was accidentally removed in the last version.
</li>
<li class="listitem">
New floating point hasher - will hash the binary representation on more
platforms, which should be faster.
</li>
</ul></div>
<h3>
<a name="hash.changes.h17"></a>
<span class="phrase"><a name="hash.changes.boost_1_53_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_53_0">Boost
1.53.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Add support for <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">int128_type</span></code> and <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint128_type</span></code>
where available - currently only <code class="computeroutput"><span class="identifier">__int128</span></code>
and <code class="computeroutput"><span class="keyword">unsigned</span> <span class="identifier">__int128</span></code>
on some versions of gcc.
</li>
<li class="listitem">
On platforms that are known to have the standard floating point functions,
don't use automatic detection - which can break if there are ambiguous
overloads.
</li>
<li class="listitem">
Fix undefined behaviour when using the binary float hash (Thomas Heller).
</li>
</ul></div>
<h3>
<a name="hash.changes.h18"></a>
<span class="phrase"><a name="hash.changes.boost_1_54_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_54_0">Boost
1.54.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<a href="https://svn.boost.org/trac/boost/ticket/7957" target="_top">Ticket 7957</a>:
Fixed a typo.
</li></ul></div>
<h3>
<a name="hash.changes.h19"></a>
<span class="phrase"><a name="hash.changes.boost_1_55_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_55_0">Boost
1.55.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Simplify a SFINAE check so that it will hopefully work on Sun 5.9 (<a href="https://svn.boost.org/trac/boost/ticket/8822" target="_top">#8822</a>).
</li>
<li class="listitem">
Suppress Visual C++ infinite loop warning (<a href="https://svn.boost.org/trac/boost/ticket/8568" target="_top">#8568</a>).
</li>
</ul></div>
<h3>
<a name="hash.changes.h20"></a>
<span class="phrase"><a name="hash.changes.boost_1_56_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_56_0">Boost
1.56.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Removed some Visual C++ 6 workarounds.
</li>
<li class="listitem">
Ongoing work on improving <code class="computeroutput"><span class="identifier">hash_combine</span></code>.
This changes the combine function which was previously defined in the reference
documentation.
</li>
</ul></div>
<h3>
<a name="hash.changes.h21"></a>
<span class="phrase"><a name="hash.changes.boost_1_58_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_58_0">Boost
1.58.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Fixed strict aliasing violation (<a href="https://github.com/boostorg/container_hash/pull/3" target="_top">GitHub
#3</a>).
</li></ul></div>
<h3>
<a name="hash.changes.h22"></a>
<span class="phrase"><a name="hash.changes.boost_1_63_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_63_0">Boost
1.63.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Fixed some warnings.
</li>
<li class="listitem">
Only define hash for <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">wstring</span></code>
when we know we have a <code class="computeroutput"><span class="keyword">wchar_t</span></code>.
Otherwise there's a compile error as there's no overload for hashing the
characters in wide strings (<a href="https://svn.boost.org/trac/boost/ticket/8552" target="_top">#8552</a>).
</li>
</ul></div>
<h3>
<a name="hash.changes.h23"></a>
<span class="phrase"><a name="hash.changes.boost_1_64_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_64_0">Boost
1.64.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Fix for recent versions of Visual C++ which have removed <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">unary_function</span></code> and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">binary_function</span></code>
(<a href="https://svn.boost.org/trac/boost/ticket/12353" target="_top">#12353</a>).
</li></ul></div>
<h3>
<a name="hash.changes.h24"></a>
<span class="phrase"><a name="hash.changes.boost_1_65_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_65_0">Boost
1.65.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Support for <code class="computeroutput"><span class="keyword">char16_t</span></code>, <code class="computeroutput"><span class="keyword">char32_t</span></code>, <code class="computeroutput"><span class="identifier">u16string</span></code>,
<code class="computeroutput"><span class="identifier">u32string</span></code>
</li></ul></div>
<h3>
<a name="hash.changes.h25"></a>
<span class="phrase"><a name="hash.changes.boost_1_66_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_66_0">Boost
1.66.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Avoid float comparison warning when using Clang - this workaround was already
in place for GCC, and was used when Clang pretends to be GCC, but the warning
was appearing when running Clang in other contexts.
</li></ul></div>
<h3>
<a name="hash.changes.h26"></a>
<span class="phrase"><a name="hash.changes.boost_1_67_0"></a></span><a class="link" href="changes.html#hash.changes.boost_1_67_0">Boost
1.67.0</a>
</h3>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Moved library into its own module, <code class="computeroutput"><span class="identifier">container_hash</span></code>.
</li>
<li class="listitem">
Moved headers for new module name, now at: <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">container_hash</span><span class="special">/</span><span class="identifier">hash</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>,
<code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">container_hash</span><span class="special">/</span><span class="identifier">hash_fwd</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>, <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">container_hash</span><span class="special">/</span><span class="identifier">extensions</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>.
</li>
<li class="listitem">
Added forwarding headers to support the old headers locations.
</li>
<li class="listitem">
Support <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string_view</span></code>, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">error_code</span></code>,
<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">error_condition</span></code> <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">optional</span></code>,
<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">variant</span></code>, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">monostate</span></code>
where available.
</li>
<li class="listitem">
Update include paths from other Boost libraries.
</li>
<li class="listitem">
Manually write out tuple overloads, rather than using the preprocessor
to generate them. Should improve usability, due to better error messages,
and easier debugging.
</li>
<li class="listitem">
Fix tutorial example (<a href="https://svn.boost.org/trac/boost/ticket/11017" target="_top">#11017</a>).
</li>
<li class="listitem">
Quick fix for hashing <code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span></code> when using libc++. Will try to introduce
a more general fix in the next release.
</li>
</ul></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2005-2008 Daniel
James<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="disable.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="rationale.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

142
doc/html/hash/combine.html Normal file
View File

@@ -0,0 +1,142 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Combining hash values</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../hash.html" title="Chapter 10. Boost.ContainerHash">
<link rel="prev" href="custom.html" title="Extending boost::hash for a custom data type">
<link rel="next" href="portability.html" title="Portability">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="custom.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="portability.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="hash.combine"></a><a class="link" href="combine.html" title="Combining hash values">Combining hash values</a>
</h2></div></div></div>
<p>
Say you have a point class, representing a two dimensional location:
</p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">point</span>
<span class="special">{</span>
<span class="keyword">int</span> <span class="identifier">x</span><span class="special">;</span>
<span class="keyword">int</span> <span class="identifier">y</span><span class="special">;</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">point</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">x</span><span class="special">(</span><span class="number">0</span><span class="special">),</span> <span class="identifier">y</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="special">{}</span>
<span class="identifier">point</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">x</span><span class="special">(</span><span class="identifier">x</span><span class="special">),</span> <span class="identifier">y</span><span class="special">(</span><span class="identifier">y</span><span class="special">)</span> <span class="special">{}</span>
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="identifier">point</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">other</span><span class="special">)</span> <span class="keyword">const</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">x</span> <span class="special">==</span> <span class="identifier">other</span><span class="special">.</span><span class="identifier">x</span> <span class="special">&amp;&amp;</span> <span class="identifier">y</span> <span class="special">==</span> <span class="identifier">other</span><span class="special">.</span><span class="identifier">y</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">};</span>
</pre>
<p>
and you wish to use it as the key for an <code class="computeroutput"><span class="identifier">unordered_map</span></code>.
You need to customise the hash for this structure. To do this we need to combine
the hash values for <code class="computeroutput"><span class="identifier">x</span></code> and
<code class="computeroutput"><span class="identifier">y</span></code>. The function <code class="computeroutput"><a class="link" href="reference.html#boost.hash_combine">boost::hash_combine</a></code> is supplied for
this purpose:
</p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">point</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">point</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">seed</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<code class="computeroutput"><a class="link" href="reference.html#boost.hash_combine">boost::hash_combine</a></code><span class="special">(</span><span class="identifier">seed</span><span class="special">,</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">x</span><span class="special">);</span>
<code class="computeroutput"><a class="link" href="reference.html#boost.hash_combine">boost::hash_combine</a></code><span class="special">(</span><span class="identifier">seed</span><span class="special">,</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">y</span><span class="special">);</span>
<span class="keyword">return</span> <span class="identifier">seed</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">...</span>
<span class="special">};</span>
</pre>
<p>
Calls to hash_combine incrementally build the hash from the different members
of point, it can be repeatedly called for any number of elements. It calls
<code class="computeroutput"><a class="link" href="reference.html#boost.hash_va_1_3_11_11_2_2_27_1">hash_value</a></code> on the supplied
element, and combines it with the seed.
</p>
<p>
Full code for this example is at <a href="../../../libs/container_hash/examples/point.cpp" target="_top">/libs/container_hash/examples/point.cpp</a>.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
When using <code class="computeroutput"><a class="link" href="reference.html#boost.hash_combine">boost::hash_combine</a></code>
the order of the calls matters. </p>
<pre class="programlisting">
std::size_t seed = 0;
boost::hash_combine(seed, 1);
boost::hash_combine(seed, 2);
</pre>
<p>
results in a different seed to:
</p>
<pre class="programlisting">
std::size_t seed = 0;
boost::hash_combine(seed, 2);
boost::hash_combine(seed, 1);
</pre>
<p>
If you are calculating a hash value for data
where the order of the data doesn't matter in comparisons (e.g. a set) you
will have to ensure that the data is always supplied in the same order.
</p>
</td></tr>
</table></div>
<p>
To calculate the hash of an iterator range you can use <code class="computeroutput"><a class="link" href="reference.html#boost.hash_range">boost::hash_range</a></code>:
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;</span> <span class="identifier">some_strings</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">hash</span> <span class="special">=</span> <code class="computeroutput"><a class="link" href="reference.html#boost.hash_range">boost::hash_range</a></code><span class="special">(</span><span class="identifier">some_strings</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">some_strings</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span>
</pre>
<p>
Note that when writing template classes, you might not want to include the
main hash header as it's quite an expensive include that brings in a lot of
other headers, so instead you can include the <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">container_hash</span><span class="special">/</span><span class="identifier">hash_fwd</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
header which forward declares <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>,
<code class="computeroutput"><a class="link" href="reference.html#boost.hash_range">boost::hash_range</a></code> and
<code class="computeroutput"><a class="link" href="reference.html#boost.hash_combine">boost::hash_combine</a></code>.
You'll need to include the main header before instantiating <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>.
When using a container that uses <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>
it should do that for you, so your type will work fine with the boost hash
containers. There's an example of this in <a href="../../../libs/container_hash/examples/template.hpp" target="_top">template.hpp</a>
and <a href="../../../libs/container_hash/examples/template.cpp" target="_top">template.cpp</a>.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2005-2008 Daniel
James<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="custom.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="portability.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

125
doc/html/hash/custom.html Normal file
View File

@@ -0,0 +1,125 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Extending boost::hash for a custom data type</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../hash.html" title="Chapter 10. Boost.ContainerHash">
<link rel="prev" href="tutorial.html" title="Tutorial">
<link rel="next" href="combine.html" title="Combining hash values">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="tutorial.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="combine.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="hash.custom"></a><a class="link" href="custom.html" title="Extending boost::hash for a custom data type">Extending boost::hash for a custom data type</a>
</h2></div></div></div>
<p>
<code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code> is implemented by calling
the function <code class="computeroutput"><a class="link" href="reference.html#boost.hash_va_1_3_11_11_2_2_27_1">hash_value</a></code>.
The namespace isn't specified so that it can detect overloads via argument
dependant lookup. So if there is a free function <code class="computeroutput"><span class="identifier">hash_value</span></code>
in the same namespace as a custom type, it will get called.
</p>
<p>
If you have a structure <code class="computeroutput"><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span></code>, where
each <code class="computeroutput"><span class="identifier">book</span></code> is uniquely defined
by it's member <code class="computeroutput"><span class="identifier">id</span></code>:
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">library</span>
<span class="special">{</span>
<span class="keyword">struct</span> <span class="identifier">book</span>
<span class="special">{</span>
<span class="keyword">int</span> <span class="identifier">id</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">author</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">title</span><span class="special">;</span>
<span class="comment">// ....</span>
<span class="special">};</span>
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="identifier">book</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">book</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">b</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">a</span><span class="special">.</span><span class="identifier">id</span> <span class="special">==</span> <span class="identifier">b</span><span class="special">.</span><span class="identifier">id</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">}</span>
</pre>
<p>
Then all you would need to do is write the function <code class="computeroutput"><span class="identifier">library</span><span class="special">::</span><span class="identifier">hash_value</span></code>:
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">library</span>
<span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">book</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">b</span><span class="special">)</span>
<span class="special">{</span>
<code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">hasher</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">hasher</span><span class="special">(</span><span class="identifier">b</span><span class="special">.</span><span class="identifier">id</span><span class="special">);</span>
<span class="special">}</span>
<span class="special">}</span>
</pre>
<p>
And you can now use <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code> with
book:
</p>
<pre class="programlisting"><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span> <span class="identifier">knife</span><span class="special">(</span><span class="number">3458</span><span class="special">,</span> <span class="string">"Zane Grey"</span><span class="special">,</span> <span class="string">"The Hash Knife Outfit"</span><span class="special">);</span>
<span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span> <span class="identifier">dandelion</span><span class="special">(</span><span class="number">1354</span><span class="special">,</span> <span class="string">"Paul J. Shanley"</span><span class="special">,</span>
<span class="string">"Hash &amp; Dandelion Greens"</span><span class="special">);</span>
<code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special">&lt;</span><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span><span class="special">&gt;</span> <span class="identifier">book_hasher</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">knife_hash_value</span> <span class="special">=</span> <span class="identifier">book_hasher</span><span class="special">(</span><span class="identifier">knife</span><span class="special">);</span>
<span class="comment">// If std::unordered_set is available:</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">unordered_set</span><span class="special">&lt;</span><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span><span class="special">,</span> <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special">&lt;</span><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">books</span><span class="special">;</span>
<span class="identifier">books</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">knife</span><span class="special">);</span>
<span class="identifier">books</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span><span class="special">(</span><span class="number">2443</span><span class="special">,</span> <span class="string">"Lindgren, Torgny"</span><span class="special">,</span> <span class="string">"Hash"</span><span class="special">));</span>
<span class="identifier">books</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span><span class="special">(</span><span class="number">1953</span><span class="special">,</span> <span class="string">"Snyder, Bernadette M."</span><span class="special">,</span>
<span class="string">"Heavenly Hash: A Tasty Mix of a Mother's Meditations"</span><span class="special">));</span>
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">books</span><span class="special">.</span><span class="identifier">find</span><span class="special">(</span><span class="identifier">knife</span><span class="special">)</span> <span class="special">!=</span> <span class="identifier">books</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span>
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">books</span><span class="special">.</span><span class="identifier">find</span><span class="special">(</span><span class="identifier">dandelion</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">books</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span>
</pre>
<p>
The full example can be found in: <a href="../../../libs/container_hash/examples/books.hpp" target="_top">/libs/container_hash/examples/books.hpp</a>
and <a href="../../../libs/container_hash/examples/books.cpp" target="_top">/libs/container_hash/examples/books.cpp</a>.
</p>
<div class="tip"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>
When writing a hash function, first look at how the equality function works.
Objects that are equal must generate the same hash value. When objects are
not equal they should generate different hash values. In this object equality
was based just on the id so the hash function only hashes the id. If it was
based on the object's name and author then the hash function should take
them into account (how to do this is discussed in the next section).
</p></td></tr>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2005-2008 Daniel
James<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="tutorial.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="combine.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,70 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Disabling The Extensions</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../hash.html" title="Chapter 10. Boost.ContainerHash">
<link rel="prev" href="portability.html" title="Portability">
<link rel="next" href="changes.html" title="Change Log">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="portability.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="changes.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="hash.disable"></a><a class="link" href="disable.html" title="Disabling The Extensions">Disabling The Extensions</a>
</h2></div></div></div>
<p>
While <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>'s extensions are
generally useful, you might want to turn them of in order to check that your
code will work with other implementations of TR1. To do this define the macro
<code class="computeroutput"><span class="identifier">BOOST_HASH_NO_EXTENSIONS</span></code>. When
this macro is defined, only the specialisations detailed in TR1 will be declared.
But, if you later undefine the macro and include &lt;<code class="computeroutput"><a class="link" href="reference.html#header.boost.container_hash.hash_hpp" title="Header &lt;boost/container_hash/hash.hpp&gt;">boost/container_hash/hash.hpp</a></code>&gt;
then the non-specialised form will be defined - activating the extensions.
</p>
<p>
It is strongly recommended that you never undefine the macro - and only define
it so that it applies to the complete translation unit, either by defining
it at the beginning of the main source file or, preferably, by using a compiler
switch or preference. And you really should never define it in header files.
</p>
<p>
If you are writing a library which has code in the header which requires the
extensions, then the best action is to tell users not to define the macro.
Their code won't <span class="emphasis"><em>require</em></span> the macro.
</p>
<p>
Translation units that are compiled with the macro defined will link with units
that were compiled without it. This feature has been designed to avoid ODR
violations.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2005-2008 Daniel
James<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="portability.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="changes.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

67
doc/html/hash/links.html Normal file
View File

@@ -0,0 +1,67 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Links</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../hash.html" title="Chapter 10. Boost.ContainerHash">
<link rel="prev" href="../boost/hash_std__1_3_11_11_2_2_25.html" title="Struct hash&lt;std::type_index&gt;">
<link rel="next" href="acknowledgements.html" title="Acknowledgements">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../boost/hash_std__1_3_11_11_2_2_25.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="acknowledgements.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="hash.links"></a><a class="link" href="links.html" title="Links">Links</a>
</h2></div></div></div>
<p>
<span class="bold"><strong>A Proposal to Add Hash Tables to the Standard Library</strong></span>
<a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2003/n1456.html" target="_top">http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2003/n1456.html</a>
The hash table proposal explains much of the design. The hash function object
is discussed in Section D.
</p>
<p>
<span class="bold"><strong>The C++ Standard Library Technical Report.</strong></span>
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf" target="_top">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf</a>
Contains the hash function specification in section 6.3.2.
</p>
<p>
<span class="bold"><strong>Library Extension Technical Report Issues List.</strong></span>
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1837.pdf" target="_top">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1837.pdf</a>
The library implements the extension described in Issue 6.18, pages 63-67.
</p>
<p>
<span class="bold"><strong>Methods for Identifying Versioned and Plagiarised Documents</strong></span>
Timothy C. Hoad, Justin Zobel <a href="http://www.cs.rmit.edu.au/~jz/fulltext/jasist-tch.pdf" target="_top">http://www.cs.rmit.edu.au/~jz/fulltext/jasist-tch.pdf</a>
Contains the hash function that <code class="computeroutput"><a class="link" href="reference.html#boost.hash_combine">boost::hash_combine</a></code>
is based on.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2005-2008 Daniel
James<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../boost/hash_std__1_3_11_11_2_2_25.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="acknowledgements.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,137 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Portability</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../hash.html" title="Chapter 10. Boost.ContainerHash">
<link rel="prev" href="combine.html" title="Combining hash values">
<link rel="next" href="disable.html" title="Disabling The Extensions">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="combine.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="disable.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="hash.portability"></a><a class="link" href="portability.html" title="Portability">Portability</a>
</h2></div></div></div>
<p>
<code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code> is written to be as portable
as possible, but unfortunately, several older compilers don't support argument
dependent lookup (ADL) - the mechanism used for customisation. On those compilers
custom overloads for <code class="computeroutput"><span class="identifier">hash_value</span></code>
needs to be declared in the boost namespace.
</p>
<p>
On a strictly standards compliant compiler, an overload defined in the boost
namespace won't be found when <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>
is instantiated, so for these compilers the overload should only be declared
in the same namespace as the class.
</p>
<p>
Let's say we have a simple custom type:
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">foo</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">custom_type</span>
<span class="special">{</span>
<span class="identifier">T</span> <span class="identifier">value</span><span class="special">;</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">custom_type</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">value</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span> <span class="special">{}</span>
<span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">custom_type</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">hasher</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">hasher</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span><span class="special">);</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="special">}</span>
</pre>
<p>
On a compliant compiler, when <code class="computeroutput"><span class="identifier">hash_value</span></code>
is called for this type, it will look at the namespace inside the type and
find <code class="computeroutput"><span class="identifier">hash_value</span></code> but on a compiler
which doesn't support ADL <code class="computeroutput"><span class="identifier">hash_value</span></code>
won't be found. To make things worse, some compilers which do support ADL won't
find a friend class defined inside the class.
</p>
<p>
So first move the member function out of the class:
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">foo</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">custom_type</span>
<span class="special">{</span>
<span class="identifier">T</span> <span class="identifier">value</span><span class="special">;</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">custom_type</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">value</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span> <span class="special">{}</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">hash</span><span class="special">(</span><span class="identifier">custom_type</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">hasher</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">hasher</span><span class="special">(</span><span class="identifier">value</span><span class="special">);</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">inline</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">custom_type</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">hash</span><span class="special">();</span>
<span class="special">}</span>
<span class="special">}</span>
</pre>
<p>
Unfortunately, I couldn't declare hash_value as a friend, as some compilers
don't support template friends, so instead I declared a member function to
calculate the hash, and called it from hash_value.
</p>
<p>
For compilers which don't support ADL, hash_value needs to be defined in the
boost namespace:
</p>
<pre class="programlisting"><span class="preprocessor">#ifdef</span> <span class="identifier">BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP</span>
<span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="preprocessor">#else</span>
<span class="keyword">namespace</span> <span class="identifier">foo</span>
<span class="preprocessor">#endif</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">foo</span><span class="special">::</span><span class="identifier">custom_type</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">hash</span><span class="special">();</span>
<span class="special">}</span>
<span class="special">}</span>
</pre>
<p>
Full code for this example is at <a href="../../../libs/container_hash/examples/portable.cpp" target="_top">/libs/container_hash/examples/portable.cpp</a>.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2005-2008 Daniel
James<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="combine.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="disable.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,96 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Rationale</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../hash.html" title="Chapter 10. Boost.ContainerHash">
<link rel="prev" href="changes.html" title="Change Log">
<link rel="next" href="reference.html" title="Reference">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="changes.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="hash.rationale"></a><a class="link" href="rationale.html" title="Rationale">Rationale</a>
</h2></div></div></div>
<p>
The rationale can be found in the original design <a href="#ftn.hash.rationale.f0" class="footnote" name="hash.rationale.f0"><sup class="footnote">[2]</sup></a>.
</p>
<h4>
<a name="hash.rationale.h0"></a>
<span class="phrase"><a name="hash.rationale.quality_of_the_hash_function"></a></span><a class="link" href="rationale.html#hash.rationale.quality_of_the_hash_function">Quality
of the hash function</a>
</h4>
<p>
Many hash functions strive to have little correlation between the input and
output values. They attempt to uniformally distribute the output values for
very similar inputs. This hash function makes no such attempt. In fact, for
integers, the result of the hash function is often just the input value. So
similar but different input values will often result in similar but different
output values. This means that it is not appropriate as a general hash function.
For example, a hash table may discard bits from the hash function resulting
in likely collisions, or might have poor collision resolution when hash values
are clustered together. In such cases this hash function will preform poorly.
</p>
<p>
But the standard has no such requirement for the hash function, it just requires
that the hashes of two different values are unlikely to collide. Containers
or algorithms designed to work with the standard hash function will have to
be implemented to work well when the hash function's output is correlated to
its input. Since they are paying that cost a higher quality hash function would
be wasteful.
</p>
<p>
For other use cases, if you do need a higher quality hash function, then neither
the standard hash function or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">hash</span></code> are
appropriate. There are several options available. One is to use a second hash
on the output of this hash function, such as <a href="http://web.archive.org/web/20121102023700/http://www.concentric.net/~Ttwang/tech/inthash.htm" target="_top">Thomas
Wang's hash function</a>. This this may not work as well as a hash algorithm
tailored for the input.
</p>
<p>
For strings there are several fast, high quality hash functions available (for
example <a href="http://code.google.com/p/smhasher/" target="_top">MurmurHash3</a>
and <a href="http://code.google.com/p/cityhash/" target="_top">Google's CityHash</a>),
although they tend to be more machine specific. These may also be appropriate
for hashing a binary representation of your data - providing that all equal
values have an equal representation, which is not always the case (e.g. for
floating point values).
</p>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.hash.rationale.f0" class="footnote"><p><a href="#hash.rationale.f0" class="para"><sup class="para">[2] </sup></a>
issue 6.18 of the <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1837.pdf" target="_top">Library
Extension Technical Report Issues List</a> (page 63)
</p></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2005-2008 Daniel
James<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="changes.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,452 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Reference</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../hash.html" title="Chapter 10. Boost.ContainerHash">
<link rel="prev" href="rationale.html" title="Rationale">
<link rel="next" href="../boost/hash.html" title="Struct template hash">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="rationale.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../boost/hash.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="hash.reference"></a>Reference</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="reference.html#hash.reference.specification"></a></span></dt>
<dt><span class="section"><a href="reference.html#header.boost.container_hash.hash_hpp">Header &lt;boost/container_hash/hash.hpp&gt;</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"></div>
<p>For the full specification, see section 6.3 of the
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf" target="_top">C++ Standard Library Technical Report</a>
and issue 6.18 of the
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1837.pdf" target="_top">Library Extension Technical Report Issues List</a> (page 63).
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="header.boost.container_hash.hash_hpp"></a>Header &lt;<a href="../../../boost/container_hash/hash.hpp" target="_top">boost/container_hash/hash.hpp</a>&gt;</h3></div></div></div>
<p>
Defines <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>,
and helper functions.
</p>
<pre class="synopsis"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash.html" title="Struct template hash">hash</a><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_bool_1_3_11_11_2_2_2.html" title="Struct hash&lt;bool&gt;">hash</a><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_char_1_3_11_11_2_2_3.html" title="Struct hash&lt;char&gt;">hash</a><span class="special">&lt;</span><span class="keyword">char</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_signe_1_3_11_11_2_2_4.html" title="Struct hash&lt;signed char&gt;">hash</a><span class="special">&lt;</span><span class="keyword">signed</span> <span class="keyword">char</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_unsig_1_3_11_11_2_2_5.html" title="Struct hash&lt;unsigned char&gt;">hash</a><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_wchar_1_3_11_11_2_2_6.html" title="Struct hash&lt;wchar_t&gt;">hash</a><span class="special">&lt;</span><span class="keyword">wchar_t</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_char1_1_3_11_11_2_2_7.html" title="Struct hash&lt;char16_t&gt;">hash</a><span class="special">&lt;</span><span class="keyword">char16_t</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_char3_1_3_11_11_2_2_8.html" title="Struct hash&lt;char32_t&gt;">hash</a><span class="special">&lt;</span><span class="keyword">char32_t</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_short_1_3_11_11_2_2_9.html" title="Struct hash&lt;short&gt;">hash</a><span class="special">&lt;</span><span class="keyword">short</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_unsi_1_3_11_11_2_2_10.html" title="Struct hash&lt;unsigned short&gt;">hash</a><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">short</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_int_1_3_11_11_2_2_11.html" title="Struct hash&lt;int&gt;">hash</a><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_unsi_1_3_11_11_2_2_12.html" title="Struct hash&lt;unsigned int&gt;">hash</a><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_long_1_3_11_11_2_2_13.html" title="Struct hash&lt;long&gt;">hash</a><span class="special">&lt;</span><span class="keyword">long</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_unsi_1_3_11_11_2_2_14.html" title="Struct hash&lt;unsigned long&gt;">hash</a><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">long</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_long_1_3_11_11_2_2_15.html" title="Struct hash&lt;long long&gt;">hash</a><span class="special">&lt;</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_unsi_1_3_11_11_2_2_16.html" title="Struct hash&lt;unsigned long long&gt;">hash</a><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_floa_1_3_11_11_2_2_17.html" title="Struct hash&lt;float&gt;">hash</a><span class="special">&lt;</span><span class="keyword">float</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_doub_1_3_11_11_2_2_18.html" title="Struct hash&lt;double&gt;">hash</a><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_long_1_3_11_11_2_2_19.html" title="Struct hash&lt;long double&gt;">hash</a><span class="special">&lt;</span><span class="keyword">long</span> <span class="keyword">double</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_std__1_3_11_11_2_2_20.html" title="Struct hash&lt;std::string&gt;">hash</a><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_std__1_3_11_11_2_2_21.html" title="Struct hash&lt;std::wstring&gt;">hash</a><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">wstring</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_std__1_3_11_11_2_2_22.html" title="Struct hash&lt;std::u16string&gt;">hash</a><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">u16string</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_std__1_3_11_11_2_2_23.html" title="Struct hash&lt;std::u32string&gt;">hash</a><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">u32string</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_T_1_3_11_11_2_2_24.html" title="Struct template hash&lt;T*&gt;">hash</a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">*</span><span class="special">&gt;</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../boost/hash_std__1_3_11_11_2_2_25.html" title="Struct hash&lt;std::type_index&gt;">hash</a><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_index</span><span class="special">&gt;</span><span class="special">;</span>
<span class="comment">// <a class="link" href="reference.html#id-1_3_11_11_2_2_26-bb">Support functions (Boost extension).</a></span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> <span class="keyword">void</span> <a class="link" href="reference.html#boost.hash_combine"><span class="identifier">hash_combine</span></a><span class="special">(</span><span class="identifier">size_t</span> <span class="special">&amp;</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> It<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_26_2_1-bb"><span class="identifier">hash_range</span></a><span class="special">(</span><span class="identifier">It</span><span class="special">,</span> <span class="identifier">It</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> It<span class="special">&gt;</span> <span class="keyword">void</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_26_2_2-bb"><span class="identifier">hash_range</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">&amp;</span><span class="special">,</span> <span class="identifier">It</span><span class="special">,</span> <span class="identifier">It</span><span class="special">)</span><span class="special">;</span>
<span class="comment">// <a class="link" href="reference.html#id-1_3_11_11_2_2_27-bb">Overloadable hash implementation (Boost extension).</a></span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_2-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">bool</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_3-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">char</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_4-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">signed</span> <span class="keyword">char</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_5-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_6-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">wchar_t</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_7-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">char16_t</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_8-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">char32_t</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_9-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">short</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_10-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">short</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_11-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">int</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_12-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_13-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">long</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_14-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">long</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_15-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_16-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_17-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">float</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_18-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">double</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_19-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">long</span> <span class="keyword">double</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_20-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">unsigned</span> N<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_21-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">T</span> <span class="special">(</span><span class="special">&amp;</span><span class="identifier">val</span><span class="special">)</span><span class="special">[</span><span class="identifier">N</span><span class="special">]</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">unsigned</span> N<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_22-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span> <span class="special">(</span><span class="special">&amp;</span><span class="identifier">val</span><span class="special">)</span><span class="special">[</span><span class="identifier">N</span><span class="special">]</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Ch<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_23-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_string</span><span class="special">&lt;</span><span class="identifier">Ch</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">char_traits</span><span class="special">&lt;</span><span class="identifier">Ch</span><span class="special">&gt;</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> A<span class="special">,</span> <span class="keyword">typename</span> B<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_24-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span> <span class="identifier">B</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_25-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_26-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_27-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">deque</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> K<span class="special">,</span> <span class="keyword">typename</span> C<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_28-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">set</span><span class="special">&lt;</span><span class="identifier">K</span><span class="special">,</span> <span class="identifier">C</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> K<span class="special">,</span> <span class="keyword">typename</span> C<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_29-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">multiset</span><span class="special">&lt;</span><span class="identifier">K</span><span class="special">,</span> <span class="identifier">C</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> K<span class="special">,</span> <span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">typename</span> C<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_30-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special">&lt;</span><span class="identifier">K</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">C</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> K<span class="special">,</span> <span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">typename</span> C<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_31-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">multimap</span><span class="special">&lt;</span><span class="identifier">K</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">C</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_32-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">complex</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_33-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_index</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> N<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_34-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">array</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">N</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span><span class="special">...</span> T<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="reference.html#id-1_3_11_11_2_2_27_1_35-bb"><span class="identifier">hash_value</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">...</span><span class="special">&gt;</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span></pre>
<div class="refsect2">
<a name="id-1.3.11.11.3.4"></a><h3>
<a name="id-1_3_11_11_2_2_26-bb"></a><code class="computeroutput"></code> Support functions (Boost extension).</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> <span class="keyword">void</span> <a name="boost.hash_combine"></a><span class="identifier">hash_combine</span><span class="special">(</span><span class="identifier">size_t</span> <span class="special">&amp;</span> seed<span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> v<span class="special">)</span><span class="special">;</span></pre>
<p class="simpara">
Called repeatedly to incrementally create a hash value from
several variables.
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term">Effects:</span></p></td>
<td>
Updates <code class="computeroutput">seed</code> with a new hash value generated by
combining it with the result of
<code class="computeroutput"><a class="link" href="reference.html#boost.hash_va_1_3_11_11_2_2_27_1">hash_value</a>(v)</code>. Will
always produce the same result for the same combination of
<code class="computeroutput">seed</code> and
<code class="computeroutput"><a class="link" href="reference.html#boost.hash_va_1_3_11_11_2_2_27_1">hash_value</a>(v)</code> during
the single run of a program.
</td>
</tr>
<tr>
<td><p><span class="term">Notes:</span></p></td>
<td>
<p><a class="link" href="reference.html#boost.hash_va_1_3_11_11_2_2_27_1">hash_value</a> is called without
qualification, so that overloads can be found via ADL.</p>
<p>This is an extension to TR1</p>
<p>
Forward declared in
<code class="computeroutput">&lt;boost/container_hash/hash_fwd.hpp&gt;</code>
</p>
<p>
This hash function is not intended for general use, and isn't
guaranteed to be equal during separate runs of a program - so
please don't use it for any persistent storage or communication.
</p>
</td>
</tr>
<tr>
<td><p><span class="term">Throws:</span></p></td>
<td>
Only throws if <a class="link" href="reference.html#boost.hash_va_1_3_11_11_2_2_27_1">hash_value</a>(T) throws.
Strong exception safety, as long as <a class="link" href="reference.html#boost.hash_va_1_3_11_11_2_2_27_1">hash_value</a>(T)
also has strong exception safety.
</td>
</tr>
</tbody>
</table></div>
</li>
<li class="listitem">
<p><a name="boost.hash_range"></a></p>
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> It<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_26_2_1-bb"></a><span class="identifier">hash_range</span><span class="special">(</span><span class="identifier">It</span> first<span class="special">,</span> <span class="identifier">It</span> last<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> It<span class="special">&gt;</span> <span class="keyword">void</span> <a name="id-1_3_11_11_2_2_26_2_2-bb"></a><span class="identifier">hash_range</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">&amp;</span> seed<span class="special">,</span> <span class="identifier">It</span> first<span class="special">,</span> <span class="identifier">It</span> last<span class="special">)</span><span class="special">;</span></pre>
<p class="simpara">
Calculate the combined hash value of the elements of an iterator
range.
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term">Effects:</span></p></td>
<td>
<p>For the two argument overload:
</p>
<pre class="programlisting">
<span class="identifier">size_t</span> <span class="identifier">seed</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<span class="keyword">for</span><span class="special">(</span><span class="special">;</span> <span class="identifier">first</span> <span class="special">!=</span> <span class="identifier">last</span><span class="special">;</span> <span class="special">++</span><span class="identifier">first</span><span class="special">)</span>
<span class="special">{</span>
<a class="link" href="reference.html#boost.hash_combine">hash_combine</a><span class="special">(</span><span class="identifier">seed</span><span class="special">,</span> <span class="special">*</span><span class="identifier">first</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">return</span> <span class="identifier">seed</span><span class="special">;</span>
</pre>
<p>
</p>
<p>For the three arguments overload:</p>
<pre class="programlisting">
<span class="keyword">for</span><span class="special">(</span><span class="special">;</span> <span class="identifier">first</span> <span class="special">!=</span> <span class="identifier">last</span><span class="special">;</span> <span class="special">++</span><span class="identifier">first</span><span class="special">)</span>
<span class="special">{</span>
<a class="link" href="reference.html#boost.hash_combine">hash_combine</a><span class="special">(</span><span class="identifier">seed</span><span class="special">,</span> <span class="special">*</span><span class="identifier">first</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span>
</pre>
</td>
</tr>
<tr>
<td><p><span class="term">Notes:</span></p></td>
<td>
<p>
<code class="computeroutput">hash_range</code> is sensitive to the order of the elements
so it wouldn't be appropriate to use this with an unordered
container.
</p>
<p>This is an extension to TR1</p>
<p>
Forward declared in
<code class="computeroutput">&lt;boost/container_hash/hash_fwd.hpp&gt;</code>
</p>
<p>
This hash function is not intended for general use, and isn't
guaranteed to be equal during separate runs of a program - so
please don't use it for any persistent storage or communication.
</p>
</td>
</tr>
<tr>
<td><p><span class="term">Throws:</span></p></td>
<td><p>
Only throws if <code class="computeroutput"><a class="link" href="reference.html#boost.hash_va_1_3_11_11_2_2_27_1">hash_value</a>(std::iterator_traits&lt;It&gt;::value_type)</code>
throws. <code class="computeroutput">hash_range(std::size_t&amp;, It, It)</code> has basic exception safety as long as
<code class="computeroutput"><a class="link" href="reference.html#boost.hash_va_1_3_11_11_2_2_27_1">hash_value</a>(std::iterator_traits&lt;It&gt;::value_type)</code>
has basic exception safety.
</p></td>
</tr>
</tbody>
</table></div>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="id-1.3.11.11.3.5"></a><h3>
<a name="id-1_3_11_11_2_2_27-bb"></a><code class="computeroutput"></code> Overloadable hash implementation (Boost extension).</h3>
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
<p><a name="boost.hash_va_1_3_11_11_2_2_27_1"></a></p>
<pre class="literallayout"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_2-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">bool</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_3-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">char</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_4-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">signed</span> <span class="keyword">char</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_5-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">char</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_6-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">wchar_t</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_7-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">char16_t</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_8-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">char32_t</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_9-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">short</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_10-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">short</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_11-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">int</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_12-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">int</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_13-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">long</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_14-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">long</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_15-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">long</span> <span class="keyword">long</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_16-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_17-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">float</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_18-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">double</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_19-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">long</span> <span class="keyword">double</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_20-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">unsigned</span> N<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_21-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">T</span> <span class="special">(</span><span class="special">&amp;</span><span class="identifier">val</span><span class="special">)</span><span class="special">[</span><span class="identifier">N</span><span class="special">]</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">unsigned</span> N<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_22-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span> <span class="special">(</span><span class="special">&amp;</span><span class="identifier">val</span><span class="special">)</span><span class="special">[</span><span class="identifier">N</span><span class="special">]</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Ch<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_23-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_string</span><span class="special">&lt;</span><span class="identifier">Ch</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">char_traits</span><span class="special">&lt;</span><span class="identifier">Ch</span><span class="special">&gt;</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> A<span class="special">,</span> <span class="keyword">typename</span> B<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_24-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span> <span class="identifier">B</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_25-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_26-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_27-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">deque</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> K<span class="special">,</span> <span class="keyword">typename</span> C<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_28-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">set</span><span class="special">&lt;</span><span class="identifier">K</span><span class="special">,</span> <span class="identifier">C</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> K<span class="special">,</span> <span class="keyword">typename</span> C<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_29-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">multiset</span><span class="special">&lt;</span><span class="identifier">K</span><span class="special">,</span> <span class="identifier">C</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> K<span class="special">,</span> <span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">typename</span> C<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_30-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special">&lt;</span><span class="identifier">K</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">C</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> K<span class="special">,</span> <span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">typename</span> C<span class="special">,</span> <span class="keyword">typename</span> A<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_31-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">multimap</span><span class="special">&lt;</span><span class="identifier">K</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">C</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_32-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">complex</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_33-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_index</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> N<span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_34-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">array</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">N</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> val<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span><span class="special">...</span> T<span class="special">&gt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="id-1_3_11_11_2_2_27_1_35-bb"></a><span class="identifier">hash_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">...</span><span class="special">&gt;</span> val<span class="special">)</span><span class="special">;</span></pre>
<p class="simpara">
Implementation of the hash function.
</p>
<p>
Generally shouldn't be called directly by users, instead they should use
<code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>, <code class="computeroutput"><a class="link" href="reference.html#boost.hash_range">boost::hash_range</a></code>
or <code class="computeroutput"><a class="link" href="reference.html#boost.hash_combine">boost::hash_combine</a></code> which
call <code class="computeroutput">hash_value</code> without namespace qualification so that overloads
for custom types are found via ADL.
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term">Notes:</span></p></td>
<td>
<p>This is an extension to TR1</p>
<p>
This hash function is not intended for general use, and isn't
guaranteed to be equal during separate runs of a program - so
please don't use it for any persistent storage or communication.
</p>
</td>
</tr>
<tr>
<td><p><span class="term">Throws:</span></p></td>
<td>
Only throws if a user supplied version of
<code class="computeroutput"><a class="link" href="reference.html#boost.hash_va_1_3_11_11_2_2_27_1">hash_value</a></code>
throws for an element of a container, or
one of the types stored in a pair.
</td>
</tr>
<tr>
<td><p><span class="term">Returns:</span></p></td>
<td><div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Types</th>
<th>Returns</th>
</tr></thead>
<tbody>
<tr>
<td>
<code class="computeroutput">bool</code>,
<code class="computeroutput">char</code>, <code class="computeroutput">signed char</code>, <code class="computeroutput">unsigned char</code>,
<code class="computeroutput">wchar_t</code>, <code class="computeroutput">char16_t</code>, <code class="computeroutput">char32_t</code>,
<code class="computeroutput">short</code>, <code class="computeroutput">unsigned short</code>,
<code class="computeroutput">int</code>, <code class="computeroutput">unsigned int</code>, <code class="computeroutput">long</code>, <code class="computeroutput">unsigned long</code>
</td>
<td><code class="computeroutput">val</code></td>
</tr>
<tr>
<td>
<code class="computeroutput">long long</code>, <code class="computeroutput">unsigned long long</code>
</td>
<td>
<code class="computeroutput">val</code> when <code class="computeroutput">abs(val) &lt;= std::numeric_limits&lt;std::size_t&gt;::max()</code>.</td>
</tr>
<tr>
<td>
<code class="computeroutput">float</code>, <code class="computeroutput">double</code>, <code class="computeroutput">long double</code>
</td>
<td>An unspecified value, except that equal arguments shall yield the same result.</td>
</tr>
<tr>
<td><code class="computeroutput">T*</code></td>
<td>An unspecified value, except that equal arguments shall yield the same result.</td>
</tr>
<tr>
<td>
<code class="computeroutput">T val[N]</code>,
<code class="computeroutput">const T val[N]</code>
</td>
<td><code class="computeroutput">hash_range(val, val+N)</code></td>
</tr>
<tr>
<td>
<code class="computeroutput">std:basic_string&lt;Ch, std::char_traits&lt;Ch&gt;, A&gt;</code>,
<code class="computeroutput">std::vector&lt;T, A&gt;</code>,
<code class="computeroutput">std::list&lt;T, A&gt;</code>,
<code class="computeroutput">std::deque&lt;T, A&gt;</code>,
<code class="computeroutput">std::set&lt;K, C, A&gt;</code>,
<code class="computeroutput">std::multiset&lt;K, C, A&gt;</code>,
<code class="computeroutput">std::map&lt;K, T, C, A&gt;</code>,
<code class="computeroutput">std::multimap&lt;K, T, C, A&gt;</code>,
<code class="computeroutput">std::array&lt;T, N&gt;</code>
</td>
<td><code class="computeroutput">hash_range(val.begin(), val.end())</code></td>
</tr>
<tr>
<td><code class="computeroutput">std::pair&lt;A, B&gt;</code></td>
<td><pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">size_t</span> <span class="identifier">seed</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<a class="link" href="reference.html#boost.hash_combine">hash_combine</a><span class="special">(</span><span class="identifier">seed</span><span class="special">,</span> <span class="identifier">val</span><span class="special">.</span><span class="identifier">first</span><span class="special">)</span><span class="special">;</span>
<a class="link" href="reference.html#boost.hash_combine">hash_combine</a><span class="special">(</span><span class="identifier">seed</span><span class="special">,</span> <span class="identifier">val</span><span class="special">.</span><span class="identifier">second</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">seed</span><span class="special">;</span></pre></td>
</tr>
<tr>
<td><code class="computeroutput">std::tuple&lt;T...&gt;</code></td>
<td><pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">size_t</span> <span class="identifier">seed</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<a class="link" href="reference.html#boost.hash_combine">hash_combine</a><span class="special">(</span><span class="identifier">seed</span><span class="special">,</span> <span class="identifier">get</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;</span><span class="special">(</span><span class="identifier">val</span><span class="special">)</span><span class="special">)</span><span class="special">;</span>
<a class="link" href="reference.html#boost.hash_combine">hash_combine</a><span class="special">(</span><span class="identifier">seed</span><span class="special">,</span> <span class="identifier">get</span><span class="special">&lt;</span><span class="number">1</span><span class="special">&gt;</span><span class="special">(</span><span class="identifier">val</span><span class="special">)</span><span class="special">)</span><span class="special">;</span>
<span class="comment">// ....</span>
<span class="keyword">return</span> <span class="identifier">seed</span><span class="special">;</span></pre></td>
</tr>
<tr>
<td>
<code class="computeroutput">std::complex&lt;T&gt;</code>
</td>
<td>When <code class="computeroutput">T</code> is a built in type and <code class="computeroutput">val.imag() == 0</code>, the result is equal to <code class="computeroutput">hash_value(val.real())</code>. Otherwise an unspecified value, except that equal arguments shall yield the same result.</td>
</tr>
<tr>
<td>
<code class="computeroutput">std::type_index</code>
</td>
<td><code class="computeroutput">val.hash_code()</code></td>
</tr>
</tbody>
</table></div></td>
</tr>
</tbody>
</table></div>
</li></ol></div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2005-2008 Daniel
James<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="rationale.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../boost/hash.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,92 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tutorial</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../hash.html" title="Chapter 10. Boost.ContainerHash">
<link rel="prev" href="../hash.html" title="Chapter 10. Boost.ContainerHash">
<link rel="next" href="custom.html" title="Extending boost::hash for a custom data type">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../hash.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="custom.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="hash.tutorial"></a><a class="link" href="tutorial.html" title="Tutorial">Tutorial</a>
</h2></div></div></div>
<p>
When using a hash index with <a href="../../../libs/multi_index/doc/index.html" target="_top">Boost.MultiIndex</a>,
you don't need to do anything to use <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>
as it uses it by default. To find out how to use a user-defined type, read
the <a class="link" href="custom.html" title="Extending boost::hash for a custom data type">section on extending boost::hash for a custom
data type</a>.
</p>
<p>
If your standard library supplies its own implementation of the unordered associative
containers and you wish to use <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>,
just use an extra template parameter:
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">unordered_multiset</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&gt;</span>
<span class="identifier">set_of_ints</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">unordered_set</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">&gt;,</span> <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&gt;</span>
<span class="identifier">set_of_pairs</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">unordered_map</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">map_int_to_string</span><span class="special">;</span>
</pre>
<p>
To use <code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code> directly, create
an instance and call it as a function:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><code class="computeroutput"><a class="link" href="reference.html#header.boost.container_hash.hash_hpp" title="Header &lt;boost/container_hash/hash.hpp&gt;">boost/container_hash/hash.hpp</a></code><span class="special">&gt;</span>
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
<code class="computeroutput"><a class="link" href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;</span> <span class="identifier">string_hash</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">h</span> <span class="special">=</span> <span class="identifier">string_hash</span><span class="special">(</span><span class="string">"Hash me"</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
For an example of generic use, here is a function to generate a vector containing
the hashes of the elements of a container:
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Container</span><span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">&gt;</span> <span class="identifier">get_hashes</span><span class="special">(</span><span class="identifier">Container</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">&gt;</span> <span class="identifier">hashes</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">transform</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">back_inserter</span><span class="special">(</span><span class="identifier">hashes</span><span class="special">),</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">hash</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">&gt;());</span>
<span class="keyword">return</span> <span class="identifier">hashes</span><span class="special">;</span>
<span class="special">}</span>
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2005-2008 Daniel
James<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../hash.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="custom.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>