On 26 November 2012 19:11, Adam D. Ruppe <span dir="ltr"><<a href="mailto:destructionator@gmail.com" target="_blank">destructionator@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">On Monday, 26 November 2012 at 17:03:41 UTC, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Error: variable isProperty cannot be read at compile time<br>
</blockquote>
<br></div>
that doesn't make any sense :S<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
TL;DR, std.traits is extremely brittle, and rather incomplete. As a programmer with deadlines trying to get work done, it<br>
is just not yet acceptable >_<<br>
</blockquote>
<br></div>
I totally get this though... just look at this pile of crap from my web.d, which is used in some really ugly conditions.<br>
<br>
I don't even know what it all even does or why it works. It was a few weekends of random guessing:<br>
<br>
<br>
// these are all filthy hacks<br>
<br>
template isEnum(alias T) if(is(T)) {<br>
static if (is(T == enum))<br>
enum bool isEnum = true;<br>
else<br>
enum bool isEnum = false;<br>
}<br>
<br>
// WTF, shouldn't is(T == xxx) already do this?<br>
template isEnum(T) if(!is(T)) {<br>
enum bool isEnum = false;<br>
}<br>
<br>
template isStruct(alias T) if(is(T)) {<br>
static if (is(T == struct))<br>
enum bool isStruct = true;<br>
else<br>
enum bool isStruct = false;<br>
}<br>
<br>
// WTF<br>
template isStruct(T) if(!is(T)) {<br>
enum bool isStruct = false;<br>
}<br>
<br>
template Passthrough(T) {<br>
T Passthrough;<br>
}<br>
<br>
template PassthroughType(T) {<br>
alias T PassthroughType;<br>
}<br>
<br>
<br>
<br>
Soooo yeah. I'm sure there's a way to get what you want, but I'm equally sure you'll have some pain in the mean time that can take a while to figure through.<br>
</blockquote></div><br></div><div class="gmail_extra">Perhaps, but I've already spent days on this, and many hours of overtime!! I need to draw the line.</div><div class="gmail_extra">Here's what I have, and it's not even close to working:</div>
<div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">template isType( alias T )</div><div class="gmail_extra">{</div><div class="gmail_extra"><span class="" style="white-space:pre"> </span>enum isType = is( T );</div>
<div class="gmail_extra">}</div><div class="gmail_extra">template isType( T )</div><div class="gmail_extra">{</div><div class="gmail_extra"><span class="" style="white-space:pre"> </span>enum isType = is( T );</div><div class="gmail_extra">
}</div><div class="gmail_extra"><br></div><div class="gmail_extra">template isFunction( alias T )</div><div class="gmail_extra">{</div><div class="gmail_extra"><span class="" style="white-space:pre"> </span>enum isFunction = is( typeof( T ) == function );</div>
<div class="gmail_extra">}</div><div class="gmail_extra">template isFunction( T )</div><div class="gmail_extra">{</div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>enum isFunction = is( T == function );</div>
<div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra">template isEnum( alias T )</div><div class="gmail_extra">{</div><div class="gmail_extra"><span class="" style="white-space:pre">    </span>template knownAtCompileTime( alias T )</div>
<div class="gmail_extra"><span class="" style="white-space:pre">      </span>{</div><div class="gmail_extra">//<span class="" style="white-space:pre">          </span>enum knownAtCompileTime = is( typeof( { enum e = T; } ) ); // immutable breaks this approach</div>
<div class="gmail_extra"><span class="" style="white-space:pre">              </span>enum knownAtCompileTime = !__traits(compiles, ( ref typeof( T ) _x_ ) {}( T ) ); // hack to see if we can pass it by ref</div><div class="gmail_extra">
<span class="" style="white-space:pre">       </span>}</div><div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>enum isEnum = is( typeof( T ) == enum ) || knownAtCompileTime!T;</div>
<div class="gmail_extra">}</div><div class="gmail_extra">template isEnum( T )</div><div class="gmail_extra">{</div><div class="gmail_extra"><span class="" style="white-space:pre"> </span>enum isEnum = is( T == enum );</div>
<div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">template isProperty( alias T ) if(isCallable!T)</div><div class="gmail_extra">{</div><div class="gmail_extra">
<span class="" style="white-space:pre">       </span>bool isProperty = (functionAttributes!T & FunctionAttribute.property) ? true : false;</div><div class="gmail_extra">}</div><div class="gmail_extra">template isProperty( alias T ) if(!isCallable!T)</div>
<div class="gmail_extra">{</div><div class="gmail_extra"><span class="" style="white-space:pre">        </span>bool isProperty = false;</div><div class="gmail_extra">}</div><div><div>template isProperty( T )</div><div>{</div><div>
<span class="" style="white-space:pre">       </span>bool isProperty = false;</div><div>}</div></div><div><br></div></div><div class="gmail_extra">template isVariable( alias T )</div><div class="gmail_extra">{</div><div class="gmail_extra">
<span class="" style="white-space:pre">       </span>enum isVariable = !is( T ) && is( typeof( T ) )<span class="" style="white-space:pre">   </span>// if it is not a type, and does have a type, it starts to look like a variable<br>
</div><div class="gmail_extra"><span class="" style="white-space:pre">          </span>&& !isFunction!T<span class="" style="white-space:pre">                                                  </span>// reject function definitions, they can't be assigned to</div>
<div class="gmail_extra"><span class="" style="white-space:pre">              </span>&& !is( typeof( T ) == void )<span class="" style="white-space:pre">                             </span>// reject modules, which appear as a variable of type 'void'</div>
<div class="gmail_extra"><span class="" style="white-space:pre">              </span>&& !isEnum!T<span class="" style="white-space:pre">                                                              </span>// reject enum's</div><div class="gmail_extra"><span class="" style="white-space:pre">         </span>&& !isProperty!T;<span class="" style="white-space:pre">                                                 </span>// seriously, why is this not caught by the function test above?!</div>
<div class="gmail_extra">}</div><div class="gmail_extra">template isVariable( T )</div><div class="gmail_extra">{</div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>enum isVariable = false; // types aren't variables</div>
<div class="gmail_extra">}</div><div><br></div><div><br></div><div><br></div><div><br></div><div><div><div>import std.stdio;</div><div>struct a { void m(); static void n(); }</div><div>alias int b;</div><div>interface c { void l(); };</div>
<div>int d;</div><div>immutable e = 10;</div><div>void function() f;</div><div>void delegate() g;</div><div>void h() {}</div><div>enum i = 10;</div><div>enum j { k = 10 }</div><div>@property int p() { return 10; }</div><div>
<br></div><div>pragma(msg, "isType");</div><div>pragma(msg, isType!int);</div><div>pragma(msg, isType!a);</div><div>pragma(msg, isType!b);</div><div>pragma(msg, isType!c);</div><div>pragma(msg, isType!d);</div><div>
pragma(msg, isType!e);</div><div>pragma(msg, isType!f);</div><div>pragma(msg, isType!g);</div><div>pragma(msg, isType!h);</div><div>pragma(msg, isType!i);</div><div>pragma(msg, isType!j);</div><div>pragma(msg, isType!(j.k));</div>
<div>pragma(msg, isType!(c.l));</div><div>pragma(msg, isType!(a.m));</div><div>pragma(msg, isType!(a.n));</div><div>pragma(msg, isType!p);</div><div>pragma(msg, isType!std);</div><div><br></div><div>pragma(msg, "isFunction");</div>
<div>pragma(msg, isFunction!int);</div><div>pragma(msg, isFunction!a);</div><div>pragma(msg, isFunction!b);</div><div>pragma(msg, isFunction!c);</div><div>pragma(msg, isFunction!d);</div><div>pragma(msg, isFunction!e);</div>
<div>pragma(msg, isFunction!f);</div><div>pragma(msg, isFunction!g);</div><div>pragma(msg, isFunction!h);</div><div>pragma(msg, isFunction!i);</div><div>pragma(msg, isFunction!j);</div><div>pragma(msg, isFunction!(j.k));</div>
<div>pragma(msg, isFunction!(c.l));</div><div>pragma(msg, isFunction!(a.m));</div><div>pragma(msg, isFunction!(a.n));</div><div>pragma(msg, isFunction!p);</div><div>pragma(msg, isFunction!std);</div><div><br></div><div>pragma(msg, "isEnum");</div>
<div>pragma(msg, isEnum!int);</div><div>pragma(msg, isEnum!a);</div><div>pragma(msg, isEnum!b);</div><div>pragma(msg, isEnum!c);</div><div>pragma(msg, isEnum!d);</div><div>pragma(msg, isEnum!e);</div><div>pragma(msg, isEnum!f);</div>
<div>pragma(msg, isEnum!g);</div><div>pragma(msg, isEnum!h);</div><div>pragma(msg, isEnum!i);</div><div>pragma(msg, isEnum!j);</div><div>pragma(msg, isEnum!(j.k));</div><div>pragma(msg, isEnum!(c.l));</div><div>pragma(msg, isEnum!(a.m));</div>
<div>pragma(msg, isEnum!(a.n));</div><div>pragma(msg, isEnum!p);</div><div>pragma(msg, isEnum!std);</div><div><br></div><div>pragma(msg, "isProperty");</div><div>pragma(msg, isProperty!int);</div><div>pragma(msg, isProperty!a);</div>
<div>pragma(msg, isProperty!b);</div><div>pragma(msg, isProperty!c);</div><div>pragma(msg, isProperty!d);</div><div>pragma(msg, isProperty!e);</div><div>pragma(msg, isProperty!f);</div><div>pragma(msg, isProperty!g);</div>
<div>pragma(msg, isProperty!h);</div><div>pragma(msg, isProperty!i);</div><div>pragma(msg, isProperty!j);</div><div>pragma(msg, isProperty!(j.k));</div><div>pragma(msg, isProperty!(c.l));</div><div>pragma(msg, isProperty!(a.m));</div>
<div>pragma(msg, isProperty!(a.n));</div><div>pragma(msg, isProperty!p);</div><div>pragma(msg, isProperty!std);</div><div><br></div><div>pragma(msg, "isVariable");</div><div>pragma(msg, isVariable!int);</div><div>
pragma(msg, isVariable!a);</div><div>pragma(msg, isVariable!b);</div><div>pragma(msg, isVariable!c);</div><div>pragma(msg, isVariable!d);</div><div>pragma(msg, isVariable!e);</div><div>pragma(msg, isVariable!f);</div><div>
pragma(msg, isVariable!g);</div><div>pragma(msg, isVariable!h);</div><div>pragma(msg, isVariable!i);</div><div>pragma(msg, isVariable!j);</div><div>pragma(msg, isVariable!(j.k));</div><div>pragma(msg, isVariable!(c.l));</div>
<div>pragma(msg, isVariable!(a.m));</div><div>pragma(msg, isVariable!(a.n));</div><div>pragma(msg, isVariable!p);</div><div>pragma(msg, isVariable!std);</div></div></div><div><br></div></div>