Re: Automatic method overriding in sub-classes

2015-10-31 Thread Tofu Ninja via Digitalmars-d
On Saturday, 31 October 2015 at 16:55:32 UTC, bitwise wrote: On Saturday, 31 October 2015 at 16:38:58 UTC, bitwise wrote: @synthesized void accept(this This)(Visitor v) { v.visit(this); } I meant to remove "(this This)" as you don't need it if you can just do "typeof(this)" in the functi

Re: Automatic method overriding in sub-classes

2015-10-31 Thread bitwise via Digitalmars-d
On Saturday, 31 October 2015 at 16:38:58 UTC, bitwise wrote: @synthesized void accept(this This)(Visitor v) { v.visit(this); } I meant to remove "(this This)" as you don't need it if you can just do "typeof(this)" in the function body. @synthesized void accept(Visitor v) { v.visit(t

Re: Automatic method overriding in sub-classes

2015-10-31 Thread bitwise via Digitalmars-d
On Saturday, 31 October 2015 at 02:39:19 UTC, Tofu Ninja wrote: On Friday, 30 October 2015 at 21:38:40 UTC, bitwise wrote: On Thursday, 29 October 2015 at 01:14:35 UTC, Tofu Ninja wrote: On Thursday, 29 October 2015 at 00:11:06 UTC, Tofu Ninja wrote: [...] Actually never mind, what I just sa

Re: Automatic method overriding in sub-classes

2015-10-31 Thread Daniel N via Digitalmars-d
On Friday, 30 October 2015 at 21:38:40 UTC, bitwise wrote: On Thursday, 29 October 2015 at 01:14:35 UTC, Tofu Ninja wrote: On Thursday, 29 October 2015 at 00:11:06 UTC, Tofu Ninja wrote: [...] Actually never mind, what I just said was basically auto override for this() so its not really any

Re: Automatic method overriding in sub-classes

2015-10-30 Thread Tofu Ninja via Digitalmars-d
On Friday, 30 October 2015 at 21:38:40 UTC, bitwise wrote: On Thursday, 29 October 2015 at 01:14:35 UTC, Tofu Ninja wrote: On Thursday, 29 October 2015 at 00:11:06 UTC, Tofu Ninja wrote: [...] Actually never mind, what I just said was basically auto override for this() so its not really any

Re: Automatic method overriding in sub-classes

2015-10-30 Thread bitwise via Digitalmars-d
On Thursday, 29 October 2015 at 01:14:35 UTC, Tofu Ninja wrote: On Thursday, 29 October 2015 at 00:11:06 UTC, Tofu Ninja wrote: [...] Actually never mind, what I just said was basically auto override for this() so its not really any different. And it is kinda limited with some problems. So

Re: Automatic method overriding in sub-classes

2015-10-29 Thread Tofu Ninja via Digitalmars-d
On Thursday, 29 October 2015 at 17:32:22 UTC, Daniel N wrote: [...] class Base(T) : IBase [...] I actually did this before, I can confidently say how damn ugly and all over bad it is. Please no.

Re: Automatic method overriding in sub-classes

