Re: [swift-users] UnsafeMutablePointer Swift 3 conversion

2016-09-02 Thread Jacob Bandes-Storch via swift-users
Hi Patrice, I don't have a solution for you, but I just wanted to point out what I think may be an error with your use of the new UnsafeRawPointer APIs: constantBufferForFrame.contents().bindMemory(to: ShadowPass.self, capacity: MemoryLayout.size) I believe the `capacity` should actually be the n

Re: [swift-users] Subtract a set of a subclass?

2016-09-02 Thread Zhao Xin via swift-users
You are correct. Whether override `hashValue` is basing on the implementation of `==`. You can't do what you want. You should follow the required rules. However, if you don't want to get the unexpected result, you can always use a `convenience init(_ instance:Self)` in `extension` to convert subcla

Re: [swift-users] Subtract a set of a subclass?

2016-09-02 Thread Dmitri Gribenko via swift-users
On Sat, Sep 3, 2016 at 4:47 AM, Zhao Xin via swift-users wrote: > Hi Jordan, > > Both you and I were wrong. > > My wrongness: Your so called principle should be applied here. > > Your wrongness: If you really want a different hash value, the parent > equality function has to be conservative and sa

Re: [swift-users] Subtract a set of a subclass?

2016-09-02 Thread Zhao Xin via swift-users
Hi Jordan, Both you and I were wrong. My wrongness: Your so called principle should be applied here. Your wrongness: If you really want a different hash value, the parent equality function has to be conservative and say that the different types are different. Here is the conclusion. The key is

Re: [swift-users] Can we `override var hashValue`?

2016-09-02 Thread Zhao Xin via swift-users
The key is how to write the `==` function. It should compare the` dynamicType`(or `type(of:)` in Swift 3.0) if the class is not a final class. func ==(lhs: Fruit, rhs: Fruit) -> Bool { print(lhs.hashValue) print(rhs.hashValue) return type(of:lhs) == type(of:rhs) && lhs.name == r

Re: [swift-users] Can we `override var hashValue`?

2016-09-02 Thread Zhao Xin via swift-users
> > There is no reason to compare the shape, it is a constant in each of these types. (So I am not sure what your point is.) Sorry. The `let shape` should be `var shape`. I just wanted to make the subclass to be something more than the super class. If two values are equal, their hash values sh

Re: [swift-users] Function to unsafe pointer and back

2016-09-02 Thread Lou Zell via swift-users
On Thu, Sep 1, 2016 at 1:48 PM, Andrew Trick wrote: > > Also, in the first case the UnsafePointer points to local memory that > holds the function value. In the second case, you’re trying to load a > function value from the address of the function body. > > Beginning to see... On Fri, Sep 2, 201

Re: [swift-users] Can we `override var hashValue`?

2016-09-02 Thread Dmitri Gribenko via swift-users
On Sat, Sep 3, 2016 at 1:31 AM, Zhao Xin via swift-users wrote: > func ==(lhs: Apple, rhs: Apple) -> Bool { > return lhs.name == rhs.name && lhs.shape == rhs.shape > } > > func ==(lhs: Banana, rhs: Banana) -> Bool { > return lhs.name == rhs.name && lhs.shape == rhs.shape > } There is no r

[swift-users] Can we `override var hashValue`?

2016-09-02 Thread Zhao Xin via swift-users
In Objective-C, it says If two objects are equal, they must have the same hash value. This last > point is particularly important if you define isEqual: in a subclass and > intend to put instances of that subclass into a collection. Make sure you > also define hash in your subclass. https://devel

Re: [swift-users] Statically linked binaries on linux

2016-09-02 Thread Joel Hughes via swift-users
Hello again, I've been attempting add to the swift-build script so that Foundation can be compiled as a static lib. Simialr to > swift/utils/build-script -r --build-swift-static-stdlib --foundation I'm not familiar with Cmake, ninja and the way the swift is built but have got the build working.

[swift-users] UnsafeMutablePointer Swift 3 conversion

2016-09-02 Thread Patrice Kouame via swift-users
Hi all - I’m converting Apple’s Swift Sample "Adopting Metal II: Designing and Implementing a Real-World Metal Renderer” in Xcode 8 beta6 to the latest UnsafeMutablePointer API for untyped memory access. Changes are necessary in MetalView.swift (Apple hasn’t updated their sample code for the

Re: [swift-users] Function to unsafe pointer and back

2016-09-02 Thread Andrew Trick via swift-users
> On Sep 2, 2016, at 9:49 AM, Jordan Rose wrote: > > (One place we are still weak is in converting between C function references > and UnsafeRawPointer—there’s no dedicated API to do this. I’m not sure we > have a recommendation in the rare cases when this is necessary. Andy?) Good question.

Re: [swift-users] Function to unsafe pointer and back

2016-09-02 Thread Jordan Rose via swift-users
> On Sep 1, 2016, at 13:48, Andrew Trick via swift-users > wrote: > > >> On Sep 1, 2016, at 12:37 PM, Lou Zell via swift-users > > wrote: >> >> As to your real question, what’s your high-level goal? Swift doesn’t really >> do pointers to functions [1] but it do

Re: [swift-users] Subtract a set of a subclass?

2016-09-02 Thread Jordan Rose via swift-users
This is incorrect. If I have a Set, I should expect that the set may contain Apples and Bananas. If you really want a different hash value, the parent equality function has to be conservative and say that the different types are different. But that’s your choice, because you wrote the implement