Avatar
Swift 4.2でArrayに生えたshuffled(using:)を試しているのですが、型にProcotolを書くと通らない... import Foundation class A: RandomNumberGenerator {} var a: RandomNumberGenerator = A() [1, 2, 3].shuffled(using: &a) // error: argument passed to call that takes no arguments // [1, 2, 3].shuffled(using: &a) var b = A() [1, 2, 3].shuffled(using: &b) // Success
3:12 PM
shuffledと似たような関数を自分で書くと
3:13 PM
import Foundation func shuffled<T>(using generator: inout T) -> [Int] where T : RandomNumberGenerator { return [] } class A: RandomNumberGenerator {} var a: RandomNumberGenerator = A() shuffled(using: &a) // error: in argument type 'inout RandomNumberGenerator', 'RandomNumberGenerator' does not conform to expected type 'RandomNumberGenerator' // shuffled(using: &a) ^
3:13 PM
'RandomNumberGenerator' does not conform to expected type 'RandomNumberGenerator'ってなんだ...
3:16 PM
これ関係あるかも 関係なさそうだった https://bugs.swift.org/browse/SR-7918?jql=text%20~%20%22RandomNumberGenerator%22 (edited)