Is there a way to do array literal initialisation of a generic type with a value?
Imagine I have a type similar to the new InlineArray
. For example, let's say I have something like this:
struct MyType<let count: Int, Component: BinaryFloatingPoint> {
}
I want users to be able to initialize this from an array literal, perhaps by conforming to ExpressibleByArrayLiteral
.
So this would allow users to do this:
let myType: MyType = [0.0, 1.0, 2.0, 3.0]
This would then assume that the type of MyType
that has been created is equivalent to MyType<4, Double>
, as the initial array used to populate it has 4 doubles.
Of course right now, I can't do that as it can't determine the value of count
.
Is there another protocol or another approach that will allow me to do what I'm looking for? So the array you pass in is used to initialise both the size of the value, and the number of components it contains?