Global operator overloading?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Aug 6 18:54:58 PDT 2009
Jeremie Pelletier wrote:
> Are there any plans to have global operator overloading in D?
>
> It would be terribly useful with ranges, since std.array already define range primitives for arrays, I tried to implement array primitives to ranges the same way, ie:
>
> ---
> bool opEquals(T, U)(T t, U, u) if(isInputRange!T && isInputRange!U) {
> return equal(t, u);
> }
> ---
>
> so I wouldnt have to change every a==b to equal(a, b) when using ranges where built-in arrays were previously used.
>
> Of course if theres another way to do it (other than manually adding opEquals and others to every range declaration in phobos), feel free to suggest it.
I guess the compiler could rewrite a == b into a.opEquals(b) and then
let normal rules find opEquals(a, b). The latter could sit in object.d.
Andrei
More information about the Digitalmars-d
mailing list