| 1 | // Copyright 2005-2009 Daniel James. |
| 2 | // Copyright 2021 Peter Dimov. |
| 3 | // Distributed under the Boost Software License, Version 1.0. |
| 4 | // https://www.boost.org/LICENSE_1_0.txt |
| 5 | |
| 6 | #ifndef BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP |
| 7 | #define BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP |
| 8 | |
| 9 | #include <boost/container_hash/hash_fwd.hpp> |
| 10 | #include <boost/container_hash/is_tuple_like.hpp> |
| 11 | #include <boost/container_hash/is_range.hpp> |
| 12 | #include <type_traits> |
| 13 | #include <utility> |
| 14 | |
| 15 | namespace boost |
| 16 | { |
| 17 | namespace hash_detail |
| 18 | { |
| 19 | |
| 20 | template <std::size_t I, typename T> |
| 21 | inline |
| 22 | typename std::enable_if<(I == std::tuple_size<T>::value), void>::type |
| 23 | hash_combine_tuple_like( std::size_t&, T const& ) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | template <std::size_t I, typename T> |
| 28 | inline |
| 29 | typename std::enable_if<(I < std::tuple_size<T>::value), void>::type |
| 30 | hash_combine_tuple_like( std::size_t& seed, T const& v ) |
| 31 | { |
| 32 | using std::get; |
| 33 | boost::hash_combine( seed, get<I>( v ) ); |
| 34 | |
| 35 | boost::hash_detail::hash_combine_tuple_like<I + 1>( seed, v ); |
| 36 | } |
| 37 | |
| 38 | template <typename T> |
| 39 | inline std::size_t hash_tuple_like( T const& v ) |
| 40 | { |
| 41 | std::size_t seed = 0; |
| 42 | |
| 43 | boost::hash_detail::hash_combine_tuple_like<0>( seed, v ); |
| 44 | |
| 45 | return seed; |
| 46 | } |
| 47 | |
| 48 | } // namespace hash_detail |
| 49 | |
| 50 | template <class T> |
| 51 | inline |
| 52 | typename std::enable_if< |
| 53 | container_hash::is_tuple_like<T>::value && !container_hash::is_range<T>::value, |
| 54 | std::size_t>::type |
| 55 | hash_value( T const& v ) |
| 56 | { |
| 57 | return boost::hash_detail::hash_tuple_like( v ); |
| 58 | } |
| 59 | |
| 60 | } // namespace boost |
| 61 | |
| 62 | #endif // #ifndef BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP |
| 63 | |