添加约束到协议的“associatedtype”

时间:2016-10-02 21:05:44

标签: swift protocols associated-types

考虑以下代码:

protocol __Strideable {
    associatedtype Stride
}

struct __ClosedRangeIndex<Bound: __Strideable> where Bound.Stride: SignedInteger {
}

protocol __ClosedRangeType {
    associatedtype Bound: __Strideable

    // Error: Type 'Self._Bound.Stride' does not conform to protocol 'SignedInteger'
    var startIndex: __ClosedRangeIndex<Bound> { get }
}

是否可以向associatedtype添加约束?

像: associatedtype _Bound: __Strideable where _Bound.String: SignedInteger? (那个人显然没有工作)

0 个答案:

没有答案