Re: Any way to expand a tuple?

2011-09-25 Thread Lutger Blijdestijn
Andrej Mitrovic wrote:

> import std.typetuple;
> import std.typecons;
> 
> struct Foo
> {
> void test(int x, double y) { }
> 
> void opOpAssign(string op, T...)(T t)
> if (op == "~")
> {
> test(t);
> }
> }
> 
> void main()
> {
> Foo foo;
> foo.opOpAssign!"~"(4, 5.0);  // ok
> foo ~= tuple(4, 5.0);  // fail
> }
> 
> If I understand this correctly in the first call T becomes a D
> language tuple, while in the second one it's a phobos library tuple. I
> really hate this distinction and would love these two to be merged so
> the second call could compile.

.expand on Tuple and generally .tupleof does the trick. Language tuples are 
quite different and more general than typecons Tuple. If tuples would 
automatically expand, this would not be possible:

import std.typetuple;
import std.typecons;
import std.stdio;

struct Foo
{
void test(Tuple!(int, int), double y) { writeln("overload a"); }
void test(int, int, double y) { writeln("overload b"); }

void opOpAssign(string op, T...)(T t)
if (op == "~")
{
test(t);
}
}

void main()
{
Foo foo;
foo.opOpAssign!"~"(tuple(4, 2), 5.0);// overload a
foo.opOpAssign!"~"(tuple(4, 2).tupleof, 5.0);// overload b
}


Re: Any way to expand a tuple?

2011-09-24 Thread Daniel Murphy
"Andrej Mitrovic"  wrote in message 
news:mailman.142.1316903007.26225.digitalmars-d-le...@puremagic.com...
>
> Is it possible to expand the phobos tuple in the call to test()? I can
> use the isTuple template in a `static if` to figure out if it needs
> expansion, so all that's left is to actually expand the phobos tuple.

Yes, use the Tuple's .expand property. 




Re: Any way to expand a tuple?

2011-09-24 Thread Jonathan M Davis
On Sunday, September 25, 2011 00:23:18 Andrej Mitrovic wrote:
> import std.typetuple;
> import std.typecons;
> 
> struct Foo
> {
> void test(int x, double y) { }
> 
> void opOpAssign(string op, T...)(T t)
> if (op == "~")
> {
> test(t);
> }
> }
> 
> void main()
> {
> Foo foo;
> foo.opOpAssign!"~"(4, 5.0);  // ok
> foo ~= tuple(4, 5.0);  // fail
> }
> 
> If I understand this correctly in the first call T becomes a D
> language tuple, while in the second one it's a phobos library tuple. I
> really hate this distinction and would love these two to be merged so
> the second call could compile.

They're completely different. The problem isn't that they're not the same. The 
problem is that TypeTuple even has a similar name.

> Is it possible to expand the phobos tuple in the call to test()? I can
> use the isTuple template in a `static if` to figure out if it needs
> expansion, so all that's left is to actually expand the phobos tuple.

expand might work, but I haven't tried it, so I don't know exactly what it 
does. I question that it'll work, but it might.

- Jonathan m Davis


Any way to expand a tuple?

2011-09-24 Thread Andrej Mitrovic
import std.typetuple;
import std.typecons;

struct Foo
{
void test(int x, double y) { }

void opOpAssign(string op, T...)(T t)
if (op == "~")
{
test(t);
}
}

void main()
{
Foo foo;
foo.opOpAssign!"~"(4, 5.0);  // ok
foo ~= tuple(4, 5.0);  // fail
}

If I understand this correctly in the first call T becomes a D
language tuple, while in the second one it's a phobos library tuple. I
really hate this distinction and would love these two to be merged so
the second call could compile.

Is it possible to expand the phobos tuple in the call to test()? I can
use the isTuple template in a `static if` to figure out if it needs
expansion, so all that's left is to actually expand the phobos tuple.