Closed jjjkkkjjj closed 4 years ago
MfArray<MfType: MfTypable>{ Hoge } //Initialization let a = MfArray<Int>([1,2,3])
I can't understand how above code can be implemented... Alternative solution is below,
subscript(indices: Int...) -> MfArray{
hoge
}
extension MfArray{
public var value?: Any{
hoge
}
}
let a = MfArray([[1,2,3], [4,5,6]])
let b = a[2,1].value as! Int
Or Passed Int of array, return Any.
subscript(indices: Int...) -> Any{
hoge
}
subscript(mfslices: MfSlice...) -> MfArray{
fuga
}
let b = a[2,1] as! Int //Scalar or MfArray
let c = a[1] as! MfArray //Scalar or MfArray
let d = a[0~,1] //-> MfArray
Or
subscript(indices: Int...) -> MfArray{
hoge
}
subscript(mfslices: MfSlice...) -> MfArray{
fuga
}
public func scalar<T: Numeric>(_ type: T) -> T?{
return self.size == 1 ? self.first! as? T : nil
}
let b = a[2,1].scalar(Int.self)!
guard let c = a[2,1].scalar(Int.self) else{ return }
If I don’t use generics in MfArray, subscript’s getter and setter must be handled as Any. However, using Any type causes unexpected error or performance loss.