I'll add an answer, but I'm not going to mark it correct. It is not complete. Too big to add as a comment. This is something along the lines which I can do, but I'm looking for a better way. And, yes, very tacky-hacky. But I figure there is some API somewhere which, although still will be a bit gross, will be guaranteed to work (if using a single compiler throughout a project).
template<typename R, typename C, typename... A>
struct MemberFunctionPointer
{
typedef R Return;
typedef C Class;
};
template<typename R, typename C, typename... A>
constexpr auto inferMemberFunctionPointer(R (C::*method)(A...))
{
return MemberFunctionPointer<R,C,A...>{};
}
template<typename M, M m, typename... A>
class GenerateMethodSignature
{
typedef typename decltype(inferMemberFunctionPointer(m))::Class T;
typedef typename decltype(inferMemberFunctionPointer(m))::Return R;
public:
static const char *mangledName (const char *fs)
{
const char *ts = typeid(T).name();
const char *rs = typeid(R).name();
const char *ms = typeid(M).name();
std::string r = "_Z";
if (ts[0] != 'N')
r += "N";
r += ts;
if (ts[0] == 'N')
r.pop_back();
r += std::to_string(strlen(fs));
r += fs;
r += "E";
r += ms + strlen ("M") + strlen(ts) + strlen ("F") + strlen(rs);
r.pop_back();
printf("calculated signature %s\n", r.c_str());
// this is very bad but... for demonstration purposes
return strdup(r.c_str());
}
} ;
namespace MyNamespace {
namespace MySubNamespace {
class MyClass
{
public:
int MyFunction (int myarg);
} ;
} // namespace
} // namespace
#define ExportSignature(T, M) GenerateMethodSignature<decltype(&T::M), &T::M>::mangledName(#M)
const char *myMethodSignature = ExportSignature(MyNamespace::MySubNamespace::MyClass, MyFunction);
-DGLIBCXX_DEBUG
) – Auricular