diff --git a/sprout/functional/hash/hash.hpp b/sprout/functional/hash/hash.hpp index 9d55d6f5..446f4702 100644 --- a/sprout/functional/hash/hash.hpp +++ b/sprout/functional/hash/hash.hpp @@ -182,16 +182,43 @@ namespace sprout { // hash_range // template - inline SPROUT_CONSTEXPR std::size_t hash_range(Iterator first, Iterator last) { - return sprout::hash_range(0, first, last); - } - template inline SPROUT_CONSTEXPR std::size_t hash_range(std::size_t seed, Iterator first, Iterator last) { return first != last ? sprout::hash_range(sprout::hash_combine(seed, *first), sprout::next(first), last) : seed ; } + template + inline SPROUT_CONSTEXPR std::size_t hash_range(Iterator first, Iterator last) { + return sprout::hash_range(0, first, last); + } + + namespace detail { + template + inline SPROUT_CONSTEXPR std::size_t hash_values_combine_impl(std::size_t seed, T const& v) { + return sprout::hash_combine(seed, v); + } + template + inline SPROUT_CONSTEXPR std::size_t hash_values_combine_impl(std::size_t seed, Head const& head, Tail const&... tail) { + return sprout::detail::hash_values_combine_impl(sprout::hash_combine(seed, head), tail...); + } + } // namespace detail + + // + // hash_values_combine + // + template + inline SPROUT_CONSTEXPR std::size_t hash_values_combine(std::size_t seed, Args const&... args) { + return sprout::detail::hash_values_combine_impl(seed, args...); + } + + // + // hash_values + // + template + inline SPROUT_CONSTEXPR std::size_t hash_values(Args const&... args) { + return sprout::hash_values_combine(0, args...); + } // // hash diff --git a/sprout/tuple/tuple.hpp b/sprout/tuple/tuple.hpp index 101edf4f..86316466 100644 --- a/sprout/tuple/tuple.hpp +++ b/sprout/tuple/tuple.hpp @@ -9,5 +9,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_TUPLE_TUPLE_HPP diff --git a/sprout/tuple/tuple/hash.hpp b/sprout/tuple/tuple/hash.hpp new file mode 100644 index 00000000..bde91f95 --- /dev/null +++ b/sprout/tuple/tuple/hash.hpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_TUPLE_TUPLE_HASH_HPP +#define SPROUT_TUPLE_TUPLE_HASH_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace detail { + template + inline SPROUT_CONSTEXPR std::size_t tuple_hash_value_impl( + sprout::tuples::tuple const& v, + sprout::index_tuple + ) + { + return sprout::hash_values(sprout::tuples::get(v)...); + } + } // namespace detail + + template + inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::tuples::tuple const& v) { + return sprout::detail::tuple_hash_value_impl( + v, + sprout::index_range<0, sprout::tuples::tuple_size >::value>::make() + ); + } +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_TUPLE_HASH_HPP