On 11/17/2011 09:33 AM, bearophile wrote:
Andrei Alexandrescu:

This is actually a pretty awesome fail.


Derived from those thoughts, an idea for Phobos, a bitFlags function:
http://d.puremagic.com/issues/show_bug.cgi?id=6946

A desire:
http://d.puremagic.com/issues/show_bug.cgi?id=6916

Example:

import std.stdio;
enum : int { A, B }
void main() {
     writeln(B); // I'd like it to print "B" here.
}


Hmm. How would that work? A and B don't have an own type.
Your program is equivalent to

import std.stdio;
enum A = 0;
enum B = 1;
void main() {
    writeln(B); // prints 1 because B is replaced with 1.
}

You could use mixins to automatically generate
alias E.A A;
alias E.B B;
// ...

for a given enumerated type.

import std.stdio, ...;
enum E : int { A, B }
mixin Import!E;
void main() {
     writeln(B); // prints "B"
}

Reply via email to