Question on class Iterators

If a Sequence is designed to vend only once, and Iterator is a class type, can makeIterator() return the same instance every time?

I don't see a reason why not.
In fact it may be a good idea to add some such sequences to the Swift tests to ensure sequence operations do not mistakenly assume repeat iteration, if such tests do not already exist.

Section Using Multiple Iterators seems to hint that doing so for a destructive sequence is an undefined behaviour.

Terms of Service

Privacy Policy

Cookie Policy