Etan
Etan

Reputation: 17554

Passing Data into function that accepts generic collection

I have a function that accepts generic collections.

func foo<T: BidirectionalCollection>(_ bar: T)
    where T.Iterator.Element == UInt8,
          T.SubSequence: BidirectionalCollection & RangeReplaceableCollection,
          T.SubSequence.Iterator.Element == UInt8,
          T.SubSequence.Index == T.Index,
          T.SubSequence.SubSequence == T.SubSequence
{
    //
}

I want to call this function with Data as T:

foo(Data())

However, this gives the error:

error: generic parameter 'T' could not be inferred

What's going on here? How to properly call the function with a Data instance?

Upvotes: 0

Views: 158

Answers (1)

0x416e746f6e
0x416e746f6e

Reputation: 10136

I think the problem is that Data.SubSequence does not conform to RangeReplaceableCollection protocol, while your generic function has this requirement:

T.SubSequence: BidirectionalCollection & RangeReplaceableCollection

Upvotes: 1

Related Questions