Bug or Feature: `this` necessary to call function with template this parameter
    Simen Kjærås 
    simen.kjaras at gmail.com
       
    Wed Oct 30 21:35:54 UTC 2019
    
    
  
On Wednesday, 30 October 2019 at 20:22:25 UTC, Q. Schroll wrote:
> struct Example
> {
>     private void helper(int i, this X)() { }
>     void funcTempl(T, this X)(T value)
>     {
>         this.helper!0();
>     //  ^^^^^ Why do I need this?
>     }
> }
>
> void main()
> {
>     auto ex = Example();
>     ex.funcTempl(1);
> }
>
> The question is in the comment in the code. Is that intentional 
> or a bug?
It's a bug - filed as 
https://issues.dlang.org/show_bug.cgi?id=20341.
However, note that typeof(this) inside funcTempl() is different 
from X, so that inside helper(), X will not be the same as in 
funcTempl(). To fix this, you will need to pass X on to helper as 
helper!(0, X). When you do this, you no longer need 'this.' in 
front of the instantiation.
--
   Simen
    
    
More information about the Digitalmars-d-learn
mailing list