[swift-evolution] Yet another fixed-size array spitball session

Dave Abrahams dabrahams at apple.com
Fri Jun 2 09:26:21 CDT 2017


on Fri Jun 02 2017, Brent Royal-Gordon <swift-evolution at swift.org> wrote:

>> On May 28, 2017, at 11:37 PM, Daryle Walker via swift-evolution
>> <swift-evolution at swift.org> wrote:
>> 
>> Static-Sized Arrays
>
> My preference would still be to build this from four separate features:
>
> 1. Magic tuple conformances: We already want to be able to
> automatically conform tuples to protocols like Equatable, Hashable,
> and Comparable. These can all be compiler magic; they don't have to be
> definable in userspace.
>
> 2. Conform tuples to Collection: The Element type should be the most
> specific common supertype of the tuple's elements. If all the elements
> are the same type, it would be that type. The Index and IndexDistance
> types should be Int.
>
> 3. Conform same-type tuples to MutableCollection: If all elements are
> the same type, you can also modify the values. (If their types vary in
> any way, however, it would not be safe to allow mutations, since you
> could assign the wrong type to an element.)
>
> 3. Add sugar for a tuple of N identical elements: Probably something
> like `4 * Int`, but opinions can vary.

I think any complete solution depends on at least two more things:

1. adding the ability to get an UnsafePointer to an immutable instance
   of value type

2. support for leaving some of the elements uninitialized, or
   alternatively, a variation of this type that is RangeReplaceable but
   also bounded in capacity.

-- 
-Dave



More information about the swift-evolution mailing list