-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed as duplicate of#62255
Closed as duplicate of#62255
Copy link
Labels
documentationgenericsFeature: generic declarations and typesFeature: generic declarations and typesinaccurate infoBug → documentation: Inaccurate infoBug → documentation: Inaccurate info
Description
Description
https://github.com/apple/swift/blob/main/docs/Generics.rst#default-implementations
shows example of protocol providing default implemntations:
protocol Numeric {
func +(lhs : Self, rhs : Self) -> Self
func -(lhs : Self, rhs : Self) -> Self { return lhs + -rhs }
func +(x : Self) -> Self { return x }
func -(x : Self) -> Self
}but it's not actual implementation of such functionality.
I suppose that the following is better because it shows actual Swift syntax:
protocol Numeric {
func +(lhs : Self, rhs : Self) -> Self
func -(x : Self) -> Self
}
extension Numeric {
func -(lhs : Self, rhs : Self) -> Self { return lhs + -rhs }
func +(x : Self) -> Self { return x }
}Metadata
Metadata
Assignees
Labels
documentationgenericsFeature: generic declarations and typesFeature: generic declarations and typesinaccurate infoBug → documentation: Inaccurate infoBug → documentation: Inaccurate info