#Type Arrays

1 messages · Page 1 of 1 (latest)

timber gyro
#

no

red sleet
#

You can pass a tuple

frigid gulch
#

why not anytype? (or am I missing something subtle in the question?)

#

sorry I may be misunderstanding ... I was thinking you were asking about a function that could accept arrays of various types .... but I think you are meaning an array consisting of a mixture of types....

#

sorry for my noise.

#

yeah.... my bad... not the first ... surely not the last either, cheers

bronze flint
#

arrays and slices can only have one element type and are accessed by multiplying the index by the size of the element type, tuples can have any type at each index, but accesses must use a comptime-known index so that it can compute the correct offset

#

so if you accept an anytype parameter and only use comptime-known indices, then the function will work with any of these types

red sleet
#

The type of foo[i] has to be known at compile time. Erego, i has to be compile-time known, since it could be any type in the tuple

bronze flint
#

inline for is a comptime loop, for is a runtime loop

#

also "array of types" sounds like []type which I assume is not what you meant

grim lake
#

you can pass an array of types:

fn takesTypes(comptime array: []const type) void {
  var x: array[0] = undefined;
  var y: array[1] = undefined;
}

😛