@@ -21,9 +21,13 @@ $(HEADERNAV_TOC)
21
21
assert(value == 3);
22
22
---------
23
23
24
- $(P $(BLUE $(B Note:)) The built-in associative arrays do not preserve the order
24
+ $(P Neither the $(I KeyType)s nor the element types of an associative
25
+ array can be function types or $(D void).
26
+ )
27
+
28
+ $(IMPLEMENTATION_DEFINED The built-in associative arrays do not preserve the order
25
29
of the keys inserted into the array. In particular, in a $(D foreach) loop the
26
- order in which the elements are iterated is unspecified.)
30
+ order in which the elements are iterated is typically unspecified.)
27
31
28
32
$(H2 $(LNAME2 removing_keys, Removing Keys))
29
33
@@ -59,9 +63,8 @@ $(H2 $(LNAME2 testing_membership, Testing Membership))
59
63
}
60
64
---------
61
65
62
- $(P Neither the $(I KeyType)s nor the element types of an associative
63
- array can be function types or $(D void).
64
- )
66
+ $(UNDEFINED_BEHAVIOR Adjusting the pointer to point before or after
67
+ the element whose address is returned, and then dereferencing it.)
65
68
66
69
$(H2 $(LNAME2 using_classes_as_key, Using Classes as the KeyType))
67
70
@@ -94,17 +97,27 @@ $(H2 $(LNAME2 using_classes_as_key, Using Classes as the KeyType))
94
97
}
95
98
---
96
99
97
- $(P Care should be taken that $(D toHash) should consistently be the
98
- same value when $(D opEquals) returns true. In other words, two objects
99
- that are considered equal should always have the same hash value. If
100
- this is not the case, the associative array will not function properly.
101
- Also note that $(D opCmp) is not used to check for equality by the
102
- associative array. However, since the actual $(D opEquals) or
100
+ $(IMPLEMENTATION_DEFINED
101
+ `opCmp` is not used to check for equality by the
102
+ associative array. However, since the actual `opEquals` or
103
103
`opCmp` called is not decided until runtime, the compiler cannot always
104
104
detect mismatched functions. Because of legacy issues, the compiler may
105
- reject an associative array key type that overrides $(D opCmp) but not
106
- $(D opEquals). This restriction may be removed in future versions of
107
- D.)
105
+ reject an associative array key type that overrides `opCmp` but not
106
+ `opEquals`. This restriction may be removed in future versions.)
107
+
108
+ $(UNDEFINED_BEHAVIOR
109
+ $(OL
110
+ $(LI If $(D toHash) must consistently be the
111
+ same value when $(D opEquals) returns true. In other words, two objects
112
+ that are considered equal should always have the same hash value.
113
+ Otherwise, undefined behavior will result.)
114
+ ))
115
+
116
+ $(BEST_PRACTICE
117
+ $(OL
118
+ $(LI Use the attributes `@safe`, `@nogc`, `pure`, `const`, and `scope` as much as possible
119
+ on the `toHash` and `opEquals` overrides.)
120
+ ))
108
121
109
122
$(H2 $(LNAME2 using_struct_as_key, Using Structs or Unions as the KeyType))
110
123
@@ -144,18 +157,29 @@ $(H2 $(LNAME2 using_struct_as_key, Using Structs or Unions as the KeyType))
144
157
}
145
158
---------
146
159
147
- $(P Care should be taken that $(D toHash) should consistently be the
148
- same value when $(D opEquals) returns true. In other words, two structs
149
- that are considered equal should always have the same hash value. If
150
- this is not the case, the associative array will not function properly.)
151
- $(P If necessary the functions can use $(D @trusted) instead of $(D @safe).)
152
- $(P Also note that $(D opCmp) is not used to check for equality by the
160
+ $(P The functions can use $(D @trusted) instead of $(D @safe).)
161
+
162
+ $(IMPLEMENTATION_DEFINED `opCmp` is not used to check for equality by the
153
163
associative array. For this reason, and for legacy reasons, an
154
164
associative array key is not allowed to define a specialized `opCmp`,
155
- but omit a specialized $(D opEquals) . This restriction may be
165
+ but omit a specialized ` opEquals` . This restriction may be
156
166
removed in future versions of D.)
157
167
158
- $(H2 $(LNAME2 construction_assignement_entries, Construction or Assignment on Setting AA Entries))
168
+ $(UNDEFINED_BEHAVIOR
169
+ $(OL
170
+ $(LI If $(D toHash) must consistently be the
171
+ same value when $(D opEquals) returns true. In other words, two structs
172
+ that are considered equal should always have the same hash value.
173
+ Otherwise, undefined behavior will result.)
174
+ ))
175
+
176
+ $(BEST_PRACTICE
177
+ $(OL
178
+ $(LI Use the attributes `@nogc` as much as possible
179
+ on the `toHash` and `opEquals` overrides.)
180
+ ))
181
+
182
+ $(H2 $(LNAME2 construction_assignment_entries, Construction or Assignment on Setting AA Entries))
159
183
160
184
$(P When an AA indexing access appears on the left side of an assignment
161
185
operator, it is specially handled for setting an AA entry associated with
0 commit comments