The in operator and normal arrays

Downs default_357-line at yahoo.de
Thu Apr 26 01:47:24 PDT 2007


Myron Alexander wrote:
> Bill Baxter wrote:
>> I've proposed this before.  Maybe others too.  It makes sense.  It's 
>> what other languages with an 'in' operator do.  It should work.  It 
>> doesn't.  It isn't high on Walter's priority list because it can be 
>> worked around easily.
>>
>> --bb
> 
> I suspected as much. Thanks for the info. I add my voice of support for 
> the proposal to expand the in operator to operate on normal arrays.

Agreed. If only because it is expected to work that way, and didn't we learn that breaking expectations is Sin?

In the meantime, a workaround with a comparable functionality as opIn would be

T *has(T)(T[] array, T match) { foreach (inout elem; array) if (elem==match) return &elem; return null; }
void main() { auto a=[0, 1, 2, 3]; if (&a[3] is a.has(3)) writefln("OK"); }

Greetings ^^



More information about the Digitalmars-d mailing list