Re: [swift-users] Extending Arrays of specific type, and specialization

2016-11-25 Thread Matt Whiteside via swift-users
> On Nov 22, 2016, at 03:04, Tino Heth via swift-users > wrote: > > Hi Rick, > > as evolution is somewhat paused, swift-users seems to gain more traction ;-) > > Imho the most natural would be > extension Array { > … > } > > I hope to see this addition included when

Re: [swift-users] Extending Arrays of specific type, and specialization

2016-11-25 Thread Karl via swift-users
> On 23 Nov 2016, at 01:50, Hooman Mehr via swift-users > wrote: > > For example, this reduces the six variants of sum to two: > > public protocol ContiguousBufferedArray: RandomAccessCollection { > > func withUnsafeBufferPointer(_ body: >

Re: [swift-users] Extending Arrays of specific type, and specialization

2016-11-22 Thread Rick Mann via swift-users
That seems to work well, thanks! > On Nov 22, 2016, at 16:59 , Hooman Mehr wrote: > > By the way, even without new Swift 3.1 feature, this works, providing > optimized sum function for all three types: > > extension ContiguousBufferedArray where Iterator.Element == Double { >

Re: [swift-users] Extending Arrays of specific type, and specialization

2016-11-22 Thread Hooman Mehr via swift-users
By the way, even without new Swift 3.1 feature, this works, providing optimized sum function for all three types: extension ContiguousBufferedArray where Iterator.Element == Double { func sum() -> Double { var result = Double() withUnsafeBufferPointer {

Re: [swift-users] Extending Arrays of specific type, and specialization

2016-11-22 Thread Rick Mann via swift-users
Thanks! It's all very educational, at the least. Obviously the ideal would be for LLVM to recognize and optimize (there are many ways to write the sum of an array), but this is cool. > On Nov 22, 2016, at 16:50 , Hooman Mehr wrote: > > For example, this reduces the six

Re: [swift-users] Extending Arrays of specific type, and specialization

2016-11-22 Thread Rick Mann via swift-users
> On Nov 22, 2016, at 03:39 , Adrian Zubarev > wrote: > > It’s already fixed for Swift 3.1. > > Here is the change log. Cool. I wonder when it will appear in a shipping Xcode. So, dumb question: how do you know that "Element" is the name of the thing you

Re: [swift-users] Extending Arrays of specific type, and specialization

2016-11-22 Thread Rick Mann via swift-users
> On Nov 22, 2016, at 03:04 , Tino Heth <2...@gmx.de> wrote: > > Hi Rick, > > as evolution is somewhat paused, swift-users seems to gain more traction ;-) > > Imho the most natural would be > extension Array { > … > } > > I hope to see this addition included when the topic is discussed again.

Re: [swift-users] Extending Arrays of specific type, and specialization

2016-11-22 Thread Hooman Mehr via swift-users
It is good to know that extension Array where Element == Double { } will work pretty soon with Swift 3.1. Back to reduce(0,+): If we get specialized instance for a reduce(0,+), so that it is known that “+” is a (Double, Double)->Double function, LLVM’s auto-vectorization should be able to

Re: [swift-users] Extending Arrays of specific type, and specialization

2016-11-22 Thread Tino Heth via swift-users
Hi Rick, as evolution is somewhat paused, swift-users seems to gain more traction ;-) Imho the most natural would be extension Array { … } I hope to see this addition included when the topic is discussed again. - Tino ___ swift-users mailing list

Re: [swift-users] Extending Arrays of specific type, and specialization

2016-11-21 Thread Hooman Mehr via swift-users
This is not possible in Swift 3.0. Swift 4.0 will improve things with conditional conformances. For now, the best solution is using global functions instead of extending types or protocols. For example you can do this now: extension Array where Element: FloatingPoint { func sum() ->