Tuple indexing and slicing

Timothee Cour thelastmammoth at gmail.com
Wed Jul 10 18:10:42 PDT 2013


On Wed, Jul 10, 2013 at 5:49 PM, Artur Skawina <art.08.09 at gmail.com> wrote:

> On 07/11/13 00:52, Timothee Cour wrote:
> > Why not support Tuple indexing and slicing with [] syntax?
> >  (see below for a way to index/slice a tuple)
>
> Not sure I understand the question.
> I guess you'd like this to work for some library pseudo-tuple type
> - I've not looked at those, somebody else may give you a better answer.
>
> "Native" tuples already support what you're asking for:
>
>    template Tuple(A...) { alias Tuple = A; }
>
>    void main(){
>      alias T=Tuple!(int,double);
>      pragma(msg,T[0].stringof);
>      pragma(msg,T[0..2].stringof);
>      pragma(msg,typeof(T.init[0]).stringof);
>      pragma(msg,typeof(Tuple!(T.init[0..$])).stringof);
>    }
>
> artur
>

I know native tuples do, I am aksing about std.typecons.Tuple.
Is there any way to support this in library code ?
If not, how about changing compiler to allow this?

I'd like that:
static assert(is(Tuple!(int,double)[0]==int));
static assert(is(Tuple!(int,double)[0..$]==Tuple!(int,double)));
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130710/aebda7e1/attachment.html>


More information about the Digitalmars-d-learn mailing list