Thread overview
synthesising instantiated template parameters and arguments
Oct 28, 2020
Nicholas Wilson
Oct 28, 2020
Adam D. Ruppe
Oct 29, 2020
Jacob Carlborg
October 28, 2020
Given

template ScopeClass(C)
{
    //...
}


where C is a, possibly templated, class I want the eponymous member of ScopeClass!(C) to have the same templatedness (both parameters and arguments)as C.
For a non-template C this is a simple as:

template ScopeClass(C)
{
    class ScopeClass
    {
         // implement members with compile time reflection
    }
}

but for a templated C this is tricker as I can't use a template sequence parameter (...) unless C uses it in the same position (I'm trying to generate a mangle from it so it needs to be exact). Given

class A(T,int,args...) {}
alias C = A!(int, 0, float);

I need `ScopeClass!C` to be

template ScopeClass(C)
{
    class Anon(T,int,args...) // name doesn't matter
    {
         // implement members with compile time reflection
    }

    alias ScopeClass = Anon!(int, 0, float);
}

How do I do this?
October 28, 2020
On Wednesday, 28 October 2020 at 05:51:14 UTC, Nicholas Wilson wrote:
> class A(T,int,args...) {}
> alias C = A!(int, 0, float);
>
> I need `ScopeClass!C` to be
>
> template ScopeClass(C)
> {
>     class Anon(T,int,args...) // name doesn't matter
>     {
>          // implement members with compile time reflection
>     }
>
>     alias ScopeClass = Anon!(int, 0, float);
> }

So I'm not sure you can do what you want to do - D doesn't have any way to reflect on template parameters (though you CAN extract arguments I don't think it really helps here since you can't tell if the arguments were from `int, float` or from `T...` for example).

But like I don't really get why you need this. Can't you just use the arguments C already has and not have the extra layer? So you'd treat templated C the same was as non-templated C, and then if you want the mangle, just use like C.mangleof instead of trying to reconstruct it.

What's the bigger picture here?
October 29, 2020
On Wednesday, 28 October 2020 at 05:51:14 UTC, Nicholas Wilson wrote:

> but for a templated C this is tricker as I can't use a template sequence parameter (...) unless C uses it in the same position (I'm trying to generate a mangle from it so it needs to be exact). Given
>
> class A(T,int,args...) {}
> alias C = A!(int, 0, float);
>
> I need `ScopeClass!C` to be
>
> template ScopeClass(C)
> {
>     class Anon(T,int,args...) // name doesn't matter
>     {
>          // implement members with compile time reflection
>     }
>
>     alias ScopeClass = Anon!(int, 0, float);
> }
>
> How do I do this?

Are you looking for `TemplateArgsOf` [1] ?

[1] https://dlang.org/phobos/std_traits.html#TemplateArgsOf

--
/Jacob Carlborg