Questions on the new __traits(parameters)

Timon Gehr timon.gehr at gmx.ch
Wed Mar 9 19:02:27 UTC 2022


On 3/9/22 11:04, 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.

It's a consequence of how such a foreach loop is lowered. Looks like one 
of those cases where a bug was resolved by changing the specification.


More information about the Digitalmars-d mailing list