More uses of operator "in"

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 28 11:29:48 PDT 2014


On Tuesday, 28 October 2014 at 17:50:30 UTC, Baz wrote:
> On Tuesday, 28 October 2014 at 16:32:13 UTC, Marc Schütz wrote:
>> On Tuesday, 28 October 2014 at 15:11:01 UTC, Baz wrote:
>>> On Tuesday, 28 October 2014 at 13:50:24 UTC, Nordlöw wrote:
>>>> Has there been any proposals/plans to make operator "in" 
>>>> work for elements in ranges such as
>>>>
>>>>  assert('x' in ['x']);
>>>>
>>>> I'm missing that Python feature when I work in D.
>>>
>>> There is also something similar in Pascal, at the language 
>>> level. Very handy when working with characters or enums.
>>
>> AFAIR it's limited to sets in Pascal, where its complexity is 
>> O(1).
>
> If "in" is used as a syntactic sugar, e.g to call 
> "std.algorithm.canFind" in a custom type, then why would the 
> bigO be a concern ?

It always was the argument against generalizing `in` to arrays. 
`in` is not alone in this respect. It's also expected that 
indexing and slicing be "cheap" operations.


More information about the Digitalmars-d-learn mailing list