CppCon 2014: Howard Hinnant "Types Don't Know #"
Why Stack Overflow recommends it
Stack Overflow users link it when answering C++ questions about hashing user-defined types and object graphs, as the reference for the hash_append design.
Recommended by 1 people across 1 different months, 2015 to 2016.
What it is
A CppCon 2014 talk by Howard Hinnant, lead author of several C++11 features, presenting his proposal for a hashing infrastructure that separates hashing algorithms from the types being hashed. It covers the hash_append approach, where type authors, algorithm authors and clients each work independently.
What people said
Recommends sehe · 2016-04 · Stack Overflow · on “C++ - Hash value of object graph similar to boost::serialization”
I did exactly that once: Hash an arbitrary precision value (boost::multiprecision::cpp_int) [LINK] Also required reading: Types Don't Know # [LINK] with the talk on YT: [this video]
Cites TemplateRex · 2015-09 · Stack Overflow · on “where should I put the specialized std::hash for user defined type”
There are several ways. Specializing std::hash In your code make sure that your std::hash<Instance> specialization is preceded immediately by the Instance class definition, and followed by the use of the unordered_set container that uses it. namespace ca { class Instance {...}; } namespaces std { template<> hash<Instance> { ... }; } namespace ca { class InstanceManager { // ... some other things. private unordered_set<Instance>; } } One drawback is that you can have funny name lookup interference when passing a std::hash<ca::Instance> to other functions. The reason is that the associated namespace ( ca ) of all the template arguments of std::hash can be used during name lookup (ADL). Such er
Cites Howard Hinnant · 2016-02 · Stack Overflow · on “migrate a template to c++11 variadic template”
Here is an approximation, but I'm using hash_append documented here: N3980 [LINK] Presentation [this video] Slides [LINK] github library [LINK] which makes things both simpler and far more flexible. #include "hash_append.h" #include <memory> #include <tuple> template <typename T, typename ARG1, typename ARG2, typename ...Args> class Base { public: Base(const std::shared_ptr<ARG1>& arg1, const std::shared_ptr<ARG2>& arg2, const std::shared_ptr<Args>& ...args) : mArgs(arg1, arg2, args...) { } template <class H> friend void hash_append(H& h, const Base& b) { hash_append(h, b.mArgs); } protected: std::tuple<std::shared_ptr<ARG1>, std::shared_ptr<ARG2>, std::shared_ptr<Args>...> mArgs; }; I arbitraril