hash.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*=============================================================================
  2. Copyright (c) 2014 Christoph Weiss
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(FUSION_HASH_23072014_1017)
  7. #define FUSION_HASH_23072014_1017
  8. #include <boost/functional/hash.hpp>
  9. #include <boost/fusion/algorithm/iteration/fold.hpp>
  10. #include <boost/fusion/support/is_sequence.hpp>
  11. #include <boost/utility/enable_if.hpp>
  12. namespace boost { namespace fusion
  13. {
  14. namespace hashing
  15. {
  16. struct hash_combine_fold
  17. {
  18. typedef std::size_t result_type;
  19. template<typename T>
  20. inline std::size_t operator()(std::size_t seed, T const& v)
  21. {
  22. boost::hash_combine(seed, v);
  23. return seed;
  24. }
  25. };
  26. template <typename Seq>
  27. inline typename
  28. boost::enable_if<traits::is_sequence<Seq>, std::size_t>::type
  29. hash_value(Seq const& seq)
  30. {
  31. return fold(seq, 0, hash_combine_fold());
  32. }
  33. }
  34. using hashing::hash_value;
  35. }}
  36. #endif