2023-07-24 12:56:19 +10:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../hash.hpp"
|
|
|
|
#include "./mix.hpp"
|
|
|
|
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
|
|
|
|
namespace cruft::hash {
|
|
|
|
/// Computes a hash for a tuple type by elementwise hashing, then variadic mixing.
|
|
|
|
///
|
|
|
|
/// \tparam ElementT The per-element hash type
|
|
|
|
/// \tparam MixT The mixing hash type. Must support variadic operator()
|
|
|
|
template <
|
|
|
|
typename ElementT,
|
|
|
|
typename MixT = cruft::hash::mixer
|
|
|
|
>
|
|
|
|
class tuple {
|
|
|
|
public:
|
2023-07-25 10:00:45 +10:00
|
|
|
using is_transparent = void;
|
|
|
|
|
2023-07-24 12:56:19 +10:00
|
|
|
template <typename ...ValueT>
|
|
|
|
auto
|
2023-07-25 10:00:30 +10:00
|
|
|
operator() (std::tuple<ValueT...> const &val) const
|
2023-07-24 12:56:19 +10:00
|
|
|
{
|
|
|
|
return compute (val, std::make_index_sequence<sizeof... (ValueT)> {});
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <typename ...ValueT, std::size_t ...IndexV>
|
|
|
|
auto
|
2023-07-25 10:00:30 +10:00
|
|
|
compute (std::tuple<ValueT...> const &val, std::index_sequence<IndexV...>) const
|
2023-07-24 12:56:19 +10:00
|
|
|
{
|
|
|
|
return MixT {} (
|
|
|
|
ElementT {} (std::get<IndexV> (val))...
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|