enhancing enums

Jeremie Pelletier jeremiep at gmail.com
Tue Dec 8 21:35:18 PST 2009


Nick Sabalausky wrote:
> "Mike Parker" <aldacron at gmail.com> wrote in message 
> news:hfmvkn$nvv$1 at digitalmars.com...
>> Nick Sabalausky wrote:
>>> "Bill Baxter" <wbaxter at gmail.com> wrote in message 
>>> news:mailman.581.1260313623.20261.digitalmars-d at puremagic.com...
>>>> 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
>>> The difference though is that doesn't make A, B and C part of a new type.
>>
>> 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.
>>
> 
> I would think that could be optimized away. Maybe it would be a linker 
> optimization though.
> 
> 

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.



More information about the Digitalmars-d mailing list