opIndex vs. opSlice for empty slices

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 21 22:47:27 PDT 2015


I've always used opSlice to produce empty slices, but having 
recently read the documentation at [1], I see this:

"To overload a[], simply define opIndex with no parameters:"

And no mention that opSlice can fill the same role. Am I right to 
infer that we should prefer opIndex over opSlice for this? If so, 
what's the rationale?


[1] http://dlang.org/operatoroverloading.html#slice


More information about the Digitalmars-d-learn mailing list