Re: [swift-users] still wrestling with a type conversion problem

2017-07-03 Thread Jacob Bandes-Storch via swift-users
Using a protocol with an "as?" cast convinces the compiler to do a dynamic lookup for a protocol conformance based on the value's actual type: protocol MyEncodable { func encoded() -> Any } func encode(_ value: T) -> Any { if let value = value as? MyEncodable {

[swift-users] still wrestling with a type conversion problem

2017-07-03 Thread David Baraff via swift-users
I’m trying to provide some custom serialization from within a generic class. (Briefly put, I want to automatically convert types like Set to an array upon serialization, and the reverse when I read it back.) While trying things out, I was suprised by this: public func encode(_ value:T) -> Any {

Re: [swift-users] can we express "does not conform to a particular protocol"?

2017-07-03 Thread Austin Zheng via swift-users
I'm pretty sure solutions like the one you proposed are impossible, unfortunately :(. The compiler has to choose the static override at compile time, but it can't tell until runtime whether the type conforms to `Equatable` or not (because of retroactive conformance). It's also not possible to u

Re: [swift-users] can we express "does not conform to a particular protocol"?

2017-07-03 Thread Zhao Xin via swift-users
In my own test, it seams that there is no way to test a type conforms to Equatable or not. `Protocol 'Equatable' can only be used as a generic constraint because it has Self or associated type requirements` Zhao Xin On Tue, Jul 4, 2017 at 9:27 AM, David Baraff wrote: > No, i want the equality

Re: [swift-users] can we express "does not conform to a particular protocol"?

2017-07-03 Thread David Baraff via swift-users
No, i want the equality function run if the two types are equatable, and false otherwise (even if you might deem them to be the same, e.g. two identical sets, because sets do not conform to equatable, or two identical classes, becauses classes are not (in general) equatable). So maybeEqual(3,

Re: [swift-users] can we express "does not conform to a particular protocol"?

2017-07-03 Thread Zhao Xin via swift-users
You mean `type(of:lhs) == type(of:rhs)`? Zhao Xin On Tue, Jul 4, 2017 at 8:00 AM, David Baraff via swift-users < swift-users@swift.org> wrote: > I’m searching for the simplest way to write a function > func maybeEqual(_ lhs:T, _rhs:T) -> Bool > > where it returns lhs == rhs if T is equatable, an

[swift-users] can we express "does not conform to a particular protocol"?

2017-07-03 Thread David Baraff via swift-users
I’m searching for the simplest way to write a function func maybeEqual(_ lhs:T, _rhs:T) -> Bool where it returns lhs == rhs if T is equatable, and false, otherwise. I tried func maybeEqual(_ lhs:T, _rhs:T) -> Bool { return false } func maybeEqual(_ lhs:T, _ rhs:T) -> Bool { retur

Re: [swift-users] Passing Data to a f(void *) function

2017-07-03 Thread Andrew Trick via swift-users
> On Jun 30, 2017, at 9:14 AM, Joe Groff via swift-users > wrote: > > >> On Jun 30, 2017, at 7:40 AM, Martin R via swift-users >> wrote: >> >> I have a C function >> >> void myfunc(const void *ptr); >> >> which is imported to Swift as >> >> func myfunc(_ ptr: UnsafeRawPointer!) >>

Re: [swift-users] Decode a JSON object of unknown format into a Dictionary with Decodable in Swift 4

2017-07-03 Thread Itai Ferber via swift-users
Hi Kevin, You’re right — this is one of the limitations of the box design here. One thing we can do is expose the underlying boxed value as a `KeyedDecodingContainerProtocol` existential value using an accessor on the box so you can down-cast. However, it shouldn’t be necessary to add any me

Re: [swift-users] Maintaining the contact information in CONTRIBUTORS.txt file

2017-07-03 Thread Alex Blewitt via swift-users
>From https://swift.org/CONTRIBUTORS.txt >on the website (which is I presume the one you're referring to): Names below this line are automatically generated from the repository logs. It contains the information about the committer that was publicly present wh

[swift-users] Maintaining the contact information in CONTRIBUTORS.txt file

2017-07-03 Thread swiftlover swiftlover via swift-users
 Each contributor is responsible for adding his or her name to the CONTRIBUTORS.txt file at the project’s root and maintaining the contact information. How can I update my email (mail server that I used was shut down)? ___ swift-users mailing list swift-u