<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">In general this is more then welcome, so +1 for me.</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">However I have one question:</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Could this allow support, or at least be a first step towards Swift allowing the following behaviour?</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">```<br><div id="bloop_customfont" style="margin: 0px;">extension MyProtocol where Self : SomeClass {</div><div id="bloop_customfont" style="margin: 0px;"><span class="Apple-tab-span" style="white-space:pre">        </span>static func getSubtypes<T>(ofType _: T.Type = T.self) -> [T] where T : Self { ... }</div><div id="bloop_customfont" style="margin: 0px;">}</div>```</div> <div><br></div>I would like to be able to upgrade `Self` to a class constraint, which then will allow me to only accept subtypes from T at compile time.<br> <div id="bloop_sign_1511565056096249088" class="bloop_sign"></div> <br><p class="airmail_on">Am 25. November 2017 um 00:03:23, Matthew Johnson via swift-evolution (<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div></div><div>
<title></title>
One of the most frequent frustrations I encounter when writing
generic code in Swift is the requirement that supertype constraints
be concrete. When I mentioned this on Twitter (<a href="https://twitter.com/anandabits/status/929958479598534656" class="">https://twitter.com/anandabits/status/929958479598534656</a>)
Doug Gregor mentioned that this feature is smaller and mostly
straightforward to design and implement (<a href="https://twitter.com/dgregor79/status/929975472779288576" class="">https://twitter.com/dgregor79/status/929975472779288576</a>).
<div class="">
<div class=""><br class=""></div>
<div class="">I currently have a PR open to add the high-level
description of this feature found below to the generics manifesto
(<a href="https://github.com/apple/swift/pull/13012" class="">https://github.com/apple/swift/pull/13012</a>):</div>
<div class=""><br class=""></div>
<div class="">
<div class="">Currently, supertype constraints may only be
specified using a concrete class or protocol type. This
prevents us from abstracting over the supertype.</div>
<div class=""><br class=""></div>
<div class="">```swift</div>
<div class="">protocol P {</div>
<div class=""> associatedtype Base</div>
<div class=""> associatedtype Derived: Base</div>
<div class="">}</div>
<div class="">```</div>
<div class=""><br class=""></div>
<div class="">In the above example `Base` may be any type.
`Derived` may be the same as `Base` or may be _any_ subtype
of `Base`. All subtype relationships supported by Swift
should be supported in this context including, but not limited to,
classes and subclasses, existentials and conforming concrete types
or refining existentials, `T?` and `T`, `((Base) -> Void)`
and `((Derived) -> Void)`, etc.</div>
<div class=""><br class=""></div>
<div class="">Generalized supertype constraints would be accepted
in all syntactic locations where generic constraints are
accepted.</div>
</div>
<div class=""><br class=""></div>
<div class="">I would like to see generalized supertype constraints
make it into Swift 5 if possible. I am not an implementer so
I will not be able to bring a proposal forward alone but am
interested in collaborating with anyone interested in working on
implementation.</div>
<div class=""><br class=""></div>
<div class="">I am also interested in hearing general feedback on
this feature from the community at large. Have you also found
this limitation frustrating? In what contexts? Does
anyone have reservations about introducing this capability?
If so, what are they?
<div class=""><br class=""></div>
<div class="">
<div class="">Matthew</div>
<div class="">
<div class=""><br class=""></div>
</div>
</div>
</div>
</div>
_______________________________________________<br>swift-evolution mailing list<br>swift-evolution@swift.org<br>https://lists.swift.org/mailman/listinfo/swift-evolution<br></div></div></span></blockquote></body></html>