Tuple indexing and slicing
Timothee Cour
thelastmammoth at gmail.com
Thu Jul 11 02:13:54 PDT 2013
On Thu, Jul 11, 2013 at 1:05 AM, Simen Kjaeraas <simen.kjaras at gmail.com>wrote:
> 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
>
ah, yes, I forgot about Types, thanks! Documentation for it could be
improved though...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130711/7b9b2714/attachment.html>
More information about the Digitalmars-d-learn
mailing list