identof || toIdent - feature suggestion / question

Daniel Keep daniel.keep.list at gmail.com
Sun Jul 2 02:21:52 PDT 2006


Tom S wrote:
> Would it be hard to add a construct to D that would convert a 
> compile-time string to an identifier ?
> 
> E.g.
> 
> int identof("foo");
> // would be equivalent to:
> int foo;
> // and
> identof("int") foo;
> // and
> identof("int") identof("foo");
> 
> 
> It would allow programmatic data structure construction through 
> templates. It would also be useful while converting C macros like:
> 
> [snip]

I've had the same idea myself several times (although I wanted to use 
"ident" instead).  Originally, I wanted it for making properties easier 
to use.

The problem with templates/mixins at the moment is that they can't 
generate new identifiers.  For example, I'd love to be able to do this:

# mixin attribute!(int, "foo", Public /*read*/, Private /*write*/);

Which would save a huge amount of essentially useless boilerplate code. 
  The problem is, of course, that I can't generate that "foo" properly. 
  The only way to do it is to manually declare the storage, and then 
alias the getter and setter seperately... and then it ends up being just 
as long as writing it manually.

So this definitely has my vote++ :)

	-- Daniel



More information about the Digitalmars-d mailing list