082_anonymous_structs3.patch 1008 B

1234567891011121314151617181920212223242526272829303132
  1. --- exercises/082_anonymous_structs3.zig 2024-08-04 15:57:16.753494020 +0200
  2. +++ answers/082_anonymous_structs3.zig 2024-09-02 19:30:00.967005314 +0200
  3. @@ -82,14 +82,14 @@
  4. // @typeInfo(Circle).Struct.fields
  5. //
  6. // This will be an array of StructFields.
  7. - const fields = ???;
  8. + const fields = @typeInfo(@TypeOf(tuple)).@"struct".fields;
  9. // 2. Loop through each field. This must be done at compile
  10. // time.
  11. //
  12. // Hint: remember 'inline' loops?
  13. //
  14. - for (fields) |field| {
  15. + inline for (fields) |field| {
  16. // 3. Print the field's name, type, and value.
  17. //
  18. // Each 'field' in this loop is one of these:
  19. @@ -117,9 +117,9 @@
  20. //
  21. // The first field should print as: "0"(bool):true
  22. print("\"{s}\"({any}):{any} ", .{
  23. - field.???,
  24. - field.???,
  25. - ???,
  26. + field.name,
  27. + field.type,
  28. + @field(tuple, field.name),
  29. });
  30. }
  31. }