Cases where I miss C++ 'using'
Daniel Keep
daniel.keep.lists at gmail.com
Tue Nov 7 18:32:20 PST 2006
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.
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)
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 :)
-- Daniel
--
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d
mailing list