GetOverloadedMethods

JS js.mdnq at gmail.com
Fri Jul 19 00:56:43 PDT 2013


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)



More information about the Digitalmars-d-learn mailing list