enhancing enums

Bill Baxter wbaxter at gmail.com
Tue Dec 8 15:06:35 PST 2009


On Tue, Dec 8, 2009 at 2:17 PM, hehe45 <a3161739 at uggsrock.com> wrote:
> In c++ it is valid syntax to have trailing commas at the and of enum definitions:
> enum {a, b, c, };
> This would be a useful addition to D too.
>
> The enum class syntax from c++0x should also adopted by D, this would allow named enums which are not automatically encased by a namespace:
>
> enum EnumName {A, B, C};       ---> A, B and C are global constants
> enum class EnumName {A, B, C};---> A, B and C are in the EnumName namespace
>

That's basically what it is now:

enum { A,B,C }  --> A,B,C global
enum EnumName {A,B,C} --> EnumName.A, EnumName.B and EnumName.C

The thing lacking from D is C++'s "using namespace EnumName" to bring
A,B,C into the current namespace.  Closest thing is the much reviled
"with" which I think works with an enum name, but I could be wrong.
Not very useful either way, though, because usually you don't want a
new scope.

--bb



More information about the Digitalmars-d mailing list