Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
April 04, 2014 Extracting Params of Templated Type | ||||
---|---|---|---|---|
| ||||
If you have a templated type, is there a way to get the compile-time parameters it was instantiated with? Ie: ---------------------- struct Foo(T) {} alias MyFoo = Foo!int; ---------------------- Is there a way to inspect MyFoo to get its T type (in this case, 'int')? *Without* actually making any changes to Foo to explicitly support this? |
April 04, 2014 Re: Extracting Params of Templated Type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On Friday, 4 April 2014 at 04:44:56 UTC, Nick Sabalausky wrote:
> If you have a templated type, is there a way to get the compile-time parameters it was instantiated with?
>
> Ie:
>
> ----------------------
> struct Foo(T) {}
>
> alias MyFoo = Foo!int;
> ----------------------
>
> Is there a way to inspect MyFoo to get its T type (in this case, 'int')? *Without* actually making any changes to Foo to explicitly support this?
alias TemplateArgs(T: Foo!U, U) = U;
void main()
{
assert(is(TemplateArgs!MyFoo == int));
}
|
April 04, 2014 Re: Extracting Params of Templated Type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On 4/4/2014 1:02 AM, Meta wrote:
>
> alias TemplateArgs(T: Foo!U, U) = U;
>
> void main()
> {
> assert(is(TemplateArgs!MyFoo == int));
> }
Ahh thanks.
|
April 04, 2014 Re: Extracting Params of Templated Type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On 4/4/14, Meta <jared771@gmail.com> wrote:
> alias TemplateArgs(T: Foo!U, U) = U;
It's also in std.traits, TemplateArgsOf, which is more complete.
|
April 04, 2014 Re: Extracting Params of Templated Type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Friday, 4 April 2014 at 07:23:51 UTC, Andrej Mitrovic wrote:
> On 4/4/14, Meta <jared771@gmail.com> wrote:
>> alias TemplateArgs(T: Foo!U, U) = U;
>
> It's also in std.traits, TemplateArgsOf, which is more complete.
I thought I remembered that being in std.traits, but I couldn't find it after quickly skimming. I must've glanced over it.
|
Copyright © 1999-2021 by the D Language Foundation