std.format and enums

JC johnch_atms at hotmail.com
Mon Oct 23 05:54:55 PDT 2006


Here's a suggestion for improving std.format.doFormat.

Currently, std.format.doFormat throws FormatError when it encounters an enum 
constant as one of the arguments. It's easy for it to get the integer 
representation and format that instead. TypeInfo_Enum has a "base" field 
from which you can determine the underlying type. This should do it:

// After case Mangle.Ttypedef
case Mangle.Tenum:
    ti = (cast(TypeInfo_Enum)ti).base;
    m = cast(Mangle)ti.classinfo.name[9];
    formatArg(fc);
    return;

Should this be added to Phobos? In an ideal world, the enum constant's name 
would be available, but this seems a reasonable alternative, and is better 
than throwing an error. 





More information about the Digitalmars-d mailing list