digitalmars.D.learn - How to get the name of member function through an alias of that
- Peter Particle (30/30) Dec 12 2018 I prefer that all the members marked with myUDA are process in
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (6/9) Dec 12 2018 Just replace fullyQualifiedName!member with __traits(identifier,
- Peter Particle (3/12) Dec 12 2018 How could I have missed that one! THX!
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); }
Dec 12 2018
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
Dec 12 2018
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:How could I have missed that one! THX!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
Dec 12 2018