In public headers it's better to add parentheses around std::min/max
because on Windows, these can be treated as the (in)famous min/max
macros from Windows SDK (minwindef.h) if the user doesn't define
NOMINMAX.
The unordered_set:reserve() can be expected to do that already. But
for our (numBuckets) constructors, we need to do the check ourselves.
Change-Id: I04e1d56e14abec1f530ecfd181eb20a97445c698
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/88301
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
DuplicateTracker transparently wraps std::pmr::unordered_map with a
std::pmr::monotonic_memory_resource in a non-copyable, non-movable
class with a narrowly-focussed API (basically, hasSeen()). If C++17
<memory_resource> isn't available, it falls back to the default
std::allocator.
This is the third iteration of this class. The first was
QDuplicateTracker in Qt, which suffers from too small a static buffer,
and a very restricted API.
The second iteration was developed in a customer project and got the
size of the static buffer (almost) right, as well as adding contains()
and set(). The latter was made possible because, unlike
QDuplicateTracker, this version always used std::unordered_set, just
with different allocators, so the interface and semantics of
decltype(set()) no longer varied wildly between C++17 and C++14
builds.
In this third iteration, I factored the preallocated storage into a
separate base class, to allow more implementation sharing between
DuplicateTracker<T, N>s with same T, but different N. It also adds
template arguments for the Hash and Equal template arguments (which is
important when you don't, yet, use Qt 5.15, because then you might
want to pass KDToolBox::QtHasher). Lastly, it exposes the
unordered_set(N) ctor, so we can control the bucket_count() already at
construction time, which means we no longer waste a default-sized
bucket list allocated from the monotonic_buffer_resource when
default-constructing a DuplicateTracker and then calling reserve().
Change-Id: Iaf7bd1d2291796e05beb36fef7172aed0c3e6c1f
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/88299
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>