An associated type declaration is defined as:
protocol-associated-type-declaration → attributes opt access-level-modifier opt associatedtype typealias-name type-inheritance-clause opt typealias-assignment opt generic-where-clause opt
I've not had any luck in finding a resource on what effect the typealias-assignment
element in this syntax has. Neither the swift.org docs or Apple's The Swift Programming Language ebook appear to mention this element of the syntax in their description of generics or associated types in particular.
Can anyone shed some light?
Further on the topic, I was curious if there is any interest or initiative in the direction of allowing the generic type parameter specification to be made optional in the context of type parameters that have a default type specified or that could be inferred (eg. from this token in the associatedtype
syntax)?
protocol Box {
associatedtype T = Void
var value: T? { get }
}
struct SimpleBox<T>: Box {
var value: T?
}
SimpleBox()
func f() -> SimpleBox<_> {}
Would be interesting if something like this was possible.