So here is what I just did:
protocol Initable {
init()
}
class Bar:<T: Initable> {
var ar: T[]
init(length: Int) {
self.ar = T[](count:length, repeatedValue: T())
}
}
Then you need to make sure that anyone Tyou use implements the protocol Initable, for example:
extension Int:Initable {}
which allows me to do this:
var foo = Bar<Int>(3)
I also used an alternative to prototyping:
class Bar:<T> {
var ar: T[]
init(length: Int, proto:T) {
self.ar = T[](count:length, repeatedValue:proto)
}
}
which does not require a protocol, but needs an initial value:
var foo = Bar<Int>(length: 3, proto: 34)