www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Feature request: with for enums

reply "Janice Caron" <caron800 googlemail.com> writes:
I would like to be able to do

    enum MyEnum
    {
        first, second, third, fourth, fifth, sixth, seventh eighth
    }

    MyEnum[100] table =
    [
        MyEnum.first,
        MyEnum.second,
        MyEnum.eighth,
        MyEnum.first,
        ...
    ];

without all that ridiculous qualifying. Maybe it's possible to do that
already, but if so, I haven't found anything which compiles. I would
have expected the following to work, but it doesn't:

    with(MyEnum) MyEnum[100] table =
    [
        first,
        second,
        eighth,
        first,
        ...
    ];

Apparently, "with" only works with structs and classes - not enums.
I'm wondering if this can be extended and made to work also with
enums?

(...or if there's something I've missed, someone please tell me).
Mar 10 2008
next sibling parent Moritz Warning <moritzwarning _nospam_web.de> writes:
On Mon, 10 Mar 2008 09:54:12 +0000, Janice Caron wrote:
[..]
     with(MyEnum) MyEnum[100] table =
     [
         first,
         second,
         eighth,
         first,
         ...
     ];
 
 Apparently, "with" only works with structs and classes - not enums. I'm
 wondering if this can be extended and made to work also with enums?
 
 (...or if there's something I've missed, someone please tell me).
What you ask for is not possible yet. As far as I can remember, Walter thought about adding this kind of feature (at least for switch). But I don't think it got much further since there is much other stuff to do.
Mar 10 2008
prev sibling next sibling parent Ary Borenszweig <ary esperanto.org.ar> writes:
Janice Caron wrote:
 I would like to be able to do
 
     enum MyEnum
     {
         first, second, third, fourth, fifth, sixth, seventh eighth
     }
 
     MyEnum[100] table =
     [
         MyEnum.first,
         MyEnum.second,
         MyEnum.eighth,
         MyEnum.first,
         ...
     ];
 
 without all that ridiculous qualifying. Maybe it's possible to do that
 already, but if so, I haven't found anything which compiles. I would
 have expected the following to work, but it doesn't:
 
     with(MyEnum) MyEnum[100] table =
     [
         first,
         second,
         eighth,
         first,
         ...
     ];
 
 Apparently, "with" only works with structs and classes - not enums.
 I'm wondering if this can be extended and made to work also with
 enums?
 
 (...or if there's something I've missed, someone please tell me).
I think using enums without fully qualifying them is a planned feature for D2. At least it says that in the first slides: http://d.puremagic.com/conference2007/speakers.html (see Enum Member Lookup Rules) So maybe with won't be necessary for enums.
Mar 10 2008
prev sibling parent Matti Niemenmaa <see_signature for.real.address> writes:
Janice Caron wrote:
 Apparently, "with" only works with structs and classes - not enums.
 I'm wondering if this can be extended and made to work also with
 enums?
 
 (...or if there's something I've missed, someone please tell me).
This has been requested before, as well: http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=40548 http://www.digitalmars.com/d/archives/digitalmars/D/37925.html -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
Mar 10 2008