digitalmars.D.learn - GetOverloadedMethods
- JS (32/32) Jul 18 2013 module main;
- Jacob Carlborg (11/43) Jul 18 2013 I would guess it would be possible to get this information using the
- JS (6/60) Jul 19 2013 This depends on what derived members will actually return... I
- Jacob Carlborg (4/5) Jul 20 2013 https://github.com/D-Programming-Language/dmd/pull/2366
- JS (2/5) Jul 20 2013 Cool...
module main; import std.stdio; interface A { final void Afoo() { } void bar(); } class B : A { final void Bfoo() { } void bar() { } void doo() { } } class C : B { //override void bar() { } override void doo() { } void doo(int x) { } } int main(string[] argv) { pragma(msg, GetOverloadedMethods!B); pragma(msg, GetOverloadedMethods!C); return 0; } GetOverloadedMethods comes from std.traits. It returns toHash, toString, opCmp, etc... tuple(bar, doo, toString, toHash, opCmp, opEquals) tuple(doo, doo, bar, toString, toHash, opCmp, opEquals) Is there a way to get only the overridden implemented methods? GetOverloadedMethods!B gives only bar and doo GetOverloadedMethods!B gives only doo and doo
Jul 18 2013
On 2013-07-19 00:47, JS wrote:module main; import std.stdio; interface A { final void Afoo() { } void bar(); } class B : A { final void Bfoo() { } void bar() { } void doo() { } } class C : B { //override void bar() { } override void doo() { } void doo(int x) { } } int main(string[] argv) { pragma(msg, GetOverloadedMethods!B); pragma(msg, GetOverloadedMethods!C); return 0; } GetOverloadedMethods comes from std.traits. It returns toHash, toString, opCmp, etc... tuple(bar, doo, toString, toHash, opCmp, opEquals) tuple(doo, doo, bar, toString, toHash, opCmp, opEquals) Is there a way to get only the overridden implemented methods? GetOverloadedMethods!B gives only bar and doo GetOverloadedMethods!B gives only doo and dooI would guess it would be possible to get this information using the __traits derivedMembers, parent and getOverloads. Something like: 1. Get all derived members of the class 2. Get all derived members of the parent class 3. Create a tuple with the intersection of the above two lists 4. Filter out any methods that doesn't have the same arguments using getOverloads Would that work? I guess it would be easier if we had a trait for that. -- /Jacob Carlborg
Jul 18 2013
On Friday, 19 July 2013 at 06:27:36 UTC, Jacob Carlborg wrote:On 2013-07-19 00:47, JS wrote:This depends on what derived members will actually return... I have such a function but haven't looked at the returns; It would be nice if we had a few more traits. I find it a mess to work with overloads because it seems traits wasn't designed for them. (allMembers does not return overloads)module main; import std.stdio; interface A { final void Afoo() { } void bar(); } class B : A { final void Bfoo() { } void bar() { } void doo() { } } class C : B { //override void bar() { } override void doo() { } void doo(int x) { } } int main(string[] argv) { pragma(msg, GetOverloadedMethods!B); pragma(msg, GetOverloadedMethods!C); return 0; } GetOverloadedMethods comes from std.traits. It returns toHash, toString, opCmp, etc... tuple(bar, doo, toString, toHash, opCmp, opEquals) tuple(doo, doo, bar, toString, toHash, opCmp, opEquals) Is there a way to get only the overridden implemented methods? GetOverloadedMethods!B gives only bar and doo GetOverloadedMethods!B gives only doo and dooI would guess it would be possible to get this information using the __traits derivedMembers, parent and getOverloads. Something like: 1. Get all derived members of the class 2. Get all derived members of the parent class 3. Create a tuple with the intersection of the above two lists 4. Filter out any methods that doesn't have the same arguments using getOverloads Would that work? I guess it would be easier if we had a trait for that.
Jul 19 2013
On 2013-07-19 00:47, JS wrote:Is there a way to get only the overridden implemented methods?https://github.com/D-Programming-Language/dmd/pull/2366 -- /Jacob Carlborg
Jul 20 2013
On Saturday, 20 July 2013 at 10:46:44 UTC, Jacob Carlborg wrote:On 2013-07-19 00:47, JS wrote:Cool...Is there a way to get only the overridden implemented methods?https://github.com/D-Programming-Language/dmd/pull/2366
Jul 20 2013