July 10, 2013 Tuple indexing and slicing | ||||
---|---|---|---|---|
| ||||
Attachments:
| Why not support Tuple indexing and slicing with [] syntax? (see below for a way to index/slice a tuple) void main(){ alias T=Tuple!(int,double); pragma(msg,T[0].stringof);//_expand_field_0 //pragma(msg,T[0..2].stringof); //Error: cannot slice type 'Tuple!(int, double) pragma(msg,typeof(T.init[0]).stringof);//int pragma(msg,typeof(tuple(T.init[0..$])).stringof);//Tuple!(int,double) } |
July 10, 2013 Re: Tuple indexing and slicing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timothee Cour | Timothee Cour:
> Why not support Tuple indexing and slicing with [] syntax?
You need a syntax like:
a.slice!(1, 3);
I don't know why Walter didn't add support for a slicing syntax for tuples. But it's an additive change, so it's not too much late to add it, if it's feasible.
If D will grow built-in tuples (that currently is among my top enhancement requests for D), probably the slice syntax will be supported.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation