[swift-dev] SR-122 / CollectionsMoveIndices.swift Prototype

Shawn Erickson shawnce at gmail.com
Wed Mar 9 18:06:34 CST 2016


On Wed, Mar 9, 2016 at 3:52 PM Shawn Erickson <shawnce at gmail.com> wrote:

Additionally when trying to provide `Strideable` optimized `Collection`
> default implementations I hit issues like the following (note
> `Collection.IndexDistance` minimally conforms to SignedInteger). I picked
> `Strideable` as the optimization point since `RandomAccessCollection.Index`
> minimally conforms to `Strideable` and `Strideable` provides the first
> level of possible optimizations after `Comparable`.
>
> extension Collection where Index : Strideable {
>   public func next(i: Index) -> Index {
>     return i.advanced(by: 1) <— this is ok
>   }
>   public func advance(i: Index, by n: IndexDistance) -> Index {
>     return i.advanced(by: n) <— this errors
>   }
>> }
>
> error: cannot invoke 'advanced' with an argument list of type '(by:
> Self.IndexDistance)'
>     return i.advanced(by: n)
>              ^
> note: expected an argument list of type '(by: Self.Index.Stride)'
>     return i.advanced(by: n)
>

Actually as soon as I sent that I realized I was looking at the error
backwards... Strideable's advanced(by:) takes something that conforms to
SignedNumber. IndexDistance is a SignedInteger which does conform to
SignedNumber. So am I hitting a limit of the compiler? ...or missing
something obvious here?

————————————————————————————————————————
Equatable
  ^
Comparable
  ^
Strideable (associatedtype Stride : SignedNumber) ->
advanced(by:Self.Stride) & distance(to: Self)
  ^
  ^              SignedNumber
  ^                 ^
Integer & _SignedInteger —> func toIntMax()
  ^
SignedInteger —> func toIntMax()
————————————————————————————————————————

-Shawn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160310/7690ce89/attachment.html>


More information about the swift-dev mailing list