I have a template that I'd like to have a specialization for arrays. Initiall I need it to work for byte arrays, but I'd like to make it eventually work for all arrays. The page <a href="http://d-programming-language.org/template">http://d-programming-language.org/template</a> says to use<div>
<br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><span class="Apple-style-span" style="font-size: 16px; background-color: rgb(255, 255, 255);"><span class="d_keyword">template</span></span></font> TFoo(T : T[]) { ... } <span class="d_comment">// #2</span></div>
</blockquote><div><div><br></div><div>but when I try it, it doesn't quite work:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font class="Apple-style-span" face="'courier new', monospace">template abc(T)</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> void abc(T parm1)</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> writeln("simpleparm: ", parm1);</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div></div><div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">template abc(T: T[])</font></div></div><div>
<div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> void abc(T parm1)</font></div></div><div>
<div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> writeln("array : ", parm1);</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div></div><div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">void main(string[] args)</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> abc(1);</font></div></div><div>
<div><font class="Apple-style-span" face="'courier new', monospace"> abc("str");</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> int[] arr = [1, 2];</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> abc(arr);</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> } </font></div></div>
</blockquote><div><div><br></div><div><div>The output is:</div></div></div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font class="Apple-style-span" face="'courier new', monospace">simpleparm: 1</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace">simpleparm: str</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">simpleparm: [1, 2]</font></div>
</div></blockquote><div><br></div><div>Which is not what I want, it needs to be the specialized template for arrays. Note, this doesn't work either:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">
<div><div><font class="Apple-style-span" face="'courier new', monospace">template abc(T: T[])</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div></div>
<div><div><font class="Apple-style-span" face="'courier new', monospace"> void abc(T[] parm1)</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> writeln("array : ", parm1);</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div></div></blockquote><div><br></div><div>John</div></div>