Skip to content

Commit 4312b41

Browse files
authored
[spec/struct] Improve Members section (#4346)
Merge struct and union member lists into table. Add bitfields entry, remove note (`std.bitmanip.bitfields` is still mentioned in bitfields section). Add copy constructors & postblits entries. Move note about bit copies and bitfields to Structs. Move union member limitations section to subheading, mention field destruction.
1 parent 64d1f2b commit 4312b41

File tree

1 file changed

+28
-51
lines changed

1 file changed

+28
-51
lines changed

spec/struct.dd

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ void main()
5656
$(P Assigning (or initializing) a struct instance from an
5757
$(DDSUBLINK spec/expression, .define-lvalue, lvalue) will copy the original struct.)
5858

59+
$(P A struct is defined to not have an identity; that is,
60+
the implementation is free to make bit copies of the struct
61+
as convenient.)
62+
5963
$(H3 $(LNAME2 storage, Storage))
6064

6165
$(P For local variables, a struct/union instance is allocated on the stack
@@ -116,56 +120,33 @@ void main()
116120
---
117121
)
118122

119-
$(H2 $(LNAME2 members, Members))
120-
121-
$(H3 $(LNAME2 struct-members, Struct Members))
122-
123-
$(P A struct definition can contain:)
124-
$(UL
125-
$(LI Fields)
126-
$(LI $(DDSUBLINK spec/attribute, static, Static) fields)
127-
$(LI $(RELATIVE_LINK2 anonymous, Anonymous Structs and Unions))
128-
$(LI $(RELATIVE_LINK2 member-functions, Member Functions)
129-
$(UL
130-
$(LI $(DDSUBLINK spec/attribute, static, Static) member functions)
131-
$(LI $(RELATIVE_LINK2 struct-constructor, Constructors))
132-
$(LI $(RELATIVE_LINK2 struct-destructor, Destructors))
133-
$(LI $(RELATIVE_LINK2 Invariant, Invariants))
134-
$(LI $(DDLINK spec/operatoroverloading, Operator Overloading, Operator Overloading))
135-
)
136-
$(LI $(RELATIVE_LINK2 alias-this, Alias This))
137-
$(LI Other declarations (see $(GLINK2 module, DeclDef)))
138-
)
123+
$(ADEF union-members)
124+
$(H2 $(LEGACY_LNAME2 struct-members, members, Members))
125+
126+
$(P The following table shows which declarations a struct or union can contain:)
127+
$(TABLE
128+
$(THEAD Members, Struct, Union)
129+
$(TROW Fields, $(YES), $(YES))
130+
$(TROW $(RELATIVE_LINK2 bitfields, Bit Fields), $(YES), $(YES))
131+
$(TROW $(DDSUBLINK spec/attribute, static, Static) fields, $(YES), $(YES))
132+
$(TROW $(RELATIVE_LINK2 anonymous, Anonymous Structs and Unions), $(YES), $(YES))
133+
$(TROW $(RELATIVE_LINK2 member-functions, Member Functions), $(YES), $(YES))
134+
$(TROW $(DDSUBLINK spec/attribute, static, Static) member functions, $(YES), $(YES))
135+
$(TROW $(RELATIVE_LINK2 struct-constructor, Constructors), $(YES), $(YES))
136+
$(TROW $(RELATIVE_LINK2 struct-copy-constructor, Copy Constructors), $(YES), $(YES))
137+
$(TROW $(RELATIVE_LINK2 struct-postblit, Postblits), $(YES), $(NO))
138+
$(TROW $(RELATIVE_LINK2 struct-destructor, Destructors), $(YES), $(NO))
139+
$(TROW $(RELATIVE_LINK2 Invariant, Invariants), $(YES), $(NO))
140+
$(TROW $(DDLINK spec/operatoroverloading, Operator Overloading, Operator Overloading), $(YES), $(YES))
141+
$(TROW $(RELATIVE_LINK2 alias-this, Alias This), $(YES), $(YES))
142+
$(TROW Other declarations (see $(GLINK2 module, DeclDef)), $(YES), $(YES))
139143
)
140144

141-
$(P A struct is defined to not have an identity; that is,
142-
the implementation is free to make bit copies of the struct
143-
as convenient.)
144-
145-
$(NOTE
146-
$(OL
147-
$(LI Native bit fields are supported with $(RELATIVE_LINK2 bitfields, Bit Field Declarations))
148-
$(LI A library implementation of bit fields is available with the
149-
$(LINK2 https://dlang.org/phobos/std_bitmanip.html#bitfields, bitfields) template.)
150-
))
151-
152-
$(H3 $(LNAME2 union-members, Union Members))
145+
$(H3 $(LNAME2 unions_and_special_memb_funct, Union Limitations))
153146

154-
$(P A union definition can contain:)
155-
$(UL
156-
$(LI Fields)
157-
$(LI $(DDSUBLINK spec/attribute, static, Static) fields)
158-
$(LI $(RELATIVE_LINK2 anonymous, Anonymous Structs and Unions))
159-
$(LI $(DDSUBLINK spec/class, member-functions, member functions)
160-
$(UL
161-
$(LI static member functions)
162-
$(LI $(RELATIVE_LINK2 UnionConstructor, Constructors))
163-
$(LI $(DDLINK spec/operatoroverloading, Operator Overloading, Operator Overloading))
164-
)
165-
$(LI $(RELATIVE_LINK2 alias-this, Alias This))
166-
$(LI Other declarations (see $(GLINK2 module, DeclDef)))
167-
)
168-
)
147+
$(P Unions may not have postblits, destructors, or invariants.
148+
A constructed field with a destructor may need to be $(RELATIVE_LINK2 union-field-destruction,
149+
destroyed manually).)
169150

170151
$(H3 $(LNAME2 recursive-types, Recursive Structs and Unions))
171152

@@ -2779,10 +2760,6 @@ $(H2 $(LNAME2 nested, Nested Structs))
27792760
`.init` is not the same as default construction).)
27802761

27812762

2782-
$(H2 $(LNAME2 unions_and_special_memb_funct, Unions and Special Member Functions))
2783-
2784-
$(P Unions may not have postblits, destructors, or invariants.)
2785-
27862763
$(SPEC_SUBNAV_PREV_NEXT hash-map, Associative Arrays, class, Classes)
27872764
)
27882765

0 commit comments

Comments
 (0)