issue with static foreach

Paul Backus snarwin at gmail.com
Thu Jul 22 18:28:16 UTC 2021


On Thursday, 22 July 2021 at 18:16:54 UTC, Tejas wrote:
> On Thursday, 22 July 2021 at 18:06:07 UTC, Paul Backus wrote:
>> On Thursday, 22 July 2021 at 17:38:09 UTC, Tejas wrote:
>>> Why does this work?
>>>
>>> ```d
>>> import std;
>>> void main()
>>> {
>>>     mixin("int") a;
>>>     writeln(a);
>>> }
>>> ```
>>
>> You can mix in a type:
>>
>> https://dlang.org/spec/type.html#mixin_types
>
> Looks like special casing to me... is it allowed because they 
> are guaranteed to not introduce a scope, I wonder.

The list of things you're allowed to mix in is:

* expressions
* statements
* declarations
* types

In some sense it is special casing, since there's no overarching 
rule that determines what goes on that list and what doesn't.


More information about the Digitalmars-d-learn mailing list