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
?
Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 21 _aaApply2 | ||||
---|---|---|---|---|
| ||||
July 21 Re: _aaApply2 | ||||
---|---|---|---|---|
| ||||
Posted in reply to IchorDev | 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 Probaly history, ranges were d2, aa's in d1 look basically the same https://digitalmars.com/d/1.0/hash-map.html |
July 22 Re: _aaApply2 | ||||
---|---|---|---|---|
| ||||
Posted in reply to IchorDev | 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 The range interface doesn’t really support key–value pair iteration. An AA can be iterated by values or keys and values. A range interface can’t do that. The issue is that iteration isn’t |
July 22 Re: _aaApply2 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Quirin Schroll | On Monday, 22 July 2024 at 11:11:53 UTC, Quirin Schroll wrote: >The range interface doesn’t really support key–value pair iteration. Yes it does? >An AA can be iterated by values or keys and values. A range interface can’t do that. Indeed, only one or the other. We should really fix this somehow though, because opApply sucks with all of D’s different function attributes. >The issue is that iteration isn’t I guess because the function calls an un-marked delegate? I’m not even sure how I’m able to call it in |
July 22 Re: _aaApply2 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Quirin Schroll | 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. Check the implementation in object.d, internally it uses a range over a struct that encapsulates the key and value pair. You can actually use this interface in user code too: aa.byKeyValue(). The non-range interface is really for compatibility with legacy code. T -- How many guacas are in 1 guacamole? 6.022*10^23, also known as Avocado's Number. |
July 22 Re: _aaApply2 | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Monday, 22 July 2024 at 15:28:45 UTC, H. S. Teoh wrote: >You can actually use this interface in user code too: aa.byKeyValue(). The non-range interface is really for compatibility with legacy code. The struct has one loop value instead of two though, so you have to rewrite code to use |
July 22 Re: _aaApply2 | ||||
---|---|---|---|---|
| ||||
Posted in reply to IchorDev | On Monday, 22 July 2024 at 15:49:54 UTC, IchorDev wrote: >The struct has one loop value instead of two though, so you have to rewrite code to use
|
July 22 Re: _aaApply2 | ||||
---|---|---|---|---|
| ||||
Posted in reply to IchorDev | On Monday, 22 July 2024 at 15:25:32 UTC, IchorDev wrote: >On Monday, 22 July 2024 at 11:11:53 UTC, Quirin Schroll wrote: >The issue is that iteration isn’t See https://issues.dlang.org/show_bug.cgi?id=21236. >I guess because the function calls an un-marked delegate? I’m not even sure how I’m able to call it in It's @safe for the compiler to generate a call to it if the loop body is @safe. If the body wasn't safe, there would be an error anyway. >and yet it supposedly uses the GC just for iteration? Do you have an example? The following compiles:
|
July 22 Re: _aaApply2 | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | 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 The range interface doesn’t really support key–value pair iteration. Sure it does. Not in the way it’s supposed to. |
July 25 Re: _aaApply2 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | On Monday, 22 July 2024 at 16:00:05 UTC, Nick Treleaven wrote: >
This won’t be an issue anymore once we have |