|
Boost : |
From: Ivan Matek (libbooze_at_[hidden])
Date: 2024-12-03 19:31:09
Regarding native vs default:
I doubt you will be able to change the default when people start using the
library, e.g. they might use it to store something on filesystem, etc. but
I see your point.
On Tue, Dec 3, 2024 at 2:56â¯PM Peter Dimov via Boost <boost_at_[hidden]>
wrote:
> Alexander Grund wrote:
> > Am 03.12.24 um 12:47 schrieb Ivan Matek via Boost:
> > >> And you never do this
> > >>
> > >> boost::hash2::hash_append( h, {}, v.x );
> > >> boost::hash2::hash_append( h, {}, v.y );
> > >> boost::hash2::hash_append( h, {}, v.z );
> > >>
> > >> You do this instead
> > >>
> > >> boost::hash2::hash_append( h, f, v.x );
> > >> boost::hash2::hash_append( h, f, v.y );
> > >> boost::hash2::hash_append( h, f, v.z );
> > >
> > > Yes, but then again I am passing f multiple times. I don't want it to
> > > sound like I am making a big deal out of this, I can just do something
> > > like(and I actually use this idiom a lot) const auto append = [&]
> > > (const auto& val){hash_append (h, f, val);} and use that "partially
> > > applied" helper, in case I actually need to do hash_append multiple
> > > times.
> > I think there is space for such a helper:
> > boost::hash2::hasher append(h, f); // Or ...::hasher append(h) for
> default
> > flavor
> > append(v.x);
> > append(v.y);
> > append(v.z);
>
>
> So I suppose I'll be adding the variadic overload, after all.
>
>
>
I was mostly interested in encoding f in helper template, as you mentioned
with repr() idiom I can just call that in 1 line.
In general I try to avoid variadics since error messages are
horrible(e.g. std::make_unique
error messages when class has many constructors), but it is sometimes
necessary in libraries so it may be a good idea to add it.
I wanted to check the library a bit more with regards to this, but got
distracted doing something else so here is unrelated question:
Question probably stems from my lack of understanding why are we hashing
size of ranges(tried googling if other languages do this, was unable to
find info about that), but maybe example is best:
int main() {
std::array<char, 3> arr = {'a', 'b', 'c'};
const std::span<char, 3> sp(arr);
assert(sp.size()==3);
{
boost::hash2::fnv1a_32 h;
hash_append_range(h, {}, sp.begin(), sp.end());
std::print("iters hash is {}\n", h.result());
}
{
boost::hash2::fnv1a_32 h;
hash_append_range(h, {}, sp.begin(), sp.end());
hash_append(h, {}, size_t{3});
std::print("iters + size hash is {}\n", h.result());
}
{
boost::hash2::fnv1a_32 h;
hash_append(h, {}, sp);
std::print("range hash is {}\n", h.result());
}
}
prints
>
iters hash is 440920331
iters + size hash is 1187447304
range hash is 1187447304
My question is the following:
After reading the documentation I understand that hash_append for
std::span (more
precisely for concept it satisfies) also hashes it's size, but it is not
clear why is that desired behavior.
I am probably missing something obvious but if I saw somebody passing
std::span<char> to hash_append I would assume that it would just hash each
byte in that span and do nothing else.
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk