Thread overview
Count template parameters of method
Oct 11
Andrey
Oct 11
Basile B.
Oct 12
Andrey
October 11
Hello,

How to count a number of parameters in uninitialized template method?

For example:
> struct Test
> {
>     void abc(int a, bool status, string text)() {}
> {

The method "Test.abc" has three template paramenters.

I know that "TemplateArgsOf" exists but it is used only for INITIALIZED templates...
October 11
On Sunday, 11 October 2020 at 06:53:59 UTC, Andrey wrote:
> Hello,
>
> How to count a number of parameters in uninitialized template method?
>
> For example:
>> struct Test
>> {
>>     void abc(int a, bool status, string text)() {}
>> {
>
> The method "Test.abc" has three template paramenters.
>
> I know that "TemplateArgsOf" exists but it is used only for INITIALIZED templates...

You can count the commas in the text representation  but this is not a good solution. The default value of a TemplateValueParameter can lead to wrong results, for example if it's an array literal or a string literal.

---
size_t countTP(alias T)()
{
    import std.algorithm : count;
    return T.stringof.count(',') + 1;
}

template T1(A){}
template T2(A,B){}
template T3(A,B,C){}

void main()
{
    pragma(msg, countTP!T1);
    pragma(msg, countTP!T2);
    pragma(msg, countTP!T3);
}
---

probably the countTP function can be enhanced to handle corner cases I mentioned.
October 12
And what about:
> void test() {}
and
> void text(alias qqq)() {}
?