I want to get full function path and declaration in code via macro or some compiler magic. I have this code (click here to run):
#include <iostream>
namespace NS {
    struct Foo {
        static int sum(int a, int b) {
            std::cout << "This is from " << __FILE__ << ":" << __LINE__ << " @ " <<     __func__ << std::endl;
            return a+b;
        }
        static int sum(int a, int b, int c) {
            std::cout << "This is from " << __FILE__ << ":" << __LINE__ << " @ " <<     __func__ << std::endl;
            return a+b+c;
        }
   };
}
int main() {
    NS::Foo::sum(1,2);
    NS::Foo::sum(1,2, 3);
}
And I get the output:
This is from /some/where/main.cpp:7 @ sum
This is from /some/where/main.cpp:12 @ sum
My questions are:
- How do I get the full path of sumfunction invoked?(NS::Foo::sum)
- How can I get the full function declaration with argument types?( sum(int, int)orsum(int, int, int))
I am interested in mainstream compilers: Clang, GCC, Microsoft C++ compiler
 
     
     
     
    