Hello! I'm trying to create a container type that hold a root type, plus n number of additional types that conform to a protocol. This works well with Parameter Packs, except that any time the number of additional types in the Parameter Packs exceeds three, the compiler throws an error and can't infer the type anymore. This requires a lot of extra code to work around inference issues and use the Expanded type with multiple elements.
Am I doing something wrong here? Or is there a workaround that would let me keep calling addingExpansion
as many times as needed?
Up to three Parameter Pack elements works fine
One more and inference stops working
UPDATE: here is the actual code:
struct Expanded<Base, each Expansion> {
fileprivate let base: Base
fileprivate let expansions: (repeat each Expansion)
init(base: Base, expansions: (repeat each Expansion)) {
self.base = base
self.expansions = (repeat each expansions)
}
public func addingExpansion<New>(_ expansion: New) -> Expanded<Base, repeat each Expansion, New> {
.init(base: base, expansions: (repeat each expansions, expansion))
}
}
struct One { }
struct Two { }
struct Three { }
struct Four { }
let initial = Expanded(base: "", expansions: One())
var more = initial
.addingExpansion(Two())
.addingExpansion(Three())
.addingExpansion(Four())
print(more)