digitalmars.D.learn - Bug or Feature: `this` necessary to call function with template this
- Q. Schroll (16/16) Oct 30 2019 struct Example
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (10/26) Oct 30 2019 It's a bug - filed as
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?
Oct 30 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
Oct 30 2019