Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
June 04, 2015 Is there a way to get the types of all template parameters? | ||||
---|---|---|---|---|
| ||||
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 |
June 04, 2015 Re: Is there a way to get the types of all template parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Atila Neves | 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. |
June 04, 2015 Re: Is there a way to get the types of all template parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Atila Neves Attachments: | 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.
|
June 04, 2015 Re: Is there a way to get the types of all template parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | 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
|
June 04, 2015 Re: Is there a way to get the types of all template parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | 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
|
June 05, 2015 Re: Is there a way to get the types of all template parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Atila Neves | 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 |
Copyright © 1999-2021 by the D Language Foundation