On Monday, 26 November 2012 at 13:08:57 UTC, Manu wrote:
On 26 November 2012 15:00, monarch_dodra
<[email protected]> wrote:
On Monday, 26 November 2012 at 12:46:10 UTC, Manu wrote:
On 26 November 2012 14:39, Andrej Mitrovic
<[email protected]>**
wrote:
On 11/26/12, Manu <[email protected]> wrote:
> 1.
>
> enum i = 10;
> pragma(msg, is(i == enum) || is(typeof(i) == enum)); // <-
> > false?!
>
> I can't find a way to identify that i is an enum, not a >
> variable;
can not
> be assigned, has no address, etc.
It's not an enum, it's a manifest constant.
Well that's certainly not intuitive. I've never even heard
that term
before. It looks awfully like an enum, with the whole 'enum'
keyword and
all ;)
How do I detect that then?
The term enum (AFAIK) is comes from an old C++ hack, where
you'd create an
actual enum to represent variable that's useable compile-time.
Anyways, when you declare an actual enumerate, you have to
declare:
1) The enum type
2) The enum values
3) The enum variable
So in your case, it would have to be:
--------
enum Enumerate
{
state1 = 10,
state2
}
Enumerate i = Enumerate.state1;
-----
I'm not looking for a hot-to use enums, I need to know how to
form an
expression to make the pragma show true in precisely that
context.
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.
If you really want to test a manifest constant, then I guess you
can test for the "lvalue-ness" of your variable:
enum i = 10;
int j = 10;
pragma(msg, __traits(compiles, (ref typeof(i) x) { } (i)));
pragma(msg, __traits(compiles, (ref typeof(j) x) { } (j)));
of the "Compile time knowability"
enum i = 10;
int j = 10;
pragma(msg, __traits(compiles, () {int[i] a;}));
pragma(msg, __traits(compiles, () {int[j] a;}));
That said, it is not an "iff" relation. I do not know of any way
to test if something is *only* a manifest constant...