<div dir="ltr">Anton, <div><br></div><div>Thanks for the explanation. Interesting!</div><div><br></div><div>I can understand the difference [I assume you are using the term template specialization (developer code to provide a special implementation for specific generic arguments) to refer to the term template instantiation (compiler generated code for a set of actual generic arguments)]; however I believe this is an implementation detail that should not influence higher-level decisions unless it is strictly necessary. At the moment I fail to see why it needs to be so.</div><div><br></div><div>Regards,</div><div>Ramiro</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, 2 Dec 2016 at 22:34 Anton Zhilin &lt;<a href="mailto:antonyzhilin@gmail.com">antonyzhilin@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg">2016-12-02 3:55 GMT+03:00 Ramiro Feria Purón <span dir="ltr" class="gmail_msg">&lt;<a href="mailto:ramiro.feria.puron@gmail.com" class="gmail_msg" target="_blank">ramiro.feria.puron@gmail.com</a>&gt;</span>:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class="gmail_msg"><span class="m_-8170196660198771226gmail- gmail_msg"><div class="gmail_msg"><span style="font-size:13px" class="gmail_msg"><i class="gmail_msg">Unlike C++&#39;s templates, a Swift&#39;s generic function is semantically a single function.</i></span><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div></span>Anton, could you provide further insight on this?</div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">Basically, generic functions in Swift are implemented as functions taking an additional parameter -- witness table, which contains implementation of all functions in the protocol.</div><div class="gmail_msg">For example, the following:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">func f&lt;T: P&gt;(a: T, b: T)</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Turns into something like:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">func f(a: Any, b: Any, witnessTableForT: UnsafePointer&lt;_WitnessTable&gt;)</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Returning to my cited phrase, Swift specializes generic types (with duplicated metadata; think C++ class specialization), but implements generic functions without using specialization. One can say that a generic type in Swift becomes a collection of distinct types, but a generic function remains a single function. So we can&#39;t view them equally, and current situation, where we can &quot;explicitly specialize&quot; types, but not functions, is not an inconsistency.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I used word &quot;semantically&quot;, because compiler can apply <i class="gmail_msg">specialization optimization</i> to a function, which is usually followed by inlining. But this optimization is guaranteed not to break the above assumptions.</div></div></div></div>
</blockquote></div>