On Wednesday, November 22, 2017 08:03:50 Fra Mecca via Digitalmars-d-learn wrote: > Why doesn't D have a in keyword for arrays? > > The docs explains that you can use in only for associative arrays > but I don't see the reasons for such decision. > > > Example code: > > void main() > { > auto v = ["r", "i", "o"]; > assert ("r" in v); > } > > > That currently fails: > main.d(4): Error: incompatible types for (("r") in (v)): 'string' > and 'string[]'
in is supposed to be at worst O(log n), whereas to do the operation for an array would be O(n). If you want to search for a specific element in an array than use std.algorithm.find or std.algorithm.canFind. - Jonathan M Davis