template this and traits getOverloads issue.

2015-11-20 Thread BBasile via Digitalmars-d-learn
Background: === http://stackoverflow.com/questions/33764540/warning-about-overriden-methods-when-using-a-mixin Why this horrible trick has to be used: === cast this as (T) in a function template that's been mixed in an ancestor is not always usable,

Re: template this and traits getOverloads issue.

2015-11-20 Thread Alex Parrill via Digitalmars-d-learn
Alternatively, you can use a static method and pass in the instance. Note that `new B` will print A's members twice, because A's constructor is always called and `__traits(allMembers, B)` includes A's members. --- import std.stdio; mixin template Bug() { import std.traits; static

Re: template this and traits getOverloads issue.

2015-11-20 Thread BBasile via Digitalmars-d-learn
On Friday, 20 November 2015 at 14:18:00 UTC, Alex Parrill wrote: If the mixin has to be used on class and on struct, I cant use an interface. In this case override will create an error and go back to the solution on SO: statically check if things are already there. Templates are not

Re: template this and traits getOverloads issue.

2015-11-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 20 November 2015 at 14:18:00 UTC, Alex Parrill wrote: But you don't need a template for this case; mixin templates have access to `this`: Indeed, this is a good answer too. The difference between this and the template thing I did is that yours is virtual so calling it through an

Re: template this and traits getOverloads issue.

2015-11-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 20 November 2015 at 14:01:13 UTC, BBasile wrote: everything that can be done to avoid the compilations errors will also prevent "bar" to be written in the output (because a B will never be analyzed). The "only" fix I see is like in the stack overflow answer: statically check if the

Re: template this and traits getOverloads issue.

2015-11-20 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 20 November 2015 at 14:01:13 UTC, BBasile wrote: Background: === http://stackoverflow.com/questions/33764540/warning-about-overriden-methods-when-using-a-mixin Why this horrible trick has to be used: === cast this as (T) in a function

Re: template this and traits getOverloads issue.

2015-11-20 Thread BBasile via Digitalmars-d-learn
On Friday, 20 November 2015 at 14:39:29 UTC, Alex Parrill wrote: Alternatively, you can use a static method and pass in the instance. Initially this solution looked awesome but when `bug()` is static, `` returns some functions, not some delegates, which is a problem: this implies that I have

Re: template this and traits getOverloads issue.

2015-11-20 Thread BBasile via Digitalmars-d-learn
On Friday, 20 November 2015 at 14:49:28 UTC, Adam D. Ruppe wrote: On Friday, 20 November 2015 at 14:01:13 UTC, BBasile wrote: everything that can be done to avoid the compilations errors will also prevent "bar" to be written in the output (because a B will never be analyzed). The "only" fix I

Re: template this and traits getOverloads issue.

2015-11-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 20 November 2015 at 15:43:00 UTC, BBasile wrote: One last question: is it possible to nest the calls to functions that take this kind of parameters ? auto this_ = cast(T) this; this_.bug0(); this_.bug1();

Re: template this and traits getOverloads issue.

2015-11-20 Thread BBasile via Digitalmars-d-learn
On Friday, 20 November 2015 at 15:03:06 UTC, Adam D. Ruppe wrote: On Friday, 20 November 2015 at 14:18:00 UTC, Alex Parrill wrote: But you don't need a template for this case; mixin templates have access to `this`: Indeed, this is a good answer too. The difference between this and the