2015-10-29 Thread bitwise via Digitalmars-d
On Thursday, 29 October 2015 at 17:32:22 UTC, Daniel N wrote: On Thursday, 29 October 2015 at 13:54:17 UTC, bitwise wrote: [...] Just sprinkle some D magic ontop.. voilà DRTP is born ;) template Dynamic(T) { static if(is(T == U!V, alias U, V)) alias Dynamic = Dynamic!V; else a

Re: Automatic method overriding in sub-classes

2015-10-29 Thread Daniel N via Digitalmars-d
On Thursday, 29 October 2015 at 13:54:17 UTC, bitwise wrote: class One : Base!One { } class Two : Base!Two { } Doesn't work with multiple levels of inheritance... Bit Just sprinkle some D magic ontop.. voilà DRTP is born ;) template Dynamic(T) { static if(is(T == U!V, alias U, V))

Re: Automatic method overriding in sub-classes

2015-10-29 Thread bitwise via Digitalmars-d
On Thursday, 29 October 2015 at 08:27:04 UTC, Daniel N wrote: On Thursday, 29 October 2015 at 01:52:16 UTC, bitwise wrote: [...] There's a famous idiom from the C++ world which solves this, google CRTP... ... or see the quick hack below. ('final' is optional, the interface is also optional.

Re: Automatic method overriding in sub-classes

2015-10-29 Thread Daniel N via Digitalmars-d
On Thursday, 29 October 2015 at 08:27:04 UTC, Daniel N wrote: class Base(T) : IBase { final string Name() { return typeof(this).stringof; } } class One : Base!One { } class Two : Base!Two { } Meh, sorry, ofcourse it should be: return typeof(cast(T)this).stringof;

Re: Automatic method overriding in sub-classes

2015-10-29 Thread Daniel N via Digitalmars-d
On Thursday, 29 October 2015 at 01:52:16 UTC, bitwise wrote: My argument though, is that a virtual function isn't needed. I'm not sure if this is sufficient for your use cases, but if I could do the this, I would have everything I need: struct MyInfo { string name; } static MyInfo[string] stuf

Re: Automatic method overriding in sub-classes

2015-10-28 Thread bitwise via Digitalmars-d
On Thursday, 29 October 2015 at 01:14:35 UTC, Tofu Ninja wrote: On Thursday, 29 October 2015 at 00:11:06 UTC, Tofu Ninja wrote: [...] Actually never mind, what I just said was basically auto override for this() so its not really any different. And it is kinda limited with some problems. My

Re: Automatic method overriding in sub-classes

2015-10-28 Thread Tofu Ninja via Digitalmars-d
On Thursday, 29 October 2015 at 00:11:06 UTC, Tofu Ninja wrote: [...] Actually never mind, what I just said was basically auto override for this() so its not really any different. And it is kinda limited with some problems.

Re: Automatic method overriding in sub-classes

2015-10-28 Thread Tofu Ninja via Digitalmars-d
On Wednesday, 28 October 2015 at 21:48:36 UTC, bitwise wrote: There is nothing spooky going on here. The declaration would be clearly annotated with auto override, or whatever keyword was chosen. If you were inheriting from a class, and didn't like its auto overrides, you could manually overrid

Re: Automatic method overriding in sub-classes

2015-10-28 Thread bitwise via Digitalmars-d
On Wednesday, 28 October 2015 at 20:04:44 UTC, Shammah Chancellor wrote: On Monday, 26 October 2015 at 23:25:49 UTC, Tofu Ninja wrote: So we have TemplateThisParameters methods which are cool but have some drawbacks. They are templates so they are implicitly non-virtual and are called based on

Re: Automatic method overriding in sub-classes

2015-10-28 Thread Timon Gehr via Digitalmars-d
On 10/27/2015 12:25 AM, Tofu Ninja wrote: Thoughts? Any one else needed this before? Yes, similar proposals have come up multiple times. It is better if it is more general though. The super class should be able to mix arbitrary declarations into the subclass scope.

Re: Automatic method overriding in sub-classes

2015-10-28 Thread Tofu Ninja via Digitalmars-d
On Wednesday, 28 October 2015 at 20:04:44 UTC, Shammah Chancellor wrote: This kind of magic is detrimental to being able to reason about the code you are writing. If libraries do this for example, there's too much spooky action-at-a-distance occurring. Having explicit mixins is the appropriat

Re: Automatic method overriding in sub-classes

2015-10-28 Thread Shammah Chancellor via Digitalmars-d
On Monday, 26 October 2015 at 23:25:49 UTC, Tofu Ninja wrote: So we have TemplateThisParameters methods which are cool but have some drawbacks. They are templates so they are implicitly non-virtual and are called based on the type of the reference. It would be very nice to be able to auto gener

Re: Automatic method overriding in sub-classes

2015-10-28 Thread Tofu Ninja via Digitalmars-d
On Wednesday, 28 October 2015 at 15:13:40 UTC, bitwise wrote: [...] I have to disagree with this. A function's meaning should not change because it's definition is removed. I suppose you are right. [...] A.foo() or B.foo() seems to work instead of super.super.foo() or super.foo() Ah

Re: Automatic method overriding in sub-classes

2015-10-28 Thread bitwise via Digitalmars-d
On Tuesday, 27 October 2015 at 23:15:39 UTC, Tofu Ninja wrote: On Tuesday, 27 October 2015 at 22:23:15 UTC, bitwise wrote: [...] -H also keeps the body of template functions so I would assume it would treat auto overrides the same. Well.. It's not going to just work. Dmd will surely have

Re: Automatic method overriding in sub-classes

2015-10-28 Thread Idan Arye via Digitalmars-d
On Tuesday, 27 October 2015 at 23:15:39 UTC, Tofu Ninja wrote: An alternative solution could be that if you provide a header to a class and don't include the auto override body, then the auto override functionality is removed and the method is treated as a regular method from that point on(with

Re: Automatic method overriding in sub-classes

2015-10-27 Thread Tofu Ninja via Digitalmars-d
On Tuesday, 27 October 2015 at 22:23:15 UTC, bitwise wrote: [...] I just did a test for this. Using dmd's -H flag to generate header files, the bodies of member functions are removed. If you link a static library containing the compiled class though, everything will work, and you can still inh

Re: Automatic method overriding in sub-classes

2015-10-27 Thread bitwise via Digitalmars-d
On Tuesday, 27 October 2015 at 20:05:17 UTC, Tofu Ninja wrote: On Tuesday, 27 October 2015 at 14:47:03 UTC, bitwise wrote: [...] Is there ever a chance the auto override definition would not be available, I think the class chain all the way up to Object always needs to be available at compil

Re: Automatic method overriding in sub-classes

2015-10-27 Thread Jacob Carlborg via Digitalmars-d
On 2015-10-27 09:05, Tofu Ninja wrote: The method is instantiated when the subclass is defined so T would obviously be right on hand. Sub-classing a class with an auto override method would implicitly instantiate and override the method. Calling a.bar() would have no problems because bar would b

Re: Automatic method overriding in sub-classes

2015-10-27 Thread Tofu Ninja via Digitalmars-d
On Tuesday, 27 October 2015 at 14:47:03 UTC, bitwise wrote: [...] Going a bit further, I think you could override an auto override fun too manually as well. This would be helpful both for adding additional functionality, and as a fallback if the definition of the auto override function was not

Re: Automatic method overriding in sub-classes

2015-10-27 Thread MrSmith via Digitalmars-d
On Monday, 26 October 2015 at 23:25:49 UTC, Tofu Ninja wrote: I know this has basically no chance of ever actually being added because that is the way of all "I want feature X" threads, but I thought I would post this anyways because I seem to want it constantly. Hey, that is what I needed ye

Re: Automatic method overriding in sub-classes

2015-10-27 Thread bitwise via Digitalmars-d
On Tuesday, 27 October 2015 at 14:21:12 UTC, bitwise wrote: On Tuesday, 27 October 2015 at 07:52:27 UTC, Jacob Carlborg wrote: On 2015-10-27 00:25, Tofu Ninja wrote: [...] I don't think this is possible. Think of code looking like this: // Imagine not having access to the source code "crea

Re: Automatic method overriding in sub-classes

2015-10-27 Thread bitwise via Digitalmars-d
On Tuesday, 27 October 2015 at 07:52:27 UTC, Jacob Carlborg wrote: On 2015-10-27 00:25, Tofu Ninja wrote: I know this has basically no chance of ever actually being added because that is the way of all "I want feature X" threads, but I thought I would post this anyways because I seem to want i

Re: Automatic method overriding in sub-classes

2015-10-27 Thread Tofu Ninja via Digitalmars-d
On Tuesday, 27 October 2015 at 07:52:27 UTC, Jacob Carlborg wrote: [...] I don't think this is possible. Think of code looking like this: // Imagine not having access to the source code "createA" A createA() { new B; } void inspectA(A a) { a.bar(); } How should the compiler know that w

Re: Automatic method overriding in sub-classes

2015-10-27 Thread Jacob Carlborg via Digitalmars-d
On 2015-10-27 00:25, Tofu Ninja wrote: I know this has basically no chance of ever actually being added because that is the way of all "I want feature X" threads, but I thought I would post this anyways because I seem to want it constantly. So we have TemplateThisParameters methods which are coo

Re: Automatic method overriding in sub-classes

2015-10-26 Thread bitwise via Digitalmars-d
On Monday, 26 October 2015 at 23:25:49 UTC, Tofu Ninja wrote: I know this has basically no chance of ever actually being added because that is the way of all "I want feature X" threads, but I thought I would post this anyways because I seem to want it constantly. [...] Stole the words right

Re: Automatic method overriding in sub-classes

2015-10-26 Thread Tofu Ninja via Digitalmars-d
On Tuesday, 27 October 2015 at 00:27:46 UTC, Tofu Ninja wrote: ... crap, copy paste error change the main to void main() { A a = new A(); a.foo(); // prints nothing a.bar(); // prints nothing B b = new B(); b.foo(); // prints X b.bar(); // print

Re: Automatic method overriding in sub-classes

2015-10-26 Thread Tofu Ninja via Digitalmars-d
On Tuesday, 27 October 2015 at 00:07:36 UTC, Ali Çehreli wrote: I don't understand all uses of the request but typeid() returns a TypeInfo reference, which is about the actual type of an object. The following change produces the expected output in this case (except, it has the added module name

Re: Automatic method overriding in sub-classes

2015-10-26 Thread Tofu Ninja via Digitalmars-d
On Tuesday, 27 October 2015 at 00:07:36 UTC, Ali Çehreli wrote: On 10/26/2015 04:25 PM, Tofu Ninja wrote: ## class A { void foo(this T)() { writeln(T.stringof); } void bar(auto override this T)() { writeln(T.stringof); } } class B : A {} void main()

Re: Automatic method overriding in sub-classes

2015-10-26 Thread Ali Çehreli via Digitalmars-d
On 10/26/2015 04:25 PM, Tofu Ninja wrote: ## class A { void foo(this T)() { writeln(T.stringof); } void bar(auto override this T)() { writeln(T.stringof); } } class B : A {} void main() { A a = new A(); a.foo(); // prints "A" a.bar()

Automatic method overriding in sub-classes

2015-10-26 Thread Tofu Ninja via Digitalmars-d
I know this has basically no chance of ever actually being added because that is the way of all "I want feature X" threads, but I thought I would post this anyways because I seem to want it constantly. So we have TemplateThisParameters methods which are cool but have some drawbacks. They are