Boost C++ Libraries: Ticket #9755: Simple way to get hash. https://svn.boost.org/trac10/ticket/9755 <p> When writing custom hash_value functions, it is often useful to forward to the hash of another value. However, there is currently no short and simple way to do this. Consider: </p> <p> template&lt;class T&gt; struct C { </p> <blockquote> <p> some_complex_mpl_expression&lt;T&gt;::type value; friend std::size_t hash_value() { </p> <blockquote> <p> <em> First attempt: requires knowledge of the type of the value to hash. return boost::hash&lt;some_complex_mpl_expression&lt;T&gt;::type&gt;()(this-&gt;value); </em></p> </blockquote> </blockquote> <blockquote> <blockquote> <p> <em> Second attempt: two lines, not recommended. using namespace boost; return hash_value(this-&gt;value); </em></p> </blockquote> </blockquote> <blockquote> <blockquote> <p> <em> Third attempt: works, but requires three lines of code and doesn't yield the same hash as the first two attempts. std::size_t seed = 0; boost::hash_combine(seed, this-&gt;value); return seed; </em></p> </blockquote> <p> } </p> </blockquote> <p> }; </p> <p> I propose the addition of a simple function to calculate the hash of any arbitrary value, defined below: </p> <p> template&lt;class T&gt; std::size_t get_hash(T const&amp; v) { </p> <blockquote> <p> return hash&lt;T&gt;()(v); </p> </blockquote> <p> } </p> <p> This would allow me to write the above hash_value function with a single line of simple and correct code: </p> <blockquote> <p> friend std::size_t hash_value() { </p> <blockquote> <p> return boost::get_hash(this-&gt;value); </p> </blockquote> <p> } </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9755 Trac 1.4.3