digitalmars.D.learn - Getting .init of a Typetuple
- Johannes Pfau (25/25) Aug 19 2010 Hi,
- Simen kjaeraas (10/33) Aug 19 2010 This works for me:
- Philippe Sigaud (16/34) Aug 19 2010 Hmm, I'm pretty sure it used to worked, because as one time that's what ...
- Simen kjaeraas (8/13) Aug 19 2010 Doh. I believe this is slightly better, though:
- Philippe Sigaud (6/19) Aug 19 2010 What, that's *five* more characters, five! I win, I win!
- Simen kjaeraas (10/15) Aug 19 2010 Seems you are right. I thought the template would work as a namespace,
- Johannes Pfau (4/15) Aug 20 2010 Great, that works! Thanks for the quick reply.
Hi, I want to do exactly the same as described in http://d.puremagic.com/issues/show_bug.cgi?id=4536 . The problem is I can't even get the workaround to work. Dmd complains about the following template: --------------------------------------------------------------- template Init(T...) { alias (Tuple!T.init).expand Init; } --------------------------------------------------------------- Dmd output: --------------------------------------------------------------- test.d(18): basic type expected, not ( test.d(18): found '!' when expecting ')' test.d(18): semicolon expected to close alias declaration test.d(18): no identifier for declarator T.init test.d(18): semicolon expected, not ')' test.d(18): Declaration expected, not ')' --------------------------------------------------------------- Is it possible that this has recently stopped working? Is this a bug in dmd or is this the expected behavior? Is there any other way to achieve the same thing? -- Johannes Pfau
Aug 19 2010
Johannes Pfau <spam example.com> wrote:Hi, I want to do exactly the same as described in http://d.puremagic.com/issues/show_bug.cgi?id=4536 . The problem is I can't even get the workaround to work. Dmd complains about the following template: --------------------------------------------------------------- template Init(T...) { alias (Tuple!T.init).expand Init; } --------------------------------------------------------------- Dmd output: --------------------------------------------------------------- test.d(18): basic type expected, not ( test.d(18): found '!' when expecting ')' test.d(18): semicolon expected to close alias declaration test.d(18): no identifier for declarator T.init test.d(18): semicolon expected, not ')' test.d(18): Declaration expected, not ')' --------------------------------------------------------------- Is it possible that this has recently stopped working? Is this a bug in dmd or is this the expected behavior? Is there any other way to achieve the same thing?This works for me: template Init( T ) { alias TypeTuple!( T.init ) Init; } template Init( T, U... ) { alias TypeTuple!( T.init, Init!U ) Init; } -- Simen
Aug 19 2010
On Thu, Aug 19, 2010 at 21:51, Simen kjaeraas <simen.kjaras gmail.com>wrote:Johannes Pfau <spam example.com> wrote: Hi,Hmm, I'm pretty sure it used to worked, because as one time that's what I used. Anyway, Simen's solutions is better, a bit less dependency. TypeTuple is a bit more universal than Tuple. Simen:I want to do exactly the same as described in http://d.puremagic.com/issues/show_bug.cgi?id=4536 . The problem is I can't even get the workaround to work. Dmd complains about the following template: --------------------------------------------------------------- template Init(T...) {alias (Tuple!T.init).expand Init;}template Init( T ) { alias TypeTuple!( T.init ) Init; } template Init( T, U... ) { alias TypeTuple!( T.init, Init!U ) Init; }And, looking in my codebase, here is what I'm using ;) template Init(T...) { T Init; } It's so simple... I think I found this before the bug report and then forgot about it and copied an old version. I'll update the bug report accordingly, if the latter version works for you. Philippe
Aug 19 2010
Philippe Sigaud <philippe.sigaud gmail.com> wrote:And, looking in my codebase, here is what I'm using ;) template Init(T...) { T Init; }Doh. I believe this is slightly better, though: template Init( T... ) { enum T Init; } :p -- Simen
Aug 19 2010
On Thu, Aug 19, 2010 at 22:16, Simen kjaeraas <simen.kjaras gmail.com>wrote:Philippe Sigaud <philippe.sigaud gmail.com> wrote: And, looking in my codebase, here is what I'm using ;)What, that's *five* more characters, five! I win, I win! More seriously, yours might be more 'solid', but isn't enum implicit in this case? Anyway, T.init should exist, since "T Init;" works... Philippetemplate Init(T...) { T Init; }Doh. I believe this is slightly better, though: template Init( T... ) { enum T Init; } :p
Aug 19 2010
Philippe Sigaud <philippe.sigaud gmail.com> wrote:What, that's *five* more characters, five! I win, I win!;'(More seriously, yours might be more 'solid', but isn't enum implicit in this case?Seems you are right. I thought the template would work as a namespace, giving this situation: Init!int = 4; int a = Init!int; // What, 4?! But such is not the case.Anyway, T.init should exist, since "T Init;" works...Indeed. -- Simen
Aug 19 2010
On 19.08.2010 22:07, Philippe Sigaud wrote:And, looking in my codebase, here is what I'm using ;) template Init(T...) { T Init; } It's so simple... I think I found this before the bug report and then forgot about it and copied an old version. I'll update the bug report accordingly, if the latter version works for you.Great, that works! Thanks for the quick reply. -- Johannes Pfau
Aug 20 2010