tuple slicing operator
Vlad Levenfeld via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Aug 9 13:32:03 PDT 2014
On Saturday, 9 August 2014 at 19:26:46 UTC, Meta wrote:
> (which is why z[] gives you a type of (int, int, int) instead
> of Tuple!(int, int, int)).
That makes sense, and on second thought it wouldn't make sense to
use a tuple as a range because it's not guaranteed to have only
one element type. So, I can see how expanding the tuple is the
reasonable thing to do.
> For one thing, any type can overload the [] operator, so x[]
> can mean anything.
True, I just meant insofar as convention based on what I had (up
until the tuples) thought to be the typical usage.
> Usually slices *are* ranges, but they don't have to be, and
> it's not a good assumption to make.
Are there any specific cases where they're not?
> In generic code, you should always use template constraints and
> static if along with the appropriate traits to check facts
> about a type.
Good advice, I think I will stick to this. My approach was
sliding into 'programming by convention'.
More information about the Digitalmars-d-learn
mailing list