On 02/11/2011 07:39 PM, bearophile wrote:
spir:

To denote a member 'm' of an enum 'e', one needs to write "e.m". Is there a way
to get back this "name"?

Is this good enough?

import std.stdio, std.conv;
enum TC { A, B, C }
void main() {
     writeln(typeof(TC.A).stringof, ".", to!string(TC.A));
}

Yo! thank you Bearophile.

A bit strange that '%s' does not produce the same string as to!string...

I agree, I have a bug report on this.

More generally, I think default %s and to!string should systematically output the literal notation able to reconstruct the string'ed element. I mean, as far as possible without getting into much complication (in cases of struct or class object, which often have data members not read in by the contructor). About the annoying case of strings, is there a tool func somewhere to reconstruct an escaped version? (like eg when the string holds '"') I have looked for it without success. Else, i guess Phobos very much needs that. (the equivalent of python's %r or repr() for strings)

Simple, clear, consistent, informative, useful.

Denis
--
_________________
vita es estrany
spir.wikidot.com

Reply via email to