Swift Dictionary Initialization of custom type gives: '>' is not a postfix unary operator error -
i trying initialise empty dictionary custom type in swift getting '>' not postfix unary operator error
struct prims { var msset = [vertex<int> : double]() // lines gives error }
i tried way; still getting same error
struct prims { var msset: [vertex<int> : double] init() { self.msset = [vertex<int> : double]() } }
i have defined vertex in separate file
import foundation public struct vertex<t: hashable> { var data: t } extension vertex: hashable { public var hashvalue: int { return "\(data)".hashvalue } static public func ==(lhs: vertex, rhs: vertex) -> bool { return lhs.data == rhs.data } } extension vertex: customstringconvertible { public var description: string { return "\(data)" } }
i looking why
happening. know using var msset = dictionary<vertex<int>, double>()
work.
while can't tell why swift compiler emits error, can make compile this:
struct prims { var msset = dictionary<vertex<int>, double>() }
or this:
struct prims { typealias v = vertex<int> var msset = [v : double]() }
Comments
Post a Comment