On Tue, 24 Nov 2009 10:44:45 -0500, Robert Clipsham <[email protected]> wrote:

Long Chang wrote:
class RegExp
{
    enum Option{
        X, Y, Z
    }
    int options;
    this(int options = 0){ this.options = options; }
}
 void main(){
       auto reg  = new RegExp("^A.",   .Option(  X |Y|Z ) );
assert( RegExp .Option.X | RegExp .Option.Y| RegExp .Option.Z == reg.options );
}

----
class Foo
{
         enum Option
         {
                 X = 2,
                 Y = 4,
                 Z = 8
         }
         int options;
         this(int opts = 0)
         {
                 options = opts;
         }
}

void main()
{
         Foo foo;
         with( foo.Option )
         {
                 foo = new Foo( X | Y | Z );
                 assert( X | Y | Z == foo.options  );
         }
}
----

Is this the kind of thing you're looking for? That looks nicer than your proposed syntax in my opinion :)

Forgetting about the assert, you don't like this one-liner?

auto foo = new Foo(Foo.Option(X | Y | Z));

I think we can even make the Foo go away, I think Java does something like that.

compared to your version (without assert):

Foo foo;
with(foo.Option) foo = new Foo(X | Y | Z);

-Steve

Reply via email to