Tuples and array literals

Daniel Keep daniel.keep.lists at gmail.com
Tue Mar 6 18:48:29 PST 2007



Jari-Matti Mäkelä wrote:
> I tried to search the ng and dstress test cases, but there was nothing
> about these.
> 
> So here are the working ones:
> 
>   const a = [1,2];
>   int[] b = [1,2];
> 
>   struct foo {
>     const int[] c = [1,2];
>     const d = [1,2];
>   }
> 
>   void main() {
>     const e = [1,2];
>   }
> 
> These ones don't work:
> 
>   template Tuple(E...) { alias E Tuple; }
>   alias Tuple!(0,1) TP;
> 
>   const a = [ TP ];
>   int[] b = [ TP ];
> 
>   struct foo {
>     const int[] c = [ TP ];
>     const d = [ TP ];
>   }
> 
> So, are these going to be fixed in future releases or is there some
> serious limitation in the template/tuple system that prevents any of
> these? Any workarounds that make use of tuples?

I'm not an expert on Tuples, but I don't think you can alias expression
tuples like (0,1), for the same reason you can't alias 1 or 2.

The solution is the same: put it in a constant.

  typeof(Tuple!(0,1)) TP = Tuple!(0,1);

The problem here is that I'm not sure if assigning between tuples works,
either.  I remember having to write a loop to do it...

> foreach( i, e ; tuple )
>     TP[i] = e;

To be honest, I haven't really played with expression tuples all that
much, so I could be totally off-base.  None the less, something to think
about :)

	-- Daniel

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/


More information about the Digitalmars-d-learn mailing list