std.BoundedArray simple dropin replacement

This thread is a good example IMHO:

If a max capacity of some item collection can be estimated upfront and isn’t too big, than a nested array + length is often much easier (and safer) to work with than a slice.

Now the old nested BoundedArray as it is also wouldn’t help all that much because it can’t be directly assigned from a Zig array.

Another situation where I used BoundedArray is to gather cmdline args in build.zigs, I have replaced this now with ArrayListUnmanaged which isn’t a big deal, but it would be nicer if a replacement would require less rather than more code (and I also instinctively don’t like that there’s some separate data blob dangling off the ‘main struct’ and I also don’t like sprinkling my code with ‘undefined’).

New:

Old:

TL;DR: for situations where I just need to throw a low number of items into an array (up to a few dozen maybe), but at the same time need to track the number of occupied slots in the array I was usually reaching for BoundedArray (since it’s just that: a fixed-size array and a length).