April 05, 2012 Re: Questions about the slice operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christophe | 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
|
April 05, 2012 Re: Questions about the slice operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christophe | Christophe:
> Having a specific range for a .. operator allows you to have them as parameters of any function.
Such functions are also able to accept a Iota struct and then read its fields to find its bounds.
For Jonathan M Davis: the first class intervals seem nice to have, but they aren't near the top of the list of my enhancement requests :-)
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation