digitalmars.D.learn - Function signature as string
- John Chapman (9/9) Nov 29 2018 Is there any way to get a string representing a function's exact
- Neia Neutuladh (8/18) Nov 29 2018 typeof(&func).stringof should do it:
- John Chapman (3/21) Nov 29 2018 That does the trick - thanks.
Is there any way to get a string representing a function's exact
signature as declared in the source? I can generate it myself
using reflection but it might not be 100% verbatim so wanted to
know if there's anything built in?
foreach (m; __traits(allMembers, T)) {
alias member = __traits(getMember, T, m);
string signature = // Call some function to get "member"'s
signature as a string
}
Nov 29 2018
On Thu, 29 Nov 2018 21:11:06 +0000, John Chapman wrote:
Is there any way to get a string representing a function's exact
signature as declared in the source? I can generate it myself using
reflection but it might not be 100% verbatim so wanted to know if
there's anything built in?
foreach (m; __traits(allMembers, T)) {
alias member = __traits(getMember, T, m);
string signature = // Call some function to get "member"'s
signature as a string
}
typeof(&func).stringof should do it:
void bar(string s, ref Foo!int i) {}
void main()
{
writeln(typeof(&bar).stringof);
}
prints: void function(string s, ref Foo!int i)
Nov 29 2018
On Thursday, 29 November 2018 at 21:31:57 UTC, Neia Neutuladh wrote:On Thu, 29 Nov 2018 21:11:06 +0000, John Chapman wrote:That does the trick - thanks.Is there any way to get a string representing a function's exact signature as declared in the source? I can generate it myself using reflection but it might not be 100% verbatim so wanted to know if there's anything built in? foreach (m; __traits(allMembers, T)) { alias member = __traits(getMember, T, m); string signature = // Call some function to get "member"'s signature as a string }typeof(&func).stringof should do it: void bar(string s, ref Foo!int i) {} void main() { writeln(typeof(&bar).stringof); } prints: void function(string s, ref Foo!int i)
Nov 29 2018








John Chapman <johnch_atms hotmail.com>