| Thread overview |
|---|
October 15, 2008 Concatenating Tuples | ||||
|---|---|---|---|---|
| ||||
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? | ||||
October 15, 2008 Re: Concatenating Tuples | ||||
|---|---|---|---|---|
| ||||
Posted in reply to dsimcha | 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;
| |||
October 15, 2008 Re: Concatenating Tuples | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BCS | == 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?
> >
> 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.
| |||
October 15, 2008 Re: Concatenating Tuples | ||||
|---|---|---|---|---|
| ||||
Posted in reply to dsimcha | 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?
>>>
>> 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).
| |||
October 15, 2008 Re: Concatenating Tuples | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BCS | == 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?
> >>>
> >> 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.
| |||
October 15, 2008 Re: Concatenating Tuples | ||||
|---|---|---|---|---|
| ||||
Posted in reply to dsimcha | == 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? > > >>> > > >> 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| | |||
October 15, 2008 Re: Concatenating Tuples | ||||
|---|---|---|---|---|
| ||||
Posted in reply to dsimcha | 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 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply