Calling template member function?
    Andrey Zherikov 
    andrey.zherikov at gmail.com
       
    Wed Apr 20 00:44:11 UTC 2022
    
    
  
On Tuesday, 19 April 2022 at 20:29:01 UTC, Steven Schveighoffer 
wrote:
> You can work around the dual context, if you are OK with 
> passing the second context explicitly.
>
> The easiest way is to move the member function to a UFCS 
> function. an example:
>
> ```d
> struct X
> {
>    int x;
>    void applyToX(alias fn)() {fn(x);}
> }
>
> void applyToX_alt(alias fn)(ref X xval) {
>    fn(xval.x);
> }
>
> void main()
> {
>    auto s = X(5);
>    int y = 6;
>    void fn(ref int x) { x += y; }
>    s.applyToX!fn; // error, dual context needed
>    s.applyToX_alt!fn; // fine, only single context needed
> }
> ```
I used struct to understand the problem. I don't actually have an 
object context to pass like in your example, the only context I 
have is template parameters.
    
    
More information about the Digitalmars-d-learn
mailing list