Suggestion: Operator `in` for slices

Araq rumpf_a at
Mon Dec 20 11:28:52 UTC 2021

On Monday, 20 December 2021 at 11:04:00 UTC, Dennis wrote:
> On Sunday, 19 December 2021 at 18:31:46 UTC, Steven 
> Schveighoffer wrote:
>> There's your answer -- make a custom type that allows `in` 
>> with an array-like structure.
> For the record, I'm not arguing in favor of `in` for slices. 
> I'm just baffled that whenever this comes up, the first thing 
> people bring up is the 'time complexity' argument.
>> That kind of expectation is useful from a generic point of 
>> view.
> And this is my biggest problem with that argument: it's about 
> this mystical function that takes a generic data structure and 
> uses the `in` operator multiple times on it, which can now 
> suddenly be called on an array, ruining performance to the 
> surprise of the programmer.
> What is this function? Does it exist in Phobos currently?

And how come it cannot store the result of the "in" operation in 
a local variable for re-use? And how exactly is calling an 
oh-so-efficient sub-linear O(log N) function repeatedly when you 
can save the result in a local *not* a problem?

More information about the Digitalmars-d mailing list