www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - getOverloads trait doesn't work on functions

reply faissaloo <faissaloo gmail.com> writes:
I'm trying to use:
```
__traits(getOverloads, fn)
```
But I get the error

expected 2 arguments for getOverloads but had 1
Is there an alternative I can use?
Apr 13 2019
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 13 April 2019 at 19:02:42 UTC, faissaloo wrote:
 I'm trying to use:
 ```
 __traits(getOverloads, fn)
 ```
 But I get the error

expected 2 arguments for getOverloads but had 1
It expects the parent and the name rather than an instance of the function. Try __traits(getOverloads, __traits(parent, fn), __traits(identifier, fn)); Which is just long-hand for like __traits(getOverloads, mymodule.name, "fn") So, for example: --- void fn() {} void fn(int) {} void fn(string) {} void main() { foreach(overload; __traits(getOverloads, __traits(parent, fn), __traits(identifier, fn))) { pragma(msg, typeof(overload)); } } --- $ dmd refl void() void(int _param_0) void(string _param_0)
Apr 13 2019