@@ -42,29 +42,23 @@ $(GNAME AnonymousEnumMember):
42
42
)
43
43
44
44
$(P Enum declarations are used to define a group of constants.
45
- They come in these forms:
46
- )
47
- $(OL
48
- $(LI Named enums, which have a name.)
49
- $(LI Anonymous enums, which do not have a name.)
50
- $(LI Manifest constants.)
51
45
)
52
46
53
47
$(H2 $(LNAME2 named_enums, Named Enums))
54
48
55
49
$(P
56
50
Named enums are used to declare related
57
51
constants and group them by giving them a unique type.
58
- The $(I EnumMembers) are declared in the scope of the named enum. The named
52
+ The $(GLINK EnumMembers) are declared in the scope of the named enum. The named
59
53
enum declares a new type, and all the $(I EnumMembers) have that type.
60
54
)
61
55
62
56
$(P This defines a new type $(CODE X) which has values
63
57
$(CODE X.A=0), $(CODE X.B=1), $(CODE X.C=2):)
64
58
65
- --- ---
66
- enum X { A, B, C } // named enum
67
- --- ---
59
+ ---
60
+ enum X { A, B, C } // named enum
61
+ ---
68
62
69
63
70
64
$(P If the $(I EnumBaseType) is not explicitly set, and the first
@@ -76,12 +70,12 @@ enum X { A, B, C } // named enum
76
70
)
77
71
78
72
79
- $(P A named enum member can be implicitly cast to its $(I EnumBaseType),
73
+ $(P A named enum member can be implicitly cast to its $(GLINK EnumBaseType),
80
74
but $(I EnumBaseType) types
81
75
cannot be implicitly cast to an enum type.
82
76
)
83
77
84
- $(P The value of an $(I EnumMember) is given by its $(ASSIGNEXPRESSION).
78
+ $(P The value of an $(GLINK EnumMember) is given by its $(ASSIGNEXPRESSION).
85
79
If there is no $(ASSIGNEXPRESSION) and it is the first $(I EnumMember),
86
80
its value is $(GLINK EnumBaseType)`.init`.
87
81
)
@@ -156,16 +150,16 @@ X.max // is X.C
156
150
X.sizeof // is same as int.sizeof
157
151
---
158
152
159
- $(P The $(I EnumBaseType) of named enums must support comparison
153
+ $(P The $(GLINK EnumBaseType) of named enums must support comparison
160
154
in order to compute the $(CODE .max) and $(CODE .min) properties.
161
155
)
162
156
163
157
164
158
$(H2 $(LNAME2 anonymous_enums, Anonymous Enums))
165
159
166
160
$(P If the enum $(I Identifier) is not present, then the enum
167
- is an $(I anonymous enum), and the $(I EnumMembers) are declared
168
- in the scope the $(I EnumDeclaration) appears in.
161
+ is an $(I anonymous enum), and the $(GLINK EnumMembers) are declared
162
+ in the scope the $(GLINK EnumDeclaration) appears in.
169
163
No new type is created.
170
164
)
171
165
@@ -175,7 +169,7 @@ $(H2 $(LNAME2 anonymous_enums, Anonymous Enums))
175
169
176
170
$(OL
177
171
$(LI The $(I Type), if present. Types are not permitted when an
178
- $(I EnumBaseType) is present.)
172
+ $(GLINK EnumBaseType) is present.)
179
173
$(LI The $(I EnumBaseType), if present.)
180
174
$(LI The type of the $(I AssignExpression), if present.)
181
175
$(LI The type of the previous $(I EnumMember), if present.)
@@ -187,7 +181,7 @@ $(H2 $(LNAME2 anonymous_enums, Anonymous Enums))
187
181
enum { A, B, C } // anonymous enum
188
182
------
189
183
190
- $(P Defines the constants A=0, B=1, C=2, all of type int.)
184
+ $(P Defines the constants A=0, B=1, C=2, all of type ` int` .)
191
185
192
186
$(P Enums must have at least one member.
193
187
)
@@ -214,13 +208,13 @@ enum { A, B, C } // anonymous enum
214
208
enum { A, B = 5+7, C, D = 8+C, E }
215
209
------
216
210
217
- $(P Sets A=0, B=12, C=13, D=21, and E=22, all of type int.)
211
+ $(P Sets A=0, B=12, C=13, D=21, and E=22, all of type ` int` .)
218
212
219
213
---
220
214
enum : long { A = 3, B }
221
215
---
222
216
223
- $(P Sets A=3, B=4 all of type long.)
217
+ $(P Sets A=3, B=4 all of type ` long` .)
224
218
225
219
---
226
220
enum : string
243
237
244
238
$(H2 $(LNAME2 manifest_constants, Manifest Constants))
245
239
246
- $(P If there is only one member of an anonymous enum, the { } can
240
+ $(P If there is only one member of an anonymous enum, the ` { }` can
247
241
be omitted. Gramatically speaking, this is an $(GLINK2 declaration, AutoDeclaration).
248
242
)
249
243
@@ -252,15 +246,14 @@ enum i = 4; // i is 4 of type int
252
246
enum long l = 3; // l is 3 of type long
253
247
---
254
248
255
- $(P Such declarations are not lvalues, meaning their address
249
+ $(P Manifest constants are not lvalues, meaning their address
256
250
cannot be taken. They exist only in the memory of the compiler.)
257
251
258
252
---
259
253
enum size = __traits(classInstanceSize, Foo); // evaluated at compile-time
260
254
---
261
255
262
- $(P Using manifest constants is an idiomatic D method
263
- to force compile-time evaluation of an expression.)
256
+ $(P The initializer for a manifest constant is evaluated using compile time function evaluation.)
264
257
265
258
---
266
259
template Foo(T)
0 commit comments