Swift GeneratorOf <T> crazy init

GeneratorOf creates the generic Generator(s Sequence):

struct GeneratorOf<T> : Generator, Sequence {
    init(_ next: () -> T?)
    init<G : Generator where T == T>(_ self_: G)
    func next() -> T?
    func generate() -> GeneratorOf<T>
}

The line I don't understand is the second init:

init<G : Generator where T == T>(_ self_: G)

Why on Earth is it necessary to indicate that T == T??

What does this mean (_ self_: G)<

Thank you, one of Swift’s main benefits is its much simpler syntax than Objective-C ... :-P

+4
source share
1 answer

This is a bug in the Swift stdlib header auto-generator. When resolving types, they replace equivalent types in some places that they shouldn't. The actual definition here should be:

init<G : Generator where Generator.Element == T>(_ self_: G)

Generator.Element T, . Apple .

(_ self_: G) , , , , , , SequenceOf, , , . , , , .

, stdlib "" . Swift . Apple Apple, .

devforms.

+5

All Articles