You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- If k1 \== k2 is true, h(k1) \== h(k2) is also true.
74
+
- If `k1 == k2` is true, `h(k1) == h(k2)` is also true.
75
75
- Unless `std::hash<Key>` is a [program-defined specialization](../language/type-id.html#Program-defined_type"cpp/language/type"), h(k1) will never throw an exception.
76
76
77
77
- Otherwise, `std::hash<Key>` is disabled.
@@ -100,8 +100,8 @@ In other words, they exist, but cannot be used.
100
100
### Member functions
101
101
|||
102
102
|---|---|
103
-
|`constuctor`| constructs a hash function object <br/> (public member function)|
104
-
|`operator()`| calculates the hash of the argument <br/> (public member function)|
103
+
|(constuctor)|<Desckind="public member function">constructs a hash function object </Desc>|
104
+
|[`operator()`](./operator-call/)|<Desckind="public member function">calculates the hash of the argument </Desc>|
Specializations of `std::hash` should define an `operator()` that:
11
+
12
+
- Takes a single argument key of type `Key`.
13
+
- Returns a value of type `std::size_t` that represents the hash value of key.
14
+
- For two parameters `k1` and `k2` that are equal, `std::hash<Key>()(k1) == std::hash<Key>()(k2)`.
15
+
- For two different parameters `k1` and `k2` that are not equal, the probability that `std::hash<Key>()(k1) == std::hash<Key>()(k2)` should be very small, approaching `1.0 / std::numeric_limits<size_t>::max()`.
16
+
17
+
18
+
## Parameters
19
+
<ParamDocList>
20
+
<ParamDocname="key">
21
+
the object to be hashed
22
+
</ParamDoc>
23
+
</ParamDocList>
24
+
25
+
## Return value
26
+
A `std::size_t` representing the hash value.
27
+
28
+
## Exceptions
29
+
Hash functions should not throw exceptions.
30
+
31
+
## Example
32
+
The following code shows how to specialize the std::hash template for a custom class. The hash function uses Fowler–Noll–Vo hash algorithm.
0 commit comments