<div class="gmail_quote">On Mon, Jun 28, 2010 at 10:56, Jacob Carlborg <span dir="ltr">&lt;<a href="mailto:doob@me.com">doob@me.com</a>&gt;</span> wrote:<br><div><br>Something to keep in mind: as of 2.04x (.045? maybe), the way UTF-8 / UTF-32 is managed was changed. &quot;asd&quot; is an array of immutable(dchar), not imutable(char). At least DMD tells me that its element type is &#39;dchar&#39;.<br>
<br>So your function can be done this way in D2:<br><br>void foo(T,U)(in T[] a, U b) if (is(U : Unqual!T)) // that compiles only if b can be cast to A<br>{<br>    writeln(a,b);<br>}<br><br>&quot;asd&quot;.foo(&#39;s&#39;); // prints &quot;asds&quot;.<br>
<br>is(U == Unqual!T) does not work, for U is &#39;char&#39; while Unqual!T is 
&#39;dchar&#39;.<br><br>More generally, using ranges and not arrays, the template becomes a bit more heavy:<br><br>void foo(Range,Elem)(in Range range, Elem elem) <br>if (isInputRange!Range &amp;&amp; is(Elem : Unqual!(ElementType!Range)))<br>
{<br>...<br>}<br> <br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div>I don&#39;t think I understand what you&#39;re showing here. How would I strip off the const/immutable with a template ?<br>
</div><br></blockquote><div><br>Hmmm...<br>* plays with is expressions *<br><br>This seems to work:<br><br>template UnConst(T)<br>{<br>    static if (is(T t == const U, U)) // that is:  &#39;if T is a &#39;const U&#39;, for some U&#39;<br>
        alias U UnConst;                      // then give me the U, (ie, T without a const)<br>    else<br>        alias T UnConst;                      // else give me the (original) T<br>}<br><br>template UnImmutable(T)<br>
{<br>    static if (is(T t == immutable U, U)) // &#39;if T is an &#39;immutable U&#39;, for some U&#39;<br>        alias U UnImmutable;<br>    else<br>        alias T UnImmutable;<br>}<br> <br>test:<br><br>void main() {<br>
    alias const int Int;<br>    writeln(UnConst!Int.stringof);<br>    writeln(Int.stringof);<br>    writeln(UnConst!int.stringof);<br>    writeln(UnConst!(const int).stringof);<br>    writeln(UnConst!(immutable int).stringof);<br>
<br>    alias immutable int IInt;<br>    writeln(UnConst!IInt.stringof);<br>    writeln(IInt.stringof);<br>    writeln(UnImmutable!int.stringof);<br>    writeln(UnImmutable!(const int).stringof);<br>    writeln(UnImmutable!(immutable int).stringof);<br>
}<br><br>Philippe<br><br></div></div>