opSlice and $

S. S at s.com
Tue Sep 11 13:16:58 PDT 2007


Oskar Linde Wrote:

> Sean Kelly wrote:
> > Russell Lewis wrote:
> >> It appears to me, looking at the spec, that there isn't a way to 
> >> support the use of $ in operator overloading.  Is there anything I've 
> >> overlooked?  What I'm looking for, of course, is to be able to do:
> >>
> >> class MyClass {....}
> >>
> >> MyClass c = new MyClass;
> >> auto x = c[1..$];
> > 
> > The '$' symbol should map to "size_t length()" when used with opSlice, 
> > but at the moment I don't think this is the case.
> 
> The problem how that generalizes to multidimensional slicing:
> c[1..$, 2..$]
> 
> -- 
> Oskar


Multidimensional slicing isn't mentioned in the language spec.  When was this added?

I would rather see $ be an alias for int.max for overloaded operators.  This should be included in the spec, and then it is up to the overloaded operator to handle this to mean the last item. (either that or there could be another type added for indexes that includes this concept as a special bit sequence)



More information about the Digitalmars-d mailing list