
On Mon, Dec 2, 2024 at 9:59 PM Ivan Matek
Read documentation for 20 minutes so apologies in advance is some of questions are too obvious.
1) did you consider using something like std::span here? I presume answer is yes, but you do not want to limit library to C++20 onwards.
HashAlgorithm( unsigned char const* seed, std::size_t n ); void update( void const* data, std::size_t n );
3) I see there is nice trait is_contiguously_hashable trait(padding was one of first things I wondered when reading docs), and also a documentation on how to deal with other types, including when user provides his own hash customization. One thing I would ask regarding design is the following example: std::string a; int b; // not part of the salient state void const* c; friend bool operator==( X const& x1, X const& x2 ) { return x1.a == x2.a && x1.b == x2.b; } template
friend void tag_invoke( boost::hash2::hash_append_tag const&, Hash& h, Flavor const& f , X const& v ) { boost::hash2::hash_append(h, f, v.a); boost::hash2:: hash_append(h, f, v.b); } Here both tag_invoke and operator == need to remember to use same fields. Would it be possible to have support so that both hash and operator == can use member function helper that returns tuple of references( to salient fields)? e.g. assume this is my current code and I want to add hash support for it. struct X { int a; short b; short cached_something; constexpr auto repr() const { return std::tie(a,b); } constexpr bool operator == (const X& other) const { return repr() == other.repr(); } };
I know Mp11 has tuple_for_each, but I wonder if it would be nice to have something that makes this idiom easier to use?
To answer my own questions: 1) this is never directly called by users so no need for safer API 3) there is overload of hash_append that works for tuples, nice Sorry for noise.