[swift-users] inout generic struct parameter error

Georgios Moschovitis george.moschovitis at icloud.com
Mon Jan 2 03:52:47 CST 2017


> But if you do this you will get a different compiler error, because your struct will no longer conform to Sequence, which requires makeIterator to be non-mutating. This is important, especially assuming your array is eventually going to conform to Collection as well. One of the requirements of collections is that they give an accurate count, but in the case of your array, the count returned might be different (greater) than the number of elements returned when you actually iterate the array, and this is not allowed (you may find that some standard library functions will trap when they discover that this has happened).

Btw, isn’t it strange that the next() method in `IteratorProtocol` *is* mutating, and makeIterator() is not?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170102/ea5925d4/attachment.html>


More information about the swift-users mailing list