[Challenge] implementing the ambiguous operator in D

Pelle pelle.mansson at gmail.com
Wed Sep 1 23:34:44 PDT 2010


On 09/01/2010 11:49 PM, Peter Alexander wrote:
> On 1/09/10 9:08 PM, Philippe Sigaud wrote:
>> Peter, can we discuss your solution here?
>
> Sure, I'd be interested to hear any improvements. Like I said in my
> answer, I'm still learning D so I'm sure there's many issues. For
> example, I made no attempt for const-correctness or anything like that
> (mostly for simplicity).
>
> In particular, I'd be interested in knowing if there's a better way to
> write opDispatch i.e. a way that doesn't use that ugly mixin.

It needs opEquals :-)

something like this

     auto opEquals(E e) {
         auto cmp = (E a) { return a == e; };
         return map!cmp(r);
     }

...

     writeln(5 == amb([1,2,3,4,5]));

[false, false, false, false, true]


More information about the Digitalmars-d mailing list