www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Concatenating Tuples

reply dsimcha <dsimcha yahoo.com> writes:
Is there a way to concatenate tuples at compile time in D2?  The obvious ~
operator doesn't work on tuples.  Also, while I'm at it, maybe there's a
better way to achieve my end goal here.  Is there a way to get a tuple
representation of a class object that includes the stuff from the base classes?
Oct 14 2008
parent reply BCS <ao pathlink.com> writes:
Reply to dsimcha,

 Is there a way to concatenate tuples at compile time in D2?  The
 obvious ~ operator doesn't work on tuples.  Also, while I'm at it,
 maybe there's a better way to achieve my end goal here.  Is there a
 way to get a tuple representation of a class object that includes the
 stuff from the base classes?
 

just put them side by side. template Tpl(T...) { alias T Tpl; } alias Tpl!(a,b,c) A; alias Tpl!(d,e,f) B; alias Tpl!(A,B) C;
Oct 14 2008
parent reply dsimcha <dsimcha yahoo.com> writes:
== Quote from BCS (ao pathlink.com)'s article
 Reply to dsimcha,
 Is there a way to concatenate tuples at compile time in D2?  The
 obvious ~ operator doesn't work on tuples.  Also, while I'm at it,
 maybe there's a better way to achieve my end goal here.  Is there a
 way to get a tuple representation of a class object that includes the
 stuff from the base classes?

template Tpl(T...) { alias T Tpl; } alias Tpl!(a,b,c) A; alias Tpl!(d,e,f) B; alias Tpl!(A,B) C;

Sorry for the poorly worded question. What you suggested would work for type tuples. I'm looking for a way to do this for value tuples, i.e. the kind you would get from Object.tupleof.
Oct 14 2008
next sibling parent reply BCS <ao pathlink.com> writes:
Reply to dsimcha,

 == Quote from BCS (ao pathlink.com)'s article
 
 Reply to dsimcha,
 
 Is there a way to concatenate tuples at compile time in D2?  The
 obvious ~ operator doesn't work on tuples.  Also, while I'm at it,
 maybe there's a better way to achieve my end goal here.  Is there a
 way to get a tuple representation of a class object that includes
 the stuff from the base classes?
 

template Tpl(T...) { alias T Tpl; } alias Tpl!(a,b,c) A; alias Tpl!(d,e,f) B; alias Tpl!(A,B) C;

for type tuples. I'm looking for a way to do this for value tuples, i.e. the kind you would get from Object.tupleof.

That should work there as well, if it dosn't work, it's a bug. (I think).
Oct 14 2008
parent reply dsimcha <dsimcha yahoo.com> writes:
== Quote from BCS (ao pathlink.com)'s article
 Reply to dsimcha,
 == Quote from BCS (ao pathlink.com)'s article

 Reply to dsimcha,

 Is there a way to concatenate tuples at compile time in D2?  The
 obvious ~ operator doesn't work on tuples.  Also, while I'm at it,
 maybe there's a better way to achieve my end goal here.  Is there a
 way to get a tuple representation of a class object that includes
 the stuff from the base classes?

template Tpl(T...) { alias T Tpl; } alias Tpl!(a,b,c) A; alias Tpl!(d,e,f) B; alias Tpl!(A,B) C;

for type tuples. I'm looking for a way to do this for value tuples, i.e. the kind you would get from Object.tupleof.


Sorry, you're right. My bad. I thought I already had tried this and it didn't work but I guess not. Seems to work now.
Oct 14 2008
parent dsimcha <dsimcha yahoo.com> writes:
== Quote from dsimcha (dsimcha yahoo.com)'s article
 == Quote from BCS (ao pathlink.com)'s article
 Reply to dsimcha,
 == Quote from BCS (ao pathlink.com)'s article

 Reply to dsimcha,

 Is there a way to concatenate tuples at compile time in D2?  The
 obvious ~ operator doesn't work on tuples.  Also, while I'm at it,
 maybe there's a better way to achieve my end goal here.  Is there a
 way to get a tuple representation of a class object that includes
 the stuff from the base classes?

template Tpl(T...) { alias T Tpl; } alias Tpl!(a,b,c) A; alias Tpl!(d,e,f) B; alias Tpl!(A,B) C;

for type tuples. I'm looking for a way to do this for value tuples, i.e. the kind you would get from Object.tupleof.


work but I guess not. Seems to work now.

Ok, now I know why this has been so weird. Looks like we do have a legit bug here. Your suggestion works in the toy case, but not in my actual use case. I'll file this in Bugzilla if someone else hasn't found it already. //The following works. import std.stdio, std.typetuple; void main() { auto foo = TypeTuple!("1 ", "2 "); auto bar = TypeTuple!("3"); writeln(TypeTuple!(foo, bar)); } //The following doesn't work. import std.stdio, std.typetuple; void main() { auto foo = new Foo; writeln(TypeTuple!(foo.tupleof)); } Error messages: D:\code\test\test3.d|13|Error: tuple is not a valid template value argument| E:\dmd\bin\..\src\phobos\std\typetuple.d|13|template instance std.typetuple.TypeTuple!(tuple((Foo).a)) error instantiating|
Oct 14 2008
prev sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Wed, Oct 15, 2008 at 12:05 AM, dsimcha <dsimcha yahoo.com> wrote:

 //The following doesn't work.

 import std.stdio, std.typetuple;

 void main() {
    auto foo = new Foo;
    writeln(TypeTuple!(foo.tupleof));
 }

 Error messages:

 D:\code\test\test3.d|13|Error: tuple is not a valid template value argument|
 E:\dmd\bin\..\src\phobos\std\typetuple.d|13|template instance
 std.typetuple.TypeTuple!(tuple((Foo).a)) error instantiating|

http://d.puremagic.com/issues/show_bug.cgi?id=1670
Oct 15 2008