2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/hash/tuple.hpp>
|
2023-07-24 12:56:19 +10:00
|
|
|
|
2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/tap.hpp>
|
2023-07-24 12:56:19 +10:00
|
|
|
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
|
|
|
|
// A "hash" that returns the argument's size.
|
|
|
|
struct size_hash {
|
|
|
|
template <typename ValueT>
|
|
|
|
std::size_t
|
|
|
|
operator () (ValueT const &val) const
|
|
|
|
{ return std::size (val); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A 'mix' function that just sums the arguments.
|
|
|
|
struct sum_mix {
|
|
|
|
template <typename ...ValueT>
|
|
|
|
std::size_t
|
|
|
|
operator () (ValueT ...val) const
|
|
|
|
{
|
|
|
|
return (val + ...);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main ()
|
|
|
|
{
|
|
|
|
using namespace std::string_view_literals;
|
|
|
|
|
|
|
|
cruft::hash::tuple<size_hash, sum_mix> h;
|
|
|
|
|
|
|
|
cruft::TAP::logger tap;
|
|
|
|
tap.expect_eq (
|
|
|
|
h (
|
|
|
|
std::make_tuple (
|
|
|
|
"foo"sv, std::vector<int> (5)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
8u,
|
|
|
|
"size/sum tuple hash"
|
|
|
|
);
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|