Wrong initialization of variables
Andrey
saasecondbox at yandex.ru
Mon Apr 1 16:31:08 UTC 2019
Hello,
Simple code:
> import std.stdio;
>
> mixin template DeclFlag(alias values)
> {
> static foreach(value; values)
> {
> mixin("bool has" ~ value ~ " = false;");
> }
> }
>
> enum Key : string
> {
> First = "qwerty",
> Last = "zaqy"
> }
>
> void main()
> {
> enum data = [Key.First, Key.Last];
> mixin DeclFlag!(data);
>
> static foreach(value; data)
> {
> writeln(mixin("has" ~ value));
> }
> }
The output is:
> true
> true
But in template mixin DeclFlag all variables are inited with
"false" value!
Also with AST switch I get code where there aren't any lines with
text "bool hasqwerty = false;" or "bool haszaqy = false;". What
happens?
More information about the Digitalmars-d-learn
mailing list