Thread overview | |||||
---|---|---|---|---|---|
|
December 12, 2018 How to get the name of member function through an alias of that function | ||||
---|---|---|---|---|
| ||||
I prefer that all the members marked with myUDA are process in the order thy appear in Foo. This happens automatically when I iterate with through 'getMemberByUDA'. // Reduced example code enum myUDA; struct Foo { public: @myUDA void bar(float f) { baz = 1 / f; } @myUDA float bar() { return 1 / baz; } float baz; } import std.traits; string getMemberFuncName(T)(ref T foo) { static foreach(member; getSymbolsByUDA!(T, myUDA)) { static if(isSomeFunction!member) { // Error: function `Test.Foo.bar(float f)` is not callable using argument types `()` // pragma(msg, member.stringof); // Don't want the fully qualified name, just the func name pragma(msg, fullyQualifiedName!member); // return the name of the first found member function //return name; } } return ""; } void main() { Foo foo; string name = getMemberFuncName(foo); } |
December 12, 2018 Re: How to get the name of member function through an alias of that function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Particle | On Wednesday, 12 December 2018 at 08:16:03 UTC, Peter Particle wrote:
> I prefer that all the members marked with myUDA are process in the order thy appear in Foo. This happens automatically when I iterate with through 'getMemberByUDA'.
Just replace fullyQualifiedName!member with __traits(identifier, member), and things should work.
--
Simen
|
December 12, 2018 Re: How to get the name of member function through an alias of that function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjærås | On Wednesday, 12 December 2018 at 08:36:00 UTC, Simen Kjærås wrote:
> On Wednesday, 12 December 2018 at 08:16:03 UTC, Peter Particle wrote:
>> I prefer that all the members marked with myUDA are process in the order thy appear in Foo. This happens automatically when I iterate with through 'getMemberByUDA'.
>
> Just replace fullyQualifiedName!member with __traits(identifier, member), and things should work.
>
> --
> Simen
How could I have missed that one! THX!
|
Copyright © 1999-2021 by the D Language Foundation