| | 1176 | } |
|---|
| | 1177 | |
|---|
| | 1178 | /** |
|---|
| | 1179 | True if a type defines an elaborate copy constructor. Elaborate copy |
|---|
| | 1180 | constructors are introduced by defining $(D this(this)) for a $(D |
|---|
| | 1181 | struct). (Non-struct types do not have elaborate copy constructors.) |
|---|
| | 1182 | */ |
|---|
| | 1183 | template hasElaborateCopyConstructor(T) |
|---|
| | 1184 | { |
|---|
| | 1185 | enum hasElaborateCopyConstructor = is(typeof(&T.__postblit)); |
|---|
| | 1186 | } |
|---|
| | 1187 | |
|---|
| | 1188 | unittest |
|---|
| | 1189 | { |
|---|
| | 1190 | static assert(!hasElaborateCopyConstructor!int); |
|---|
| | 1191 | struct S |
|---|
| | 1192 | { |
|---|
| | 1193 | this(this) {} |
|---|
| | 1194 | } |
|---|
| | 1195 | static assert(hasElaborateCopyConstructor!S); |
|---|
| | 1196 | } |
|---|
| | 1197 | |
|---|
| | 1198 | /** |
|---|
| | 1199 | True if a type defines an elaborate assignmentq. Elaborate |
|---|
| | 1200 | assignments are introduced by defining $(D opAssign(typeof(this))) |
|---|
| | 1201 | or $(D opAssign(ref typeof(this))) for a $(D struct). (Non-struct |
|---|
| | 1202 | types do not have elaborate assignments.) |
|---|
| | 1203 | */ |
|---|
| | 1204 | template hasElaborateAssign(T) |
|---|
| | 1205 | { |
|---|
| | 1206 | enum hasElaborateAssign = is(typeof(T.init.opAssign(T.init))); |
|---|
| | 1207 | } |
|---|
| | 1208 | |
|---|
| | 1209 | unittest |
|---|
| | 1210 | { |
|---|
| | 1211 | static assert(!hasElaborateAssign!int); |
|---|
| | 1212 | struct S { void opAssign(S) {} } |
|---|
| | 1213 | static assert(hasElaborateAssign!S); |
|---|
| | 1214 | struct S1 { void opAssign(ref S1) {} } |
|---|
| | 1215 | static assert(hasElaborateAssign!S1); |
|---|
| | 1216 | struct S2 { void opAssign(S1) {} } |
|---|
| | 1217 | static assert(!hasElaborateAssign!S2); |
|---|