Skip to content

Commit 029f4c5

Browse files
authored
Merge pull request #2104 from WalterBright/enum-spec
enum.dd: minor touch-up merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
2 parents b6635f2 + 2929361 commit 029f4c5

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

spec/enum.dd

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,23 @@ $(GNAME AnonymousEnumMember):
4242
)
4343

4444
$(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.)
5145
)
5246

5347
$(H2 $(LNAME2 named_enums, Named Enums))
5448

5549
$(P
5650
Named enums are used to declare related
5751
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
5953
enum declares a new type, and all the $(I EnumMembers) have that type.
6054
)
6155

6256
$(P This defines a new type $(CODE X) which has values
6357
$(CODE X.A=0), $(CODE X.B=1), $(CODE X.C=2):)
6458

65-
------
66-
enum X { A, B, C } // named enum
67-
------
59+
---
60+
enum X { A, B, C } // named enum
61+
---
6862

6963

7064
$(P If the $(I EnumBaseType) is not explicitly set, and the first
@@ -76,12 +70,12 @@ enum X { A, B, C } // named enum
7670
)
7771

7872

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),
8074
but $(I EnumBaseType) types
8175
cannot be implicitly cast to an enum type.
8276
)
8377

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).
8579
If there is no $(ASSIGNEXPRESSION) and it is the first $(I EnumMember),
8680
its value is $(GLINK EnumBaseType)`.init`.
8781
)
@@ -156,16 +150,16 @@ X.max // is X.C
156150
X.sizeof // is same as int.sizeof
157151
---
158152

159-
$(P The $(I EnumBaseType) of named enums must support comparison
153+
$(P The $(GLINK EnumBaseType) of named enums must support comparison
160154
in order to compute the $(CODE .max) and $(CODE .min) properties.
161155
)
162156

163157

164158
$(H2 $(LNAME2 anonymous_enums, Anonymous Enums))
165159

166160
$(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.
169163
No new type is created.
170164
)
171165

@@ -175,7 +169,7 @@ $(H2 $(LNAME2 anonymous_enums, Anonymous Enums))
175169

176170
$(OL
177171
$(LI The $(I Type), if present. Types are not permitted when an
178-
$(I EnumBaseType) is present.)
172+
$(GLINK EnumBaseType) is present.)
179173
$(LI The $(I EnumBaseType), if present.)
180174
$(LI The type of the $(I AssignExpression), if present.)
181175
$(LI The type of the previous $(I EnumMember), if present.)
@@ -187,7 +181,7 @@ $(H2 $(LNAME2 anonymous_enums, Anonymous Enums))
187181
enum { A, B, C } // anonymous enum
188182
------
189183

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`.)
191185

192186
$(P Enums must have at least one member.
193187
)
@@ -214,13 +208,13 @@ enum { A, B, C } // anonymous enum
214208
enum { A, B = 5+7, C, D = 8+C, E }
215209
------
216210

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`.)
218212

219213
---
220214
enum : long { A = 3, B }
221215
---
222216

223-
$(P Sets A=3, B=4 all of type long.)
217+
$(P Sets A=3, B=4 all of type `long`.)
224218

225219
---
226220
enum : string
@@ -243,7 +237,7 @@ enum
243237

244238
$(H2 $(LNAME2 manifest_constants, Manifest Constants))
245239

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
247241
be omitted. Gramatically speaking, this is an $(GLINK2 declaration, AutoDeclaration).
248242
)
249243

@@ -252,15 +246,14 @@ enum i = 4; // i is 4 of type int
252246
enum long l = 3; // l is 3 of type long
253247
---
254248

255-
$(P Such declarations are not lvalues, meaning their address
249+
$(P Manifest constants are not lvalues, meaning their address
256250
cannot be taken. They exist only in the memory of the compiler.)
257251

258252
---
259253
enum size = __traits(classInstanceSize, Foo); // evaluated at compile-time
260254
---
261255

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.)
264257

265258
---
266259
template Foo(T)

0 commit comments

Comments
 (0)