www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - GetOverloadedMethods

reply "JS" <js.mdnq gmail.com> writes:
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
next sibling parent reply Jacob Carlborg <doob me.com> writes:
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 doo
I 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
parent "JS" <js.mdnq gmail.com> writes:
On Friday, 19 July 2013 at 06:27:36 UTC, Jacob Carlborg wrote:
 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 doo
I 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.
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)
Jul 19 2013
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
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
parent "JS" <js.mdnq gmail.com> writes:
On Saturday, 20 July 2013 at 10:46:44 UTC, Jacob Carlborg wrote:
 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
Cool...
Jul 20 2013