About the in expression, Why can't use with array.

IGotD- nise at nise.com
Fri Oct 25 16:19:31 UTC 2019


On Thursday, 24 October 2019 at 12:58:11 UTC, lili wrote:
> Hi:
>    In Dlang where is strange design. The in expression can only 
> use to associative array, why array can not use in expression.

I don't see much of a problem why this couldn't be implemented as 
long as the user understands the limitations of it. In real life, 
linear searches are often completely acceptable when the number 
of items are in a few hundreds or less of them. Depends on the 
use case of course.

Many has answered because of search complexity but one thing is 
that use case with associative arrays is to have unique keys. 
This is not the case for arrays which allows duplicates which not 
to seldom the case. Naturally an implementation would take the 
first hit and return that object. Why it isn't implemented for 
arrays, I suspect it has to do more that the search can be 
ambiguous as the array allows duplicates. Still I think a linear 
search in an array should be implemented based on a first hit 
search.



More information about the Digitalmars-d-learn mailing list