Overriding "in" operator
Simen kjaeraas
simen.kjaras at gmail.com
Fri Mar 4 08:42:09 PST 2011
Magnus Lie Hetland <magnus at hetland.org> wrote:
> On 2011-03-04 17:06:29 +0100, Mafi said:
>
>> If you try to use it in the manner of `something in
>> classWhichDefinesThisOpBinary` then it doesn't work because operator
>> overloading normally overloads on the left operand (ie something). Use
>> opBinaryRight(string op)(...) if(...) to get it working.
>
> Aaah. That makes sense. And works.
>
> *But*: I copied my code from Phobos :D If you search for "in", with the
> quotes, in std/container.d, you'll find two occurrences. The actual live
> use (in RedBlackTree) is opBinaryRight (which makes sense), but in the
> dummy class, TotalContainer, which is described as "an unimplemented
> container that illustrates a host of primitives that a container may
> define", uses just opBinary. The doc-comment says that "$(D k in
> container) returns true if the given key is in the container".
>
> So ... a "bug", I guess? (One that isn't really executed -- but
> still...) Worth reporting?
>
> Anwyay: Thanks for the clarification :)
Definitely report it.
--
Simen
More information about the Digitalmars-d-learn
mailing list