maliput
hash_append generic hashing

Drake uses the hash_append pattern as described by N3980.

For a full treatment of the hash_append pattern, refer to: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3980.html

Providing hash_append support within a class

Drake types may implement a hash_append function. The function appends every hash-relevant member field into the hasher:

class MyValue {
public:
...
/// Implements the @ref hash_append concept.
template <class HashAlgorithm>
friend void hash_append(
HashAlgorithm& hasher, const MyValue& item) noexcept {
hash_append(hasher, item.my_data_);
}
...
private:
std::string my_data_;
};

Checklist for reviewing a hash_append implementation:

Using hashable types

Types that implement this pattern may be used in unordered collections:

std::unordered_set<MyValue, maliput::drake::DefaultHash> foo;

Some Drake types may also choose to specialize std::hash<MyValue> to use DefaultHash, so that the second template argument to std::unordered_set can be omitted. For example, Drake's symbolic::Expression header says:

namespace std {
struct hash<maliput::drake::symbolic::Expression> : public maliput::drake::DefaultHash {};
} // namespace std

so that users are able to simply write:

std::unordered_set<maliput::drake::symbolic::Expression> foo;
maliput
Code in this file is inspired by: https://github.com/RobotLocomotion/drake/blob/master/common/text_lo...
Definition: basic_id_index.h:41
maliput::drake::hash_append
std::enable_if_t< std::is_integral_v< T > > hash_append(HashAlgorithm &hasher, const T &item) noexcept
Provides hash_append generic hashing for integral constants.
Definition: hash.h:78
maliput::drake::uhash
A hashing functor, somewhat like std::hash.
Definition: hash.h:172
maliput::common::hash_append
std::enable_if_t< std::is_integral< T >::value > hash_append(HashAlgorithm &hasher, const T &item) noexcept
Provides hash_append generic hashing for integral constants.
Definition: maliput_hash.h:131