[swift-users] Chaining struct-mutating funcs

2016-08-05 Thread Fritz Anderson via swift-users
Swift 3 as of Xcode 8.0b4 TL;DR: I have a struct value type backed by a copy-on-write mutable buffer. You use it to perform arithmetic on the buffers. The most expressive way to do this efficiently is to chain the arithmetic operators so each mutates the same buffer. Swift does not like to chai

Re: [swift-users] Chaining struct-mutating funcs

2016-08-05 Thread Joe Groff via swift-users
Since your backing buffer is copy-on-write, you can do the in-place mutation optimization in your immutable implementations, something like this: class C { var value: Int init(value: Int) { self.value = value } } struct S { var c: C } func addInts(x: S, y: S) -> S { var tmp = x // Don't

[swift-users] SCNetworkReachabilityFlags beta 4 issue

2016-08-05 Thread Jon Shier via swift-users
Swifters: I’m attempting to port a library to Xcode 8 beta 4 and have run into a peculiar issue with SCNetworkReachabilityFlags. Prior to beta 4, this extension on SCNetworkReachabilityFlags which provided convenience Bool properties worked just fine: extension SCNetworkReachabilityFlag

[swift-users] Two Obj-C visible functions no longer overload?

2016-08-05 Thread Jon Shier via swift-users
Swifters: I’m attempting to update some library code to beta 4 and I’ve run into something that’s either a bug or a deliberate change. In a class that’s a Foundation.Operation subclass, there are two finish() functions: final func finish(_ receivedErrors: [Error] = []) { _finish(rece

[swift-users] Chaining struct-mutating funcs

2016-08-05 Thread Fritz Anderson via swift-users
Swift 3 as of Xcode 8.0b4 TL;DR: I have a struct value type backed by a copy-on-write mutable buffer. You use it to perform arithmetic on the buffers. The most expressive way to do this efficiently is to chain the arithmetic operators so each mutates the same buffer. Swift does not like to chai

Re: [swift-users] Assertion Failure When Using the swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a Xcode Toolchain

2016-08-05 Thread Saagar Jha via swift-users
Thanks, I managed to create a small test project with the same issue; I’ve filed it as SR-2288 . Saagar Jha > On Aug 4, 2016, at 21:01, Mark Lacey wrote: > >> >> On Aug 4, 2016, at 8:51 PM, Saagar Jha via swift-users >> mailto:swift-users@swift.org>>

Re: [swift-users] swift-users Digest, Vol 9, Issue 5

2016-08-05 Thread Adrian Brink via swift-users
On Friday, 5 August 2016, wrote: > Send swift-users mailing list submissions to > swift-users@swift.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://lists.swift.org/mailman/listinfo/swift-users > or, via email, send a message with subject or body 'help'

Re: [swift-users] non-mutating func that still mutates a struct, compiler not aware

2016-08-05 Thread Jordan Rose via swift-users
Those UnsafeMutablePointer(…) calls aren’t correct. When an array is implicitly converted to a pointer in Swift, the pointer is only valid for the immediate call that it’s being passed to. In this case, that’s the UnsafeMutablePointer initializer, and after that the pointer is invalid. So it’s

Re: [swift-users] Set size of byte array

2016-08-05 Thread KS Sreeram via swift-users
> On 05-Aug-2016, at 4:02 PM, Brent Royal-Gordon wrote: > > I don't believe this is possible with an Array; the only way to work with > uninitialized memory is with an UnsafeMutablePointer. > > The simplest solution is probably to load the data into an allocated chunk of > memory with an Uns

Re: [swift-users] Set size of byte array

2016-08-05 Thread KS Sreeram via swift-users
> On 05-Aug-2016, at 1:19 PM, Daniel Vollmer wrote: > > I’m by no means a Swift expert (not even a user at the moment), but I don't > see a way to do this either. The best that comes to mind is initializing a > ContiguousArray with the sufficient capacity as size, using > withUnsafeBufferPointer

Re: [swift-users] non-mutating func that still mutates a struct, compiler not aware

2016-08-05 Thread Raphael Sebbe via swift-users
Do you see a reason why the copy isn't happening in this specific case? Is it a bug, or a mistake in my code? Thank you, Raphael On Thu, Aug 4, 2016 at 4:18 PM Brent Royal-Gordon wrote: > > On Aug 4, 2016, at 1:25 AM, Raphael Sebbe via swift-users < > swift-users@swift.org> wrote: > > > > My u

Re: [swift-users] Set size of byte array

2016-08-05 Thread Brent Royal-Gordon via swift-users
> On Aug 4, 2016, at 11:42 PM, KS Sreeram via swift-users > wrote: > > I’m trying to initialize a byte-array efficiently with minimal copying with > the following steps: > > 1. Create an empty byte array. > 2. Reserve sufficient capacity in the array. > 3. Use mutable pointers into the array t