Add solutions

This commit is contained in:
Laurens Miers 2024-09-25 15:26:17 +02:00
parent 7417f01d5d
commit b056b6ad81
96 changed files with 229 additions and 166 deletions

View file

@ -82,14 +82,14 @@ fn printTuple(tuple: anytype) void {
// @typeInfo(Circle).Struct.fields
//
// This will be an array of StructFields.
const fields = ???;
const fields = @typeInfo(@TypeOf(tuple)).Struct.fields;
// 2. Loop through each field. This must be done at compile
// time.
//
// Hint: remember 'inline' loops?
//
for (fields) |field| {
inline for (fields) |field| {
// 3. Print the field's name, type, and value.
//
// Each 'field' in this loop is one of these:
@ -117,9 +117,9 @@ fn printTuple(tuple: anytype) void {
//
// The first field should print as: "0"(bool):true
print("\"{s}\"({any}):{any} ", .{
field.???,
field.???,
???,
field.name,
field.type,
@field(tuple, field.name),
});
}
}