<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><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Please NO. Templates are the worst idea ever to evolve from C++. Never let this madness enter into Swift, it has done enough damage in the C++ world already.</div></div></blockquote></div>Hey, templates are cool — they are even Turing complete! ;-)<div class="">No, I really don't think it's that useful to calculate Fibunacci-numbers at compile time (at least I don't think C++ template syntax is a good tool to do so).</div><div class=""><br class=""></div><div class="">But it wouldn't be that hard to implement something in between generics and full template support, without the dangers (that's what I meant with "limited").</div><div class="">I might write a proposal some day, but the concept isn't that hard:</div><div class="">Right now, we can have something like</div><div class="">let m = Matrix(rows: 3, columns: 4)</div><div class="">easily.</div><div class="">There's just the problem that the compiler cannot deduce which matrices are "compatible", as there is only one Matrix-type.</div><div class="">If we had a way to tell the compiler that "rows" and "columns" have an effect on the type, everything would be fine, and this model of compile-time parameters imho is quite simple:</div><div class=""><br class=""></div><div class="">struct FloatVector<dimensions: UInt> {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>private var elements = Array<Float>(capacity: dimensions)</div><div class="">…</div><div class="">}</div><div class=""><br class=""></div><div class="">let vector = FloatVector<3>(0, 0, 1)</div><div class="">let otherVector = FloatVector<2>(0, 1)</div><div class=""><br class=""></div><div class="">let sum = vector + otherVector // compiler error, type mismatch</div><div class=""><br class=""></div><div class="">I think many problems with template happen because they are not compiled unless you use them, and compile-time parameters wouldn't suffer from this.</div><div class=""><br class=""></div><div class="">Best regards,</div><div class="">Tino</div></body></html>