How to get the name of member function through an alias of that function

Peter Particle ParticlePeter at gmx.de
Wed Dec 12 08:16:03 UTC 2018


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);
}


More information about the Digitalmars-d-learn mailing list