This can be done with typeid; the trick is to encode a function pointer into a type name by creating a type with a template parameter of a non-type type whose value is a function pointer. For instance:
template <class T> int foo(T&);
template <class U, U> struct IntegralConstant {};
std::cout << typeid(IntegralConstant<decltype(&foo<int>), &foo<int>>).name() << '\n';
16IntegralConstantIPFiRiEXadL_Z3fooIiEiRT_EEE, c++filt -t IntegralConstant<int (*)(int&), &(int foo<int>(int&))>. , _Z3fooIiEiRT_ (demangling to int foo<int>(int&)) ; , , nullptr :
template <class U, U> struct IntegralConstant {};
template <class U, U* u> std::string mangledSymbolName() {
std::string null = typeid(IntegralConstant<U*, nullptr>).name();
std::string symbol = typeid(IntegralConstant<U*, u>).name();
return symbol.substr(null.size() - 3, symbol.size() - null.size() + 0);
}
: http://melpon.org/wandbox/permlink/6b46CBOv0ZwIMukk
3 0 ++ ABI nullptr, ; , IntegralConstant .