How to check if a class has a specific overload for member x?
Hipreme
msnmancini at hotmail.com
Mon Aug 1 00:23:21 UTC 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;
}
```
More information about the Digitalmars-d-learn
mailing list