On 26 November 2012 15:27, monarch_dodra <span dir="ltr"><<a href="mailto:monarchdodra@gmail.com" target="_blank">monarchdodra@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Monday, 26 November 2012 at 13:08:57 UTC, Manu wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On 26 November 2012 15:00, monarch_dodra <<a href="mailto:monarchdodra@gmail.com" target="_blank">monarchdodra@gmail.com</a>> wrote:<br>
<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On Monday, 26 November 2012 at 12:46:10 UTC, Manu wrote:<br>
<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 26 November 2012 14:39, Andrej Mitrovic <<a href="mailto:andrej.mitrovich@gmail.com" target="_blank">andrej.mitrovich@gmail.com</a>>**<div><div class="h5"><br>
wrote:<br>
<br>
On 11/26/12, Manu <<a href="mailto:turkeyman@gmail.com" target="_blank">turkeyman@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> 1.<br>
><br>
> enum i = 10;<br>
> pragma(msg, is(i == enum) || is(typeof(i) == enum)); // <-<br>
> > false?!<br>
><br>
> I can't find a way to identify that i is an enum, not a > > variable;<br>
can not<br>
> be assigned, has no address, etc.<br>
<br>
It's not an enum, it's a manifest constant.<br>
<br>
<br>
</blockquote>
Well that's certainly not intuitive. I've never even heard that term<br>
before. It looks awfully like an enum, with the whole 'enum' keyword and<br>
all ;)<br>
How do I detect that then?<br>
<br>
</div></div></blockquote><div><div class="h5">
<br>
The term enum (AFAIK) is comes from an old C++ hack, where you'd create an<br>
actual enum to represent variable that's useable compile-time.<br>
<br>
Anyways, when you declare an actual enumerate, you have to declare:<br>
1) The enum type<br>
2) The enum values<br>
3) The enum variable<br>
<br>
So in your case, it would have to be:<br>
--------<br>
enum Enumerate<br>
{<br>
state1 = 10,<br>
state2<br>
}<br>
Enumerate i = Enumerate.state1;<br>
-----<br>
<br>
</div></div></blockquote>
<br><div class="im">
I'm not looking for a hot-to use enums, I need to know how to form an<br>
expression to make the pragma show true in precisely that context.<br>
</div></blockquote>
<br>
Is see, but (unfortunatly), as already mentioned, the keyword "enum" is also used to create a manifest constant. That means the tests you are giving your i are irrelevant.<br>
<br>
If you really want to test a manifest constant, then I guess you can test for the "lvalue-ness" of your variable:<br>
enum i = 10;<br>
int j = 10;<br>
pragma(msg, __traits(compiles, (ref typeof(i) x) { } (i)));<br>
pragma(msg, __traits(compiles, (ref typeof(j) x) { } (j)));<br>
<br>
of the "Compile time knowability"<br>
enum i = 10;<br>
int j = 10;<br>
pragma(msg, __traits(compiles, () {int[i] a;}));<br>
pragma(msg, __traits(compiles, () {int[j] a;}));<br>
<br>
That said, it is not an "iff" relation. I do not know of any way to test if something is *only* a manifest constant...<br>
</blockquote></div><br></div><div class="gmail_extra">That's sooo brutal! But it works, I'll use the first one, the second depends on i being an int.</div>