Idiomatic way to call base method in generic code

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 25 15:43:28 PDT 2015


On Mon, 25 May 2015 09:24:56 +0000, ZombineDev wrote:

> On Monday, 25 May 2015 at 07:57:49 UTC, ketmar wrote:
>> i don't know why you want that, but something like this may do:
>>
>> auto callBaseMethod(string MTN, C, Args...) (inout C self, Args args) {
>>   alias FSC = BaseClassesTuple!(C)[0];
>>   return mixin(`self.`~FSC.stringof~`.`~MTN~"(args)");
>> }
>>
>> writeln(d.callBaseMethod!"toString");
>>
>>
> Thanks!

note that this funny trick works even for `void` methods, due to magic of 
`auto` return type.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150525/eb71e587/attachment.sig>


More information about the Digitalmars-d-learn mailing list