The in operator and normal arrays

Dan murpsoft at hotmail.com
Thu Apr 26 08:42:41 PDT 2007


inFavor++;

Downs Wrote:
> 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