GNOME Bugzilla – Bug 602511
if ( element in array ) would be a nice addition
Last modified: 2010-03-26 19:20:47 UTC
Rather than having to use ... bool found = false; for ( var i = 0; i < array.length ) { if ( array[i] == element ) found = true; } ... I tried to add a generic function that does it for me, but that seems to trigger another bug.
Created attachment 151811 [details] [review] Adds support for writing if (element in array)
Awesome, thanks for the patch. Seems to work fine. Jürg?
Thanks for the patch. While it works fine for, e.g., integer arrays, this fails for string arrays (and probably also for struct arrays). We should fix that before applying this to master as this would generate invalid code without any warnings at compile-time otherwise. There is another bug in the patch but that's easy to fix: in the patch get_array_size_cexpression is used where get_array_length_cexpression should have been usd.
Created attachment 153295 [details] [review] Updated version This version fixes the problems described above. Also gives a user doing this with incompatible types a less nonsensical error message.
commit d962523d21b0a7de631d128d224e5fa8588a4c14 Author: Robin Sonefors <ozamosi@flukkost.nu> Date: Wed Jan 20 05:41:32 2010 +0100 Support `in' operator for arrays This is already supported for some non-array types, so this patch merely extends it. Fixes bug 602511.
*** Bug 605157 has been marked as a duplicate of this bug. ***