_aaApply2
Quirin Schroll
qs.il.paperinik at gmail.com
Mon Jul 22 18:17:10 UTC 2024
On Monday, 22 July 2024 at 15:28:45 UTC, H. S. Teoh wrote:
> On Mon, Jul 22, 2024 at 11:11:53AM +0000, Quirin Schroll via
> Digitalmars-d wrote:
>> On Sunday, 21 July 2024 at 16:44:56 UTC, IchorDev wrote:
>> > Shouldn't AAs be using a range interface instead of opApply
>> > these days? Is really there any reason for a `foreach` over
>> > an AA not to be `nothrow`?
>>
>> The range interface doesn’t really support key–value pair
>> iteration.
> [...]
>
> Sure it does.
Not in the way it’s supposed to. `foreach (v; aa)` is supposed to
run over values and `foreach (k, v; aa)` over keys `k` and values
`v`. From the range interface, `front` can only return one thing.
If it’s a tuple that can decay into two values, sure the `k, v`
one works, but the `v` one gives you tuples, not values.
More information about the Digitalmars-d
mailing list