www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - tupleof feature request

reply bc <mi_emayl_adrez hotmail.com> writes:
i was thinking, it would be nice if you could do some of these things:

import std.stdio;

template Tuple(E...)
{
     alias E Tuple;
}

alias Tuple!(int, int) TL;

void main()
{
	TL tl;
	struct S
	{
		int x;
		int y;
	}
	S s;
	s.x =3D 1;
	s.y =3D 2;
	=

	tl =3D s.tupleof;
	/* gives:
	C:\Code\D\Test\testtuple.d(21): Error: tl is not an lvalue
	C:\Code\D\Test\testtuple.d(21): Error: forward reference to type (int, =
 =

int)
	C:\Code\D\Test\testtuple.d(21): Error: cannot implicitly convert  =

expression (tuple((s.X),(s.Y))) of type (int, int) to (int, int)
	*/
	auto tl2 =3D s.tupleof;
	writefln(tl2);
	// this outputs '00'. would be nicer if it did '12'
	tl2 =3D s.tupleof; // doesn't compile
	s.tupleof =3D tl2; // doesn't compile
}
Sep 21 2007
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"bc" <mi_emayl_adrez hotmail.com> wrote in message 
news:op.ty0sldi3u40fk4 hal9000...
------------------------------------------
i was thinking, it would be nice if you could do some of these things:

import std.stdio;

template Tuple(E...)
{
     alias E Tuple;
}

alias Tuple!(int, int) TL;

void main()
{
TL tl;
struct S
{
int x;
int y;
}
S s;
s.x = 1;
s.y = 2;

tl = s.tupleof;
auto tl2 = s.tupleof;
writefln(tl2);
tl2 = s.tupleof; // doesn't compile
s.tupleof = tl2; // doesn't compile
}
------------------------------------------

Don Clugston and I (and probably others ;) ) have suggested some kind of 
unification of tuples and structs before.  You could do some cool stuff. 
Sep 21 2007