function(pointer) as template argument, explicit template instantiation

Tejas notrealemail at gmail.com
Fri Dec 31 03:02:08 UTC 2021


On Friday, 31 December 2021 at 00:57:26 UTC, kdevel wrote:
> ```dptr.d
> class R {
> }
>
> void foo (R r)
> {
> }
>
> alias fn = void function (R);
>
> void lyr (fn F) (R r)
> {
> }
>
> immutable fn foo_ptr = &foo; // line 14
> pragma (msg, typeof (foo_ptr));
>
> auto ptr = lyr!(foo_ptr);    // line 17
> ```
> dmd reports:
>
> ```
> immutable(void function(R))
> dptr.d(14): Error: expression `& foo` is not a valid template 
> value argument
> ```
>
> If I comment out line 17 the code compiles. I want to put the 
> explicitly instantiated function template into an immutable AA. 
> How can that be phrased such that dmd compiles it?

Is it okay to use template parameter instead of **template 
value** parameter?
```d
class R {
}

void foo (R r)
{
}

void lyr (fp_type, R) (fp_type fp, R r)
{
}

pragma (msg, typeof (&foo));
R r;
void main(){
     auto foo_ptr = &foo;
     lyr(foo_ptr, r);
}
```


More information about the Digitalmars-d-learn mailing list