47 lines
810 B
C++
47 lines
810 B
C++
|
#include "hash/tuple.hpp"
|
||
|
|
||
|
#include "tap.hpp"
|
||
|
|
||
|
#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 ();
|
||
|
}
|