4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
11 * Code by Tor Brede Vekterli
12 * http://arcticinteractive.com/2009/04/18/compile-time-string-hashing-boost-mpl/
13 * (Boost 1.0 license.)
17 #ifndef LYX_META_HASH_H
18 #define LYX_META_HASH_H
20 #include <boost/mpl/string.hpp>
21 #include <boost/mpl/fold.hpp>
22 #include <boost/mpl/size_t.hpp>
23 #include <boost/functional/hash.hpp>
32 // disable addition overflow warning
33 #pragma warning(disable:4307)
36 template <typename Seed, typename Value>
39 typedef boost::mpl::size_t<
40 Seed::value ^ (static_cast<std::size_t>(Value::value)
41 + 0x9e3779b9 + (Seed::value << 6) + (Seed::value >> 2))
49 // Hash any sequence of integral wrapper types
50 template <typename Sequence>
54 , boost::mpl::size_t<0>
55 , hash_combine<boost::mpl::_1, boost::mpl::_2>
59 // For hashing std::strings et al that don't include the zero-terminator
60 template <typename String>
61 struct hash_string : hash_sequence<String>
64 // Hash including terminating zero for char arrays
65 template <typename String>
67 : hash_combine< hash_sequence<String>, boost::mpl::size_t<0> >::type