digitalmars.D - enhancing enums
- hehe45 (6/6) Dec 08 2009 In c++ it is valid syntax to have trailing commas at the and of enum def...
- bearophile (5/12) Dec 08 2009 Global constants are a little dangerous, I don't like that.
- Nick Sabalausky (4/10) Dec 08 2009 That's right. And I think it's also allowed for array literals. Very han...
- Ellery Newcomer (2/15) Dec 08 2009 it's only allowed for array initializers
- Nick Sabalausky (4/23) Dec 08 2009 Oh yea, that's right. A real strange inconsistency. I hope that gets fix...
- Phil Deets (3/9) Dec 08 2009 and in D2.
- Bill Baxter (13/19) Dec 08 2009 ow named enums which are not automatically encased by a namespace:
- Nick Sabalausky (6/21) Dec 08 2009 The difference though is that doesn't make A, B and C part of a new type...
- Mike Parker (6/32) Dec 08 2009 Which is a very good thing, from my perspective. I cut down the size of
- Nick Sabalausky (4/30) Dec 08 2009 I would think that could be optimized away. Maybe it would be a linker
- Jeremie Pelletier (14/48) Dec 08 2009 If i remember right there is some code in phobos that relies on
- =?iso-8859-2?B?VG9tZWsgU293afFza2k=?= (7/16) Dec 08 2009 Please no. I've done some C++ but the "need semicolon after brace?" is ...
- Nick Sabalausky (4/11) Dec 08 2009 I don't think he was talking about the semicolon, just the comma between...
- Jeremie Pelletier (5/13) Dec 08 2009 I don't think that's necessary, you could simply do:
- Lars T. Kyllingstad (3/22) Dec 09 2009 Not any more. typedef will be removed from D2.
- Jeremie Pelletier (4/29) Dec 09 2009 Ah hmm, I missed that thread.
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
Dec 08 2009
hehe45: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.I think that's already possible in D1.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 namespaceGlobal constants are a little dangerous, I don't like that. Bye, bearophile
Dec 08 2009
"bearophile" <bearophileHUGS lycos.com> wrote in message news:hfmlkl$1kil$1 digitalmars.com...hehe45:That's right. And I think it's also allowed for array literals. Very handly feature. Although I had no idea that C++ also allowed it.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.I think that's already possible in D1.
Dec 08 2009
On 12/08/2009 06:35 PM, Nick Sabalausky wrote:"bearophile"<bearophileHUGS lycos.com> wrote in message news:hfmlkl$1kil$1 digitalmars.com...it's only allowed for array initializershehe45:That's right. And I think it's also allowed for array literals. Very handly feature. Although I had no idea that C++ also allowed it.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.I think that's already possible in D1.
Dec 08 2009
"Ellery Newcomer" <ellery-newcomer utulsa.edu> wrote in message news:hfmssk$2n2d$1 digitalmars.com...On 12/08/2009 06:35 PM, Nick Sabalausky wrote:Oh yea, that's right. A real strange inconsistency. I hope that gets fixed for D2."bearophile"<bearophileHUGS lycos.com> wrote in message news:hfmlkl$1kil$1 digitalmars.com...it's only allowed for array initializershehe45:That's right. And I think it's also allowed for array literals. Very handly feature. Although I had no idea that C++ also allowed it.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.I think that's already possible in D1.
Dec 08 2009
On Tue, 08 Dec 2009 17:57:25 -0500, bearophile <bearophileHUGS lycos.com> wrote:hehe45:and in D2.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.I think that's already possible in D1.
Dec 08 2009
On Tue, Dec 8, 2009 at 2:17 PM, hehe45 <a3161739 uggsrock.com> wrote:In c++ it is valid syntax to have trailing commas at the and of enum defi=nitions: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 all=ow named enums which are not automatically encased by a namespace:enum EnumName {A, B, C}; =A0 =A0 =A0 ---> A, B and C are global constants enum class EnumName {A, B, C};---> A, B and C are in the EnumName namespa=ceThat'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
Dec 08 2009
"Bill Baxter" <wbaxter gmail.com> wrote in message news:mailman.581.1260313623.20261.digitalmars-d puremagic.com...On Tue, Dec 8, 2009 at 2:17 PM, hehe45 <a3161739 uggsrock.com> wrote:The difference though is that doesn't make A, B and C part of a new type. Personally, I'm fine with that though (well, except for the whole "let's pretend manifest constants are an 'enum'" absurdity), because I *hate* enums that pollute the namespace with their members.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 namespaceThat's basically what it is now: enum { A,B,C } --> A,B,C global
Dec 08 2009
Nick Sabalausky wrote:"Bill Baxter" <wbaxter gmail.com> wrote in message news:mailman.581.1260313623.20261.digitalmars-d puremagic.com...Which is a very good thing, from my perspective. I cut down the size of the Derelict libraries quite a bit when I converted all the named enums and other constants into anonymous enums, thereby eliminating all the TypeInfo objects. In that particular case, TypeInfo is just useless bloat, IMO.On Tue, Dec 8, 2009 at 2:17 PM, hehe45 <a3161739 uggsrock.com> wrote:The difference though is that doesn't make A, B and C part of a new type.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 namespaceThat's basically what it is now: enum { A,B,C } --> A,B,C globalPersonally, I'm fine with that though (well, except for the whole "let's pretend manifest constants are an 'enum'" absurdity), because I *hate* enums that pollute the namespace with their members.
Dec 08 2009
"Mike Parker" <aldacron gmail.com> wrote in message news:hfmvkn$nvv$1 digitalmars.com...Nick Sabalausky wrote:I would think that could be optimized away. Maybe it would be a linker optimization though."Bill Baxter" <wbaxter gmail.com> wrote in message news:mailman.581.1260313623.20261.digitalmars-d puremagic.com...Which is a very good thing, from my perspective. I cut down the size of the Derelict libraries quite a bit when I converted all the named enums and other constants into anonymous enums, thereby eliminating all the TypeInfo objects. In that particular case, TypeInfo is just useless bloat, IMO.On Tue, Dec 8, 2009 at 2:17 PM, hehe45 <a3161739 uggsrock.com> wrote:The difference though is that doesn't make A, B and C part of a new type.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 namespaceThat's basically what it is now: enum { A,B,C } --> A,B,C global
Dec 08 2009
Nick Sabalausky wrote:"Mike Parker" <aldacron gmail.com> wrote in message news:hfmvkn$nvv$1 digitalmars.com...If i remember right there is some code in phobos that relies on typeinfos to do safe string formatting and integer to identifier conversion for enums. Still I agree that there should be a way to turn off typeinfo generation for most types (except classes of course, that would screw up dynamic casts). One way would be to have a switch like --minimal-typeinfo that reduces all TypeInfo instances to a mere int that is an index into a primitives array [byte, short, int, long, ubyte, ushort, uint, ulong, float, double, real, ...] to still enable the routines that relies on typeinfos to work. That way even if you have a thousands enum's, their combined typeinfo data is 4 bytes long in the executable.Nick Sabalausky wrote:I would think that could be optimized away. Maybe it would be a linker optimization though."Bill Baxter" <wbaxter gmail.com> wrote in message news:mailman.581.1260313623.20261.digitalmars-d puremagic.com...Which is a very good thing, from my perspective. I cut down the size of the Derelict libraries quite a bit when I converted all the named enums and other constants into anonymous enums, thereby eliminating all the TypeInfo objects. In that particular case, TypeInfo is just useless bloat, IMO.On Tue, Dec 8, 2009 at 2:17 PM, hehe45 <a3161739 uggsrock.com> wrote:The difference though is that doesn't make A, B and C part of a new type.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 namespaceThat's basically what it is now: enum { A,B,C } --> A,B,C global
Dec 08 2009
Dnia 08-12-2009 o 23:17:55 hehe45 <a3161739 uggsrock.com> napisa=B3(a):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.Please no. I've done some C++ but the "need semicolon after brace?" is = always something I need to think twice about.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 =namespaceD enums are already like that. Use with(EnumName) to get a temporary = relief from prefixing constants with EnumName all the time. Tomek
Dec 08 2009
"Tomek Sowiński" <just ask.me> wrote in message news:op.u4m6tf2eot0hzo las-miodowy...Dnia 08-12-2009 o 23:17:55 hehe45 <a3161739 uggsrock.com> napisał(a):I don't think he was talking about the semicolon, just the comma between the "c" and the "}".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.Please no. I've done some C++ but the "need semicolon after brace?" is always something I need to think twice about.
Dec 08 2009
hehe45 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 namespaceI don't think that's necessary, you could simply do: typedef int EnumName; enum : EnumName {A, B, C} And your global scope is happily polluted!
Dec 08 2009
Jeremie Pelletier wrote:hehe45 wrote:Not any more. typedef will be removed from D2. -LarsIn 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 namespaceI don't think that's necessary, you could simply do: typedef int EnumName; enum : EnumName {A, B, C} And your global scope is happily polluted!
Dec 09 2009
Lars T. Kyllingstad wrote:Jeremie Pelletier wrote:Ah hmm, I missed that thread. That was about the biggest use I had for typedefs, but this case can use aliases just as well.hehe45 wrote:Not any more. typedef will be removed from D2. -LarsIn 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 namespaceI don't think that's necessary, you could simply do: typedef int EnumName; enum : EnumName {A, B, C} And your global scope is happily polluted!
Dec 09 2009