Re: Swift Generics Error When Enforcing Protocol Conformance...
Re: Swift Generics Error When Enforcing Protocol Conformance...
- Subject: Re: Swift Generics Error When Enforcing Protocol Conformance...
- From: Quincey Morris <email@hidden>
- Date: Thu, 24 Dec 2015 14:41:29 -0800
- Feedback-id: 167118m:167118agrif8a:167118sR49F_ORPD:SMTPCORP
On Dec 24, 2015, at 13:22 , Peters, Brandon <email@hidden> wrote:
>
> I do not see this one being any different from the integer type version.
What’s different is that FloatingPointType doesn’t have any arithmetic operators defined on it.
The solution is to add a protocol that requires that behavior:
> protocol ArithmeticFloatingPointType: FloatingPointType
> {
> func * (lhs: Self, rhs: Self) -> Self
> func += (inout lhs: Self, rhs: Self)
> }
>
> extension Double: ArithmeticFloatingPointType {} // These already have the operator that conforms, so nothing to do here
> extension Float: ArithmeticFloatingPointType {}
>
> func linconv<T: ArithmeticFloatingPointType>(signal_A signal_A: [T], signal_B: [T]) -> [T]? {
> …
> }
You’ll have to expand the new protocol for any other operators you happen to use.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden