On Thu, May 31, 2012 at 7:14 PM, simendsjo <[email protected]> wrote:
> On Thu, 31 May 2012 18:42:20 +0200, bearophile <[email protected]>
> wrote:
>
>> simendsjo:
>>
>>> int a;
>>> string b;
>>> ToTuple!(a, b) should create Tuple!(int, "a", string, "b")
>>>
>>> template ToTuple(Variables...) {
>>> ?
>>> }
Is the following what you're looking for?
import std.stdio;
import std.typecons;
import std.typetuple;
template TypeAndName(Variables...)
{
static if (Variables.length == 0)
alias TypeTuple!() TypeAndName;
else
alias TypeTuple!(typeof(Variables[0]), Variables[0].stringof,
TypeAndName!(Variables[1..$])) TypeAndName;
}
Tuple!(TypeAndName!(Variables)) toTuple(Variables...)() @property
{
return Tuple!(TypeAndName!(Variables))(Variables);
}
void main()
{
int i = 1;
double d = 3.14;
auto t = toTuple!(i,d);
writeln(t.i);
writeln(t.d);
}