[Issue 538] Can't return an expression tuple from a function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Nov 18 10:49:48 PST 2006
http://d.puremagic.com/issues/show_bug.cgi?id=538
------- Comment #4 from wbaxter at gmail.com 2006-11-18 12:49 -------
In any event, you are correct that it does not say anywhere that you should be
able to return an expression tuple from a function.
On the other hand you can convert a struct to an expression tuple and
initialize it's values by setting elements of the tuple. So there really
shouldn't be much difference at the metal level between returning a struct{int
x, int y} and a Tuple!(int,int). It should be doable as long as it's an
expression tuple.
I tried for a while to write a simple list picking template. I got it working
for type tuples:
template Pick(TList...)
{
template Indexes(int I, IList...)
{
static if (IList.length==0)
{
alias TList[I] Indexes;
}
else
{
alias Tuple!(TList[I], Indexes!(IList)) Indexes;
}
}
template PickArgs(IList...) {
alias With!(IList) DList;
DList PickArgs(TList arg) {
DList darg;
return darg;
}
}
}
alias Tuple!(int,float,char[],long) ArgTSet;
alias Tuple!(0,3,1) IdxSet;
alias Pick!(ArgTSet) P;
alias P.Indexes!(IdxSet) sublist;
writefln(typeid(sublist));
Output: int, long, float
But I couldn't figure out any way to do the equivalent with an Expression tuple
without having return values. Hmm, maybe it was just a bug that was causing
the problem.
Here's my test for expression tuples:
alias Tuple!(3,2.3,"hi",9) args;
alias Pick!(args) P2;
alias P2.Indexes!(IdxSet) subargs;
writefln(subargs);
It fails to compile with a "tuple TList is used as a type". But looking at it
now I think that may just be a compiler error. I think maybe that should work.
TList shouldn't have to be a type to define that alias. (Otherwise alias
Tuple!(3,2.3,"hi",9) should fail too).
--
More information about the Digitalmars-d-bugs
mailing list