Error[8]: Undefined offset: 3, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我试图转换以下 Swift 2.3代码: //Example usage://(0 ..< 778).binarySearch { $0 < 145 } // 145extension CollectionType where Index: RandomAccessIndexType { /// Finds such index N that predicate is true fo 我试图转换以下 Swift 2.3代码:
//Example usage://(0 ..< 778).binarySearch { 
//Example usage://(0 ..< 778).binarySearch { 
extension Collection {    func binarySearch(predicate: (Iterator.Element) -> Bool) -> Index {        var low = startIndex        var high = endindex        while low != high {            let mID = index(low,offsetBy: distance(from: low,to: high)/2)            if predicate(self[mID]) {                low = index(after: mID)            } else {                high = mID            }        }        return low    }}
< 145 } // 145extension Collection where Index: StrIDeable { /// Finds such index N that predicate is true for all elements up to /// but not including the index N,and is false for all elements /// starting with index N. /// Behavior is undefined if there is no such N. func binarySearch(predicate: (Generator.Element) -> Bool) -> Index { var low = startIndex var high = endindex while low != high { let mID = low.advanced(by: low.distance(to: high) / 2) if predicate(self[mID]) { low = mID.advanced(to: 1) } else { high = mID } } return low }}
< 145 } // 145extension CollectionType where Index: RandomAccessIndexType { /// Finds such index N that predicate is true for all elements up to /// but not including the index N,and is false for all elements /// starting with index N. /// Behavior is undefined if there is no such N. func binarySearch(predicate: Generator.Element -> Bool) -> Index { var low = startIndex var high = endindex while low != high { let mID = low.advancedBy(low.distanceto(high) / 2) if predicate(self[mID]) { low = mID.advancedBy(1) } else { high = mID } } return low }}

进入Swift 3如下:

[+++]

错误

Binary operator ‘/’ cannot be applIEd to operands of type ‘self.Index.StrIDe’ and ‘Int’

抛出让mID = low.advanced(by:low.distance(to:high)/ 2)

有关如何修复它的任何帮助?

在Swift 3中,“集合移动他们的索引”,比较
关于Swift进化的 A New Model for Collections and Indices.特别是,您不要在索引上调用advancedBy(),
但是在集合上使用index()方法来推进索引.

所以你的方法将在Swift 3中实现

[+++]

不需要对索引类型进行任何限制.

总结

以上是内存溢出为你收集整理的swift – Stridable Protocol全部内容,希望文章能够帮你解决swift – Stridable Protocol所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我试图转换以下 Swift 2.3代码: //Example usage://(0 ..< 778).binarySearch { $0 < 145 } // 145extension CollectionType where Index: RandomAccessIndexType { /// Finds such index N that predicate is true fo 我试图转换以下 Swift 2.3代码:
//Example usage://(0 ..< 778).binarySearch { 
//Example usage://(0 ..< 778).binarySearch { 
extension Collection {    func binarySearch(predicate: (Iterator.Element) -> Bool) -> Index {        var low = startIndex        var high = endindex        while low != high {            let mID = index(low,offsetBy: distance(from: low,to: high)/2)            if predicate(self[mID]) {                low = index(after: mID)            } else {                high = mID            }        }        return low    }}
< 145 } // 145extension Collection where Index: StrIDeable { /// Finds such index N that predicate is true for all elements up to /// but not including the index N,and is false for all elements /// starting with index N. /// Behavior is undefined if there is no such N. func binarySearch(predicate: (Generator.Element) -> Bool) -> Index { var low = startIndex var high = endindex while low != high { let mID = low.advanced(by: low.distance(to: high) / 2) if predicate(self[mID]) { low = mID.advanced(to: 1) } else { high = mID } } return low }}
< 145 } // 145extension CollectionType where Index: RandomAccessIndexType { /// Finds such index N that predicate is true for all elements up to /// but not including the index N,and is false for all elements /// starting with index N. /// Behavior is undefined if there is no such N. func binarySearch(predicate: Generator.Element -> Bool) -> Index { var low = startIndex var high = endindex while low != high { let mID = low.advancedBy(low.distanceto(high) / 2) if predicate(self[mID]) { low = mID.advancedBy(1) } else { high = mID } } return low }}

