Tuple indexing and slicing
Simen Kjaeraas
simen.kjaras at gmail.com
Thu Jul 11 01:05:48 PDT 2013
On 2013-07-11, 00:52, Timothee Cour wrote:
> 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)
> }
This works:
import std.typecons : Tuple, tuple;
void main() {
alias T = Tuple!(int, string, float);
T a;
Tuple!(int, string) b = tuple(a[0..2]); // Slicing values.
Tuple!(T.Types[1..3]) c; // Slicing types.
}
--
Simen
More information about the Digitalmars-d-learn
mailing list