Cases where I miss C++ 'using'

Bill Baxter dnewsgroup at billbaxter.com
Tue Nov 7 19:58:27 PST 2006


Daniel Keep wrote:
> 
> Jari-Matti Mäkelä wrote:
>> Daniel Keep wrote:
>>>> Finally I wish there were some way to bring all the values in an *enum*
>>>> into the current name resolution scope.  For example:
>>>>
>>>> enum Buttons {
>>>>    Left,
>>>>    Right,
>>>>    Middle
>>>> }
>>>> with(Buttons) {  // doesn't work!
>>>>    x = Left|Middle
>>>> }
>>>> alias Buttons B;
>>>> y = B.Left | B.Middle;  // ok, but not as nice looking
>>>>
>>>>
>>>> --bb
>>> Allowing you to use an Enum's name without the prefix is one of the
>>> things I actually miss about Visual Basic.  Sure, requiring the prefix
>>> is nice for the sake of organisation, but it gets *really* aggravating
>>> after a while.
>> I mostly use enums inside switch statements. Java makes a nice
>> compromise here by only requiring the prefix outside switches. I don't
>> like making them accessible everywhere without prefixing.
> 
> True, since that negates one of the benefits of Enums: organisation.

I don't want them to be available everywhere either.  Just in particular 
functions or scopes where I'm going to be using them heavily.  I don't 
see why that ability should be limited to the insides of switch 
statements.

> One thing I thought was very cool (I can't remember if this was VB6 or
> VB.Net) was that if you were calling a function that took an enum, you
> could omit the prefix.  ie:
> 
>> Sub Foo(SomeEnum e)
> 
> Could be called:
> 
>> Foo(SomeEnum.Bar)
> 
> Or:
> 
>> Foo(Bar)

I would like that.  That's one of my biggest annoyances with C++ that 
still remains in D right there.

But there are ambiguities with operator overloading.  But that's no 
biggie, the compiler just needs to complain if leaving off the enum type 
creates an ambiguous overload situation.

> Maybe if we allowed the prefix to be omitted when
> a. we're switching on an enum,
> b. we're passing an enum argument to a function and
> c. when we're assigning to an enum typed variable
> 
> that would be enough.  Then again, maybe that's just because I'm a lazy
> bugger :)

Me too.  But its not just laziness.  Having lots of repetitive cruft in 
the code makes it harder to see what's really going on.

--bb



More information about the Digitalmars-d mailing list