进入Swift 3如下:

错误

Binary operator ‘/’ cannot be applIEd to operands of type ‘self.Index.StrIDe’ and ‘Int’

抛出让mID = low.advanced(by:low.distance(to:high)/ 2)

有关如何修复它的任何帮助?

在Swift 3中,“集合移动他们的索引”,比较
关于Swift进化的 A New Model for Collections and Indices.特别是,您不要在索引上调用advancedBy(),
但是在集合上使用index()方法来推进索引.

所以你的方法将在Swift 3中实现

[+++]

不需要对索引类型进行任何限制.

总结

以上是内存溢出为你收集整理的swift – Stridable Protocol全部内容,希望文章能够帮你解决swift – Stridable Protocol所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
< 145 } // 145extension"og:type" content="webpage"> < 145 } // 145extension" /> < 145 } // 145extension"> swift – Stridable Protocol_app_内存溢出

阅读 25

swift – Stridable Protocol,第1张

概述我试图转换以下 Swift 2.3代码: //Example usage://(0 ..< 778).binarySearch { $0 < 145 } // 145extension CollectionType where Index: RandomAccessIndexType {    /// Finds such index N that predicate is true fo                         我试图转换以下  Swift 2.3代码:      
//Example usage://(0 ..< 778).binarySearch { 
//Example usage://(0 ..< 778).binarySearch {
extension Collection { func binarySearch(predicate: (Iterator.Element) -> Bool) -> Index { var low = startIndex var high = endindex while low != high { let mID = index(low,offsetBy: distance(from: low,to: high)/2) if predicate(self[mID]) { low = index(after: mID) } else { high = mID } } return low }}
< 145 } // 145extension Collection where Index: StrIDeable { /// Finds such index N that predicate is true for all elements up to /// but not including the index N,and is false for all elements /// starting with index N. /// Behavior is undefined if there is no such N. func binarySearch(predicate: (Generator.Element) -> Bool) -> Index { var low = startIndex var high = endindex while low != high { let mID = low.advanced(by: low.distance(to: high) / 2) if predicate(self[mID]) { low = mID.advanced(to: 1) } else { high = mID } } return low }}

< 145 } // 145extension CollectionType where Index: RandomAccessIndexType { /// Finds such index N that predicate is true for all elements up to /// but not including the index N,and is false for all elements /// starting with index N. /// Behavior is undefined if there is no such N. func binarySearch(predicate: Generator.Element -> Bool) -> Index { var low = startIndex var high = endindex while low != high { let mID = low.advancedBy(low.distanceto(high) / 2) if predicate(self[mID]) { low = mID.advancedBy(1) } else { high = mID } } return low }}

进入Swift 3如下:

错误

Binary operator ‘/’ cannot be applIEd to operands of type ‘self.Index.StrIDe’ and ‘Int’

抛出让mID = low.advanced(by:low.distance(to:high)/ 2)


有关如何修复它的任何帮助?
在Swift 3中,“集合移动他们的索引”,比较

关于Swift进化的 A New Model for Collections and Indices.特别是,您不要在索引上调用advancedBy(),

但是在集合上使用index()方法来推进索引.

所以你的方法将在Swift 3中实现

不需要对索引类型进行任何限制.

总结

以上是内存溢出为你收集整理的swift – Stridable Protocol全部内容,希望文章能够帮你解决swift – Stridable Protocol所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:

内存溢出

原文地址:

https://outofmemory.cn/web/1037234.html
(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
管理专业硕士 管理专业硕士 一级用户组
带双点的Swift非包含范围
上一篇
2022-05-24
swift – 迭代无限引用的结构体数组
2022-05-24

发表评论
请登录后评论... 登录
提交

    评论列表(0条)
保存
{label} {label} < 145 }145extension CollectionType wher', author : '管理专业硕士', cat_name : 'app', time_y_m : '2022年05月', time_d : '24', site_motto : '内存溢出' }; {script} {script}