Associative arrays
Steven Schveighoffer
schveiguy at gmail.com
Tue May 18 12:53:54 UTC 2021
On 5/18/21 5:34 AM, Chris Piker wrote:
> On Tuesday, 18 May 2021 at 08:54:00 UTC, Mathias LANG wrote:
>
> Thanks for the description, that was informative :)
>
>> The following doesn't even compile:
>> ```
>> void main () nothrow
>> {
>> int[int] aa;
>> foreach (k, v; aa) {}
>> }
>> ```
>
> So basically I can use AAs, so long as I don't put them in critical
> software since they are always going to throw. No trouble, I can live
> with that, it's good to know that up front.
>
No, that's the wrong way to look at it.
`foreach(k, v; aa)` isn't nothrow, because it accepts an opApply-style
delegate. This is a language limitation, not a promise that they will
throw in some cases.
`foreach(kv; aa.byKeyValue)` is nothrow, (where kv.key and kv.value are
used to access the data), because it uses the range interface to foreach.
-Steve
More information about the Digitalmars-d
mailing list