Questions on the new __traits(parameters)

Paul Backus snarwin at gmail.com
Thu Mar 10 12:49:57 UTC 2022


On Wednesday, 9 March 2022 at 10:04:57 UTC, Quirin Schroll wrote:
> In the changelog it says:
>> When used inside a foreach using an overloaded `opApply`, the 
>> trait yields the parameters to the delegate and not the 
>> function the foreach appears within.
>
> Why? This will rarely be wanted or be used intentionally. When 
> a programmer uses `__traits(parameters)` in a `foreach` loop, 
> it will for certain happen to someone not aware of this. The 
> iteration implemention (`opApply` or range functions) is a 
> detail one should not really have to care about on the usage 
> side. This complicates the language. Morally, this is a bug. 
> Please reconsider this design decision before it sticks.

 From [the PR discussion][1], the rationale given for the current 
behavior was:

> I'm not sure whether this was desirable or not, but it's not 
> really along the lines of how this feature is intended to be 
> used so I don't see any utility any different behaviour.

So there is no real justification for it; the interaction with 
`foreach` was just not considered important enough to be worth 
the effort of handling correctly.

[1]: https://github.com/dlang/dmd/pull/13071


More information about the Digitalmars-d mailing list