digitalmars.D.learn - How to check if a class has a specific overload for member x?
I wish to generate some functions using mixin template and I wish to check if the current class already has an specific overload with parameters (A, B). What I'm currently trying is doing `__traits(getOverloads, T, "foo")`, and then checking if its type are equal. But it seems hackish, and I would like to make something like `hasOverload!(Test, "foo", int(int a, int b) const)` or something like that.
Jul 31 2022
On Sunday, 31 July 2022 at 19:25:51 UTC, Hipreme wrote:I wish to generate some functions using mixin template and I wish to check if the current class already has an specific overload with parameters (A, B). What I'm currently trying is doing `__traits(getOverloads, T, "foo")`, and then checking if its type are equal. But it seems hackish, and I would like to make something like `hasOverload!(Test, "foo", int(int a, int b) const)` or something like that.Seems that is how it should be checked: ```d enum hasOverload(T, string member, FuncType)() { bool ret; static foreach(overload; __traits(getVirtualMethods, T, member)) if(is(typeof(overload) == FuncType) && !__traits(isAbstractFunction, overload)) ret = true; return ret; } ```
Jul 31 2022
On Monday, 1 August 2022 at 00:23:21 UTC, Hipreme wrote:On Sunday, 31 July 2022 at 19:25:51 UTC, Hipreme wrote:It's like checking if a word used in a text with more than one definition according the dictionary.[...]Seems that is how it should be checked: ```d enum hasOverload(T, string member, FuncType)() { bool ret; static foreach(overload; __traits(getVirtualMethods, T, member)) if(is(typeof(overload) == FuncType) && !__traits(isAbstractFunction, overload)) ret = true; return ret; } ```
Aug 01 2022