greg7mdp / parallel-hashmap

A family of header-only, very fast and memory-friendly hashmap and btree containers.
https://greg7mdp.github.io/parallel-hashmap/
Apache License 2.0
2.53k stars 239 forks source link

Only reference Alloc swap if permitted by AllocTraits #187

Closed BurningEnlightenment closed 1 year ago

BurningEnlightenment commented 1 year ago

Describe the bug The following code fails to compile with std::pmr::polymorphic_allocator or any allocator without a swap implementation: https://github.com/greg7mdp/parallel-hashmap/blob/f5e1638a912cdb83fde49ed4611acf9832b54586/parallel_hashmap/phmap.h#L1660-L1665

To Reproduce Compile the following code with C++17 or higher

#include <memory_resource>
#include <utility>

#include <parallel_hashmap/phmap.h>

template <typename K, typename T>
using pmrmap = phmap::flat_hash_map<K, T, std::hash<K>, std::equal_to<>, std::pmr::polymorphic_allocator<std::pair<const K, T>>>;

int main()
{
    pmrmap<int, int> m1;
    pmrmap<int, int> m2;
    using std::swap;
    swap(m1, m2);
}

Expected behavior No compiler errors (the UB in case of mismatching allocators is fine, however, in this case we do have matching allocators).

Environment OS Compiler project version
Windows 10 MSVC 19.35.32216.1 v1.3.8
Ubuntu 22.04.1 LTS GCC 11.3.0 v1.3.8

Additional context This is sort of a continuation of #128.

greg7mdp commented 1 year ago

Thanks for the report, @BurningEnlightenment , issue should be fixed now. I'm closing it, but feel free to reopen if not fully fixed.