efficient / libcuckoo

A high-performance, concurrent hash table
Other
1.61k stars 275 forks source link

swap must not be inside namespace std #116

Closed jk-jeon closed 4 years ago

jk-jeon commented 5 years ago

According to the C++ standard, it is not allowed to add an overload of any function inside the namespace std. Practically, I think adding an overload of std::swap for a user-defined type may almost never cause any problem, but technically speaking this is strictly banned by the standard and can lead to an undefined behavior.

AFAIK, the idiomatic way of "specializing" functions like std::swap is to rely on ADL. That means, the "specialization" of swap must be inside the namespace where cuckoohash_map is defined. Since cuckoohash_map is inside the global namespace, its corresponding swap should also be inside the global namespace. This sounds not good, and I strongly suggest you to wrap everything in this library inside a namespace.

manugoyal commented 4 years ago

Good point! I wrapped everything inside a libcuckoo namespace, and put the swap specialization inside this namespace. c75a843f079315ba3fd6b53a992755fa2a15a1bb.