www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is there a way to get the types of all template parameters?

reply "Atila Neves" <atila.neves gmail.com> writes:
For regular runtime parameters, there's ParameterTypeTuple. How 
would I write an equivalent template for template parameters? i.e.

     void fun(Foo foo, Bar bar)() {}

     alias types = CtParameterTypeTuple!fun; //TypeTuple!(Foo, Bar)

I've tried but my is expression kung fu was weak.

Atila
Jun 04 2015
next sibling parent reply "Meta" <jared771 gmail.com> writes:
On Thursday, 4 June 2015 at 13:38:20 UTC, Atila Neves wrote:
 For regular runtime parameters, there's ParameterTypeTuple. How 
 would I write an equivalent template for template parameters? 
 i.e.

     void fun(Foo foo, Bar bar)() {}

     alias types = CtParameterTypeTuple!fun; //TypeTuple!(Foo, 
 Bar)

 I've tried but my is expression kung fu was weak.

 Atila
There is http://dlang.org/phobos/std_traits.html#TemplateArgsOf, but it only works with an instantiated template.
Jun 04 2015
parent "Atila Neves" <atila.neves gmail.com> writes:
On Thursday, 4 June 2015 at 13:50:02 UTC, Meta wrote:
 On Thursday, 4 June 2015 at 13:38:20 UTC, Atila Neves wrote:
 For regular runtime parameters, there's ParameterTypeTuple. 
 How would I write an equivalent template for template 
 parameters? i.e.

    void fun(Foo foo, Bar bar)() {}

    alias types = CtParameterTypeTuple!fun; //TypeTuple!(Foo, 
 Bar)

 I've tried but my is expression kung fu was weak.

 Atila
There is http://dlang.org/phobos/std_traits.html#TemplateArgsOf, but it only works with an instantiated template.
Don't know how I missed that, thanks! Atila
Jun 04 2015
prev sibling next sibling parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Thu, 04 Jun 2015 13:38:18 +0000, Atila Neves wrote:

 For regular runtime parameters, there's ParameterTypeTuple. How would I
 write an equivalent template for template parameters? i.e.
=20
      void fun(Foo foo, Bar bar)() {}
=20
      alias types =3D CtParameterTypeTuple!fun; //TypeTuple!(Foo, Bar)
=20
 I've tried but my is expression kung fu was weak.
actually, you can't. uninstantiated template cannot be processed by=20 anything, as it's not semanticed yet. and to semantic it, you have to=20 instantiate it.=
Jun 04 2015
parent "Atila Neves" <atila.neves gmail.com> writes:
On Thursday, 4 June 2015 at 14:12:08 UTC, ketmar wrote:
 On Thu, 04 Jun 2015 13:38:18 +0000, Atila Neves wrote:

 For regular runtime parameters, there's ParameterTypeTuple. 
 How would I
 write an equivalent template for template parameters? i.e.
 
      void fun(Foo foo, Bar bar)() {}
 
      alias types = CtParameterTypeTuple!fun; //TypeTuple!(Foo, 
 Bar)
 
 I've tried but my is expression kung fu was weak.
actually, you can't. uninstantiated template cannot be processed by anything, as it's not semanticed yet. and to semantic it, you have to instantiate it.
The way I wrote it, no. But if they all have default values, then yes: TemplateArgsOf!(fun!()) Atila
Jun 04 2015
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2015-06-04 15:38, Atila Neves wrote:
 For regular runtime parameters, there's ParameterTypeTuple. How would I
 write an equivalent template for template parameters? i.e.

      void fun(Foo foo, Bar bar)() {}

      alias types = CtParameterTypeTuple!fun; //TypeTuple!(Foo, Bar)

 I've tried but my is expression kung fu was weak.
Unfortunately this is not implemented yet. But there's a pull request [1]. [1] https://github.com/D-Programming-Language/dmd/pull/3515 -- /Jacob Carlborg
Jun 04 2015