Concatenating Tuples
dsimcha
dsimcha at yahoo.com
Tue Oct 14 21:05:29 PDT 2008
== Quote from dsimcha (dsimcha at yahoo.com)'s article
> == Quote from BCS (ao at pathlink.com)'s article
> > Reply to dsimcha,
> > > == Quote from BCS (ao at 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?
> > >>>
> > >> 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;
> > > 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.
> > >
> > That should work there as well, if it dosn't work, it's a bug. (I think).
> 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.
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|
More information about the Digitalmars-d
mailing list