Boost.Hana  1.7.1
Your standard library for metaprogramming
Hashable

The Hashable concept represents objects that can be normalized to a type-level hash.

In day to day programming, hashes are very important as a way to efficiently lookup objects in maps. While the implementation of maps is very different, the same idea of using hashes for efficient lookup applies in metaprogramming. The Hashable concept represents objects that can be summarized (possibly with loss of information) to a type, in a way suitable for use in hash-based data structures. Of course, in order for a hash to be well-behaved, it must obey some laws that are explained below.

Minimal complete definition

hash, satisfying the laws below

Laws

First, hana::hash must return a hana::type. Furthermore, for any two Hashable objects x and y, it must be the case that

x == y implies hash(x) == hash(y)

where == denotes hana::equal. In other words, any two objects that compare equal (with hana::equal) must also have the same hash. However, the reverse is not true, and two different objects may have the same hash. This situation of two different objects having the same hash is called a collision.

Concrete models

hana::integral_constant, hana::type, hana::string

Free model for <tt>IntegralConstant</tt>s

Any IntegralConstant is Hashable, by normalizing its value to a hana::integral_constant. The type of the value held in the normalized integral_constant is unsigned long long for unsigned integral types, and signed long long for signed integral types.