Fixed size array hacks

I'm curious of what you think about the need for and/or possibility of adding some small language feature to make working with homogeneous tuples less cumbersome.

  1. There is no nice / general way of writing them:

    • We can use textual repetition, manually or via eg gyb:

      typealias ArrayOf12Floats = (Float, Float, Float, Float, Float, Float, Float, Float, Float, Float, Float, Float)
      
    • or we can use bridged C types like:

      typedef float ArrayOf12Floats[12];
      
    • or we can use various recursive workarounds like the Adjoin struct in your prototype (which leads to nested tuple types (with the same memory layout as the simplest unnested form)).

  2. And to initialize them we have to jump through similar hoops.


I'm probably wrong, but it feels like some small natural addition to the language could remove the above two pain points, and thereby make something like your prototype and the one by @jrose work as a way to officially support static arrays in Swift.

1 Like