Swift's GeneratorOf crazy init

前端 未结 1 448
失恋的感觉
失恋的感觉 2021-01-13 23:47

GeneratorOf creates a generic Generator (and Sequence):

struct GeneratorOf : Generator, Sequence {
    init(_ next: () -&g         


        
相关标签:
1条回答
  • 2021-01-14 00:30

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

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

    But since Generator.Element is the same as T, the tool replaces it. Apple's been working on fixing that.

    (_ self_: G) is standard syntax, though an admittedly unusual style that I haven't seen used elsewhere, except for in SequenceOf, which was probably written by the same person. I suspect it's just how the developer named the variable, rather than having some deeper meaning.

    Remember, the stdlib header isn't a "normal" header. Swift doesn't have headers. Apple does a special Apple-only trick to allow one.

    Chris Lattner commented on this in the devforms.

    0 讨论(0)
提交回复
热议问题