Questions about the slice operator

Jonathan M Davis jmdavisProg at gmx.com
Thu Apr 5 11:23:48 PDT 2012


On Thursday, April 05, 2012 14:58:41 Christophe wrote:
> "Jonathan M Davis" , dans le message (digitalmars.D.learn:34243), a
> 
> > Except that opSlice already works with "..". What would this buy you?

As I said, all it does is give you syntactic sugar for iota which can't even 
do as much as iota can (since it lacks a step parameter).

But my point that you're quoting has nothing to do with using .. with 
functions in general. It specifically has to do with creating a new overload 
for opSlice as Jacob suggestios - i.e. when you do a[0 .. 5] where a is an 
instance of a user-defined type. That works just fine with auto opSlice (size_t 
start, size_t end). The range type buys you nothing for that, and in fact 
would be _more_ expensive, since it would have to allocate a struct rather 
than simply passing the two indices.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list