Questions on the new __traits(parameters)

bauss jj_1337 at live.dk
Thu Mar 10 07:21:23 UTC 2022


On Wednesday, 9 March 2022 at 19:02:27 UTC, Timon Gehr wrote:
> 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.

Surely we could work around it?


More information about the Digitalmars-d mailing list