In their versions without parameters, these two operators would be called in the same way. If both are defined, opIndex() is called, regardless of lexical definition order, according to my test with DMD.

If both (again I'm just talking about the overloads with no arguments) are defined within the same type, it's the fault of the author. But I would think the compiler should complain.

They can also be inherited, which is sneakier.

The web reference tersely says under its *Slice* Operator Overloading chapter [1]:
"To overload a[], simply define opIndex with no parameters."

Should not the overload of opSlice() with no arguments be deprecated? Am I missing something?


[1] https://dlang.org/spec/operatoroverloading.html#array-ops

Reply via email to