Thanks Howard.
I've used N3980-like constructs in other projects and indeed found it
to be more pleasant to work with overall, and with fewer bugs. Good to
know that it'll solve the basic_string problem as well, if adopted.
-- on N3980 --
An issue I have with N3980 as written is that you always hash_append
the string's size (same with other containers), which means that a
hasher over a buffer of UTF-8 bytes produces different results than a
hash of a std::basic_string of UTF-8 characters; it would be ideal if
the user had a way to select whether they wanted that extra metadata
to be included or not. I often need a hash of the contents using a
known algorithm, not the metadata, especially when inter-operating
with other libraries or tools that only hash the contents.
Another case might be hashing a vector of string fragments against a
fully-assembled string, which I have encountered here and there
(especially when comparing paths, where you may not want to allocate a
string just to assemble a path when you already know the component
pieces).
The variants of N3980 I've written for myself just leaves out the
metadata, as the concerns over uniqueness are moot for my common uses
in game engines. I'm not sure what the most ergonomic extensibility
mechanism might be, but something that does the equivalent of:
template <class HashAlgorithm, class T, class Alloc>
void
hash_append(HashAlgorithm& h, std::vector<T, Alloc> const& v) noexcept
{
for (auto const& t : v)
hash_append(h, t);
if (h.uses_metadata())
hash_append(h, v.size());
}
// override siphash to avoid use of metadata like container sizes
struct MyHash : std::siphash
{
constexpr bool uses_metadata() const { return false; }
};
using hasher = uhash<MyHash>;
assert(hasher{}(vector<string>({"ab", "cd"})) == hasher{}(string{"abcd"}));
That also lets a user write a version of the hash algorithm that makes
its metadata choice at runtime, if they need it.
Apologies if this has already been brought up; my Google-fu on the ISO
groups is failing me and I'm not finding the previous discussions on
the paper, though I know I've seen them before.
> --
>
> ---
> You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Discussion" group.
> To unsubscribe from this topic, visit
https://groups.google.com/a/isocpp.org/d/topic/std-discussion/gtfSBtckVEQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
std-discussio...@isocpp.org.
> To post to this group, send email to
std-dis...@isocpp.org.
> Visit this group at
http://groups.google.com/a/isocpp.org/group/std-discussion/.
--
Sean Middleditch
http://seanmiddleditch.com