On 08/01/11 23:20, bearophile wrote:
Andrei has recently closed issue 1323, it's a small but very useful feature, so 
I suggest some public discussion:
http://d.puremagic.com/issues/show_bug.cgi?id=1323

Lines like this is present thousands of time in my Python code:
n in [1, 2, 3]
c in "hello"
"llo" in some_string

Bye,
bearophile

I'd be all for this, except it's inconsistent.
----
auto arr = [ "foo" : 1, "bar" : 2 ];
assert("foo" in arr);
----
in for associative arrays works by key, if it works by value for normal arrays it's inconsistent, and if it works for keys people will wonder why it's not working as expected.

This said, you could do something like the following:
----
import tango.core.Array;

struct Arr(T)
{
    T[] a;
    bool opIn_r(T val)
    {
        return a.find(val) != a.length;
    }
}
void main()
{
    auto myArr = Arr([1, 2, 3]);
    assert(1 in myArr);
}
----
I'm sure with some alias this magic from D2 you could make this function in an even nicer fashion.

--
Robert
http://octarineparrot.com/

Reply via email to