Skip to content

Commit e92dc98

Browse files
authored
Merge pull request #4170 from MrcSnm/patch-4
Mention the existence of the .tupleof property Signed-off-by: Nicholas Wilson <thewilsonator@users.noreply.github.com> Merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2 parents 54ac61a + 1707ef7 commit e92dc98

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

spec/property.dd

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,34 @@ $(D object.TypeInfo_Class)).)
307307
$(P $(CODE .classinfo) applied to an interface gives the information for the
308308
interface, not the class it might be an instance of.)
309309

310+
$(H2 $(LNAME2 tupleof, .tupleof Property))
311+
312+
$(P $(CODE .tupleof) provides a symbol sequence of all the non-static fields in a struct or class.
313+
The order of the fields in the tuple matches the order in which the fields are declared.
314+
315+
For classes, hidden fields and fields of the bass class are excluded.
316+
317+
A common use case is to iterate over the fields with a $(CODE foreach) loop.)
318+
319+
---
320+
struct Vector3
321+
{
322+
int x, y, z;
323+
}
324+
325+
void test()
326+
{
327+
Vector3 v = Vector3(5, 10, 15);
328+
float sum = 0;
329+
foreach(num; v.tupleof)
330+
{
331+
sum+= num;
332+
}
333+
writeln(sum); //30
334+
}
335+
---
336+
337+
310338
$(H2 $(LNAME2 classproperties, User-Defined Properties))
311339

312340
$(P User-defined properties can be created using $(LINK2 function.html#property-functions, Property Functions).)

0 commit comments

Comments
 (0)