Getting the string representing the enum value ~ Proposal

pragma pragma_member at pathlink.com
Mon Apr 3 15:08:12 PDT 2006


In article <e0rsbe$1hdm$1 at digitaldaemon.com>, kris says...
>
>pragma wrote:
>> In article <e0pqn7$1ngo$1 at digitaldaemon.com>, kris says...
>> 
>>>I'll propose that a new property be added, somewhat like the .mangleof 
>>>property. Instead, a .nameof property would simply return the lexical 
>>>token for the named entity. Doesn't matter whether it refers to a 
>>>struct, class, some attribute thereof, enum types or members, whatever 
>>>... the x.nameof should just return a char[] of the respective name.
>>>
>>>Thoughts?
>> 
>> 
>> It gets my vote - but there are a few kinks to work out.
>> 
>> For instance, how does this compare to .classname or TypeInfo.toString()?
>
>For classes, I think it would be equivalent to .classname (since that 
>returns a char[] of the class name). I suspect TypeInfo.toString() is a 
>different kettle of fish, since it deals with type information instead 
>of names per se?
>
>> 
>> I'd imagine that it would follow the same behavior as .mangleof (possibly all
>> the way around), with respect to aliases and typedefs.  Templates might be kind
>> of sticky though -- any ideas on that?
>
>I think it would, as you say, follow the same behaviour as .mangleof ~ a 
>  simple concept with simple rules; Had imagined .nameof would simply 
>give you an equivalent name for anything that you can legitimately 
>dereference. Regarding templates, does .mangleof do anything unexpected?

Well, you can only name-mangle a template instance, since they technically don't
exist otherwise.  The result is often a *very* complicated mangling that is a
composite of the template name, namespace and all the type arguments that
comprise it.  So the .nameof might have to be something simple, and less useful
and unique than the .mangleof rendition.

class Foo(X){}
const char[] bar = Foo!(int).mangleof; // should probably just yield "Foo"

- EricAnderton at yahoo



More information about the Digitalmars-d-learn mailing list