A custom name for variables

solidstate1991 laszloszeremi at outlook.com
Fri May 29 20:53:46 UTC 2020


On Thursday, 28 May 2020 at 20:26:55 UTC, Quantium wrote:
> I need to create a variable with custom name, like this
> import std;
> void main()
> {
>     string name;
>     readf(" %s", &name);
>     // some code that generates a variable of type integer and 
> value 0
> }
> Could you help me with that?

This might be possible in certain scripting languages, but not in 
D.

Static fields are generated during compile time, and while 
something like that is possible using template mixins in the code 
(famous use in D is Phobos's bitfields, which generates 
properties for a struct or a class), it's impossible during 
runtime, and - in extension - by reading a value from console.


More information about the Digitalmars-d-learn mailing list