<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On 30 May 2017, at 16:27, David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><div dir="auto" class=""><div class=""><br class=""></div><div class="">On May 30, 2017, at 03:25, Pavol Vaskovic &lt;<a href="mailto:pali@pali.sk" class="">pali@pali.sk</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra"><span class="gmail-im" style="font-size:12.8px">On Tue, May 30, 2017 at 7:51 AM, David Sweeris&nbsp;<span dir="ltr" class="">&lt;<a href="mailto:davesweeris@mac.com" target="_blank" class="">davesweeris@mac.com</a>&gt;</span>&nbsp;wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto" class=""><span class="gmail-m_4057504060529073430gmail-"><div class=""><br class=""></div><div class="">`(Int, Int, Int, Int)` isn't *that* horrible compared to "[Int x 4]", but would you want to replace "[Int8 x 10000]" with the multipage-long tuple equivalent?</div></span></div></blockquote><div class=""><br class=""></div></span><div style="font-size:12.8px" class="">😳</div><div style="font-size:12.8px" class="">It would be really helpful to my understanding, if you spoke about a practical use case. This reads as a contrived counterexample to me…</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">If your type really has 10 000 values in it, why does it have to be static, why doesn't normal Array fit the bill?</div></div></div>
</blockquote><br class=""><div class="">Sure, I meant it as an example of how unwieldy large tuples can be. Even medium ones, really. Tuples are great for bundling a few values, but much more than that any they become annoying to work with because there's no easy way to iterate through them. As a more realistic example, what if you want a stack-allocated 256-element buffer (which is a real possibility since statically-allocated C arrays are imported as tuples)? You have to manually keep track of i, because you have to hard-code which element you're addressing ("buf.0", "buf.1", etc), rather than being able to look it up directly from an index variable like, well, an array ("buf[i]").</div></div></div></blockquote><div><br class=""></div></div>The other issue is when you're importing an existing enum from a fixed size data structure which has a fixed array count:<div class=""><br class=""></div><div class="">// in include/*.h</div><div class="">#define MAX_ELEMENTS 100</div><div class="">typedef struct {</div><div class="">&nbsp; size_t count;</div><div class="">&nbsp; int elements[MAX_ELEMENTS];</div><div class="">} MyData</div><div class=""><br class=""></div><div class="">This gets imported into Swift as a 100-element tuple, which means you can't do elements[i] to look them up. And while a case statement will be hand-rollable, given that this is a compile-time value which could be changed in the future, it won't be safe.</div><div class=""><br class=""></div><div class="">You can end up with such unrolled loops (e.g.&nbsp;<a href="https://github.com/apple/swift-corelibs-foundation/blob/46b4e84a263d4fb657d84dfa4ca5b8fb4ed1f75f/Foundation/NSDecimal.swift#L1546-L1591" class="">https://github.com/apple/swift-corelibs-foundation/blob/46b4e84a263d4fb657d84dfa4ca5b8fb4ed1f75f/Foundation/NSDecimal.swift#L1546-L1591</a>&nbsp;) but they're pretty unwieldy for something that should be a compile-time check.</div><div class=""><br class=""></div><div class="">It can be hacked with mirror, but well, it's a hack:</div><div class=""><br class=""></div><div class="">&nbsp; subscript(index:Int) -&gt; Int {<br class="">&nbsp; &nbsp; &nbsp;&nbsp;let all =&nbsp;Mirror(reflecting:self.elements).children.map({$0.value as! Int})</div><div class="">&nbsp; &nbsp; &nbsp; return all[index]<br class="">&nbsp;&nbsp;}<br class=""><br class=""></div><div class="">Alex</div></body></html>