shortcut for dynamic dispatch and operators

Pelle Månsson pelle.mansson at gmail.com
Tue Dec 1 13:26:06 PST 2009


Bill Baxter wrote:
> On Tue, Dec 1, 2009 at 12:23 PM, Bill Baxter <wbaxter at gmail.com> wrote:
>> On Tue, Dec 1, 2009 at 12:15 PM, Pelle M�nsson <pelle.mansson at gmail.com> wrote:
>>>> It's a bit difficult to see a very thin operator mask a linear operation,
>>>> but I'm thinking maybe "x in y" could be defined if y is a compile-time
>>>> array. In that case, the compiler knows the operation and the operand so it
>>>> may decide to change representation as it finds fit.
>>>>
>>>> Andrei
>>> What do you suggest using when you need to find out if an object is in an
>>> array? Arrays lacking opIn bothers me.
>> I'm guessing Andrei would recommend std.range.find.
> 
> er... std.algorithm.find, I mean.
> 
> --bb

I find

if (x in [1, 2, 3]) { }

more clear than

if ([1, 2, 3].find(x).length != 0) { }



More information about the Digitalmars-d mailing list