Double bracket "{{" for scoping static foreach is no longer part of D

data pulverizer data.pulverizer at gmail.com
Wed Dec 22 16:25:56 UTC 2021


On Wednesday, 22 December 2021 at 16:01:49 UTC, rikki cattermole 
wrote:
> Seems to be working just fine as of 2.098.
>
> ```d
> import std;
> void main()
> {
>     static foreach(Foo; ["Abc", "def"]) {{
>         string str = Foo;
>     	writeln("Hello D ", str, __VERSION__);
>     }}
> }
> ```
>
> ```
> Hello D Abc2098
> Hello D def2098
> ```

I see, It looks like I remembered incorrectly about using `{{` in 
templates! It seems that it doesn't work in templates or in 
"global" (outside main), so for instance neither this

```
// compiled with -o- flag
static foreach(Foo; ["Abc", "def"])
{{
     enum str = Foo;
   pragma(msg, "Hello D ", str, __VERSION__);
}}

```

nor this

```
template Demo()
{
   static foreach(Foo; ["Abc", "def"])
   {{
       enum str = Foo;
     pragma(msg, "Demo: Hello D ", str, __VERSION__);
   }}
   enum Demo = null;
}

void main()
{
   Demo!()
}
```

will run. It gives an error `Error: declaration expected, not {`.


More information about the Digitalmars-d-learn mailing list