<div dir="ltr"><div><div class="gmail_signature" data-smartmail="gmail_signature">@Dave,</div></div><div class="gmail_quote"><div dir="ltr"><div><br></div><div>How do I write that though.</div><div><br></div><div>I can't write:</div><div><br></div><div> extension Array: Equatable {<span class=""><br> static func ==(lhs: Array, rhs: Array) -> Bool {<br></span> let size = lhs.count<br> precondition(rhs.count == size, "The arrays must be the same length")<br> for i in 0 ..< size {<br> if (lhs[i] as! Equatable) != (rhs[i] as! Equatable) {<br> return false<br> }<br> }<br> return true<br> }<br> }</div><div><br></div><div>Because I can't cast to an Equatable, because Equatable uses Self.</div><div><br></div><div>Am I missing something?</div><div><br></div><div> -- Howard.</div></div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_1196678530383631321gmail_signature" data-smartmail="gmail_signature"> -- Howard.<br></div></div></font></span><div><div class="h5">
<br><div class="gmail_quote">On 16 November 2016 at 16:35, David Sweeris <span dir="ltr"><<a href="mailto:davesweeris@mac.com" target="_blank">davesweeris@mac.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_1196678530383631321HOEnZb"><div class="m_1196678530383631321h5"><br>
> On Nov 15, 2016, at 21:39, Howard Lovatt via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:<br>
><br>
> Hi All,<br>
><br>
> Does anyone have a good workaround for generics not currently supporting conditional conformance to a protocol. As stated in the Generics Manifesto something like this would be nice:<br>
><br>
> extension Array: Equatable where Element: Equatable {<br>
> static func ==(lhs: Array, rhs: Array) -> Bool { ... }<br>
> }<br>
><br>
> But I would currently write a wrapper, something like:<br>
><br>
> struct ArrayE<T: Equatable> {<br>
> var elements: [T]<br>
> }<br>
> extension ArrayE: Equatable {<br>
> static func ==(lhs: ArrayE, rhs: ArrayE) -> Bool { ... }<br>
> }<br>
><br>
> This can get unwieldy when there are a lot of conditional protocol extensions required, i.e. wrappers round wrappers.<br>
><br>
> Is there a better way?<br>
><br>
> Thanks for any tips,<br>
><br>
> -- Howard.<br>
</div></div>> ______________________________<wbr>_________________<br>
> swift-users mailing list<br>
> <a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br>
<br>
Can you make Array conform to Equatable for any T and then in the == function, if T conforms to Equatable loop the Arrays to check if they're equal, and if it doesn't conform just return false?<br>
<br>
I mean, it's still "wrong", but at least you won't get any false positives.<br>
<br>
- Dave Sweeris</blockquote></div><br></div></div></div>
</div><br></div>