Why does "+" require "RangeReplaceableCollection?

Viewed 2078

I'm trying to implement a struct, called "Dual", and overload the arithmetic operators on it. I want it to work for Integers and Doubles, so am hoping that defining it generically will help with that, . At the moment I have:

struct Dual<Element: Numeric> {
    var f: Element
    var fPrime: Element

    init(_ f: Element, _ fPrime: Element) {
        self.f = f
        self.fPrime = fPrime
    }

    static func + (left: Dual, right: Dual) -> Dual {
        return Dual(left.f + right.f, left.fPrime + right.fPrime)
    }
}

But I get the compiler error:

Referencing operator function '+' on 'RangeReplaceableCollection' requires that 'Numeric' conform to 'RangeReplaceableCollection'

I work out what the suggestion protocol has to do with struct, it's just an ordered pair.

Can anyone suggest what I need to do? Thanks!

0 Answers
Related