Created
September 18, 2018 12:15
-
-
Save tarunon/177547c2766db279e6b74cf9d5cde0fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User<T> { ... } // ←こういうものをConformしたい | |
extension Array where User<T> { ... } // ←これはまだできない | |
// ここからWorkaround | |
protocol UserProtocol { associatedtype T } // ←まずこれを作って | |
extension User: UserProtocol {} // Conformして | |
extension Array where Element: UserProtocol { // ←まずProtocolで縛って | |
func foo() where Element == User<Element.T> // ←さらに得られるassoctypeを使って二重に縛る。 | |
} | |
[User<Int>]().foo() // OK | |
[User<String>]().foo() // OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment