#Unable to infer array size if I don't repeat it twice

1 messages · Page 1 of 1 (latest)

dusky herald
#

fails: foos: [_]?Foo = .{ null } ** ELEM_COUNT,
works: foos: [ELEM_COUNT]?Foo = .{ null } ** ELEM_COUNT,
How can I do this without repeating ELEM_COUNT twice?

hidden grove
dusky herald
#

Thanks!

#

Actually another related question; this is an element of another struct Bar:

const Bar = struct {
  foos: [ELEM_COUNT]?Foo = @splat(null),
};

how can I initialize a Bar with only one Foo without using ELEM_COUNT?

const bar = Bar{
  foos[0] ??? = .{...},
}
hidden grove
dusky herald
hidden grove
#

yep

#

but labelled blocks are great :)

dusky herald
#

Yeah, very flexible

hidden grove
#

you can do all sorts of complex initialization in them, without losing constness

#

and you can do it at comptime too if you want