'in' for arrays?
Lionello Lunesu
lio at lunesu.remove.com
Wed Dec 6 00:32:37 PST 2006
Bill Baxter wrote:
> I keep wanting to say
> if (val in somearray) {
> }
It makes sense to make "in" behave as if an int[] is a int[int], but the
problem is that "in" for normal arrays is O(n), slow. If you need to
search the array, you probably should have been using another container
in the first place.
My philosophy is always that CPU-expensive actions should also appear as
such in code. A small "in" that actual does a linear search might seem a
like a good idea, but people should be discouraged from using it.
L.
More information about the Digitalmars-d
mailing list