<div class="gmail_quote">On Fri, Apr 23, 2010 at 14:57, Robert Jacques <span dir="ltr">&lt;<a href="mailto:sandford@jhu.edu">sandford@jhu.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div>PS. You can get things like this to work using template constraints.<br></div>
<br>
For example, here&#39;s a horrible hack:<br>
void unary_op(T)(T value)<br>
if(T.stringof[0..3] == &quot;A!(&quot; &amp;&amp; T.stringof[$-1..$] == &quot;)&quot;  ){}<br>
</blockquote></div><br>Maybe a bit less hacky (?) using an is expression:<br><br>void unary_op(T)(T value) if (is(T TT == A!N, uint N)) {}<br><br><br>N does not exist inside the function, though. For that, you&#39;d have to recreate it with a static if:<br>
<br>void unary_op(T)(T value) if (is(T TT == A!N, uint N)) <br>{<br>    static if (is(T TT == A!N, uint N)) // read this as &quot;if T is a type like A!N, for some uint N&quot;<br>        writeln(N);<br>}<br><br><br>I have a template that may be useful there:<br>
<br>/**<br>isInstanceOf!(Type, templateName) is true iff Type is an instantiation (is that the right term?) of templateName.<br>*/<br>template isInstanceOf(T, alias templ)<br>{<br>    static if (T.stringof.length &gt;= __traits(identifier, templ).length &amp;&amp; T.stringof[0..__traits(identifier, templ).length] == __traits(identifier, templ))<br>
        enum bool isInstanceOf = true;<br>    else<br>        enum bool isInstanceOf = false;<br>}<br><br>Example:<br><br>void unary_op2(T)(T value) if (isInstanceOf!(T, A)) <br>{<br>// T is an A!(someParam)<br>}<br><br>If you want to extract the &#39;someParam&#39; part, it&#39;s doable by using a CT function that extracts what&#39;s between the first &#39;(&#39; and the corresponding &#39;)&#39;. I think I have somewhere a template that alias itself to the corresponding typetuple:<br>
<br>TemplateParametersTypeTuple!(Temp!(int, double, char[]))  =&gt;  TypeTuple!(int,double, char[])<br><br>Is anyone interested by this one?<br><br>Philippe<br><br><br><br><